+
+void InspSocket::HandleEvent(EventType et, int errornum)
+{
+ switch (et)
+ {
+ case EVENT_ERROR:
+ this->Instance->SE->DelFd(this);
+ this->Close();
+ delete this;
+ return;
+ break;
+ case EVENT_READ:
+ if (!this->Poll())
+ {
+ this->Instance->SE->DelFd(this);
+ this->Close();
+ delete this;
+ return;
+ }
+ break;
+ case EVENT_WRITE:
+ if (this->WaitingForWriteEvent)
+ {
+ this->WaitingForWriteEvent = false;
+ if (!this->OnWriteReady())
+ {
+ this->Instance->SE->DelFd(this);
+ this->Close();
+ delete this;
+ return;
+ }
+ }
+ if (this->state == I_CONNECTING)
+ {
+ /* This might look wrong as if we should be actually calling
+ * with EVENT_WRITE, but trust me it is correct. There are some
+ * writeability-state things in the read code, because of how
+ * InspSocket used to work regarding write buffering in previous
+ * versions of InspIRCd. - Brain
+ */
+ this->HandleEvent(EVENT_READ);
+ return;
+ }
+ else
+ {
+ if (this->FlushWriteBuffer())
+ {
+ this->Instance->SE->DelFd(this);
+ this->Close();
+ delete this;
+ return;
+ }
+ }
+ break;
+ }
+}
+