]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/inspsocket.cpp
Fix this so it works, passes test case. Provide a method to query for a bit and to...
[user/henk/code/inspircd.git] / src / inspsocket.cpp
index d712e5c19675ebfbc9429e287cf24e571b4e22cb..5f5c2d6ec2d3701f6e2cf6244b6f99b97055d8da 100644 (file)
@@ -120,6 +120,7 @@ InspSocket::InspSocket(InspIRCd* SI, const std::string &ipaddr, int aport, bool
 void InspSocket::WantWrite()
 {
        this->Instance->SE->WantWrite(this);
+       this->WaitingForWriteEvent = true;
 }
 
 void InspSocket::SetQueues(int nfd)
@@ -403,7 +404,6 @@ bool InspSocket::Poll()
                return false;
 
        int incoming = -1;
-       bool n = true;
 
        if ((fd < 0) || (fd > MAX_DESCRIPTORS))
                return false;
@@ -436,24 +436,8 @@ bool InspSocket::Poll()
                        return true;
                break;
                case I_CONNECTED:
-
-                       if (this->WaitingForWriteEvent)
-                       {
-                               /* Switch back to read events */
-                               this->Instance->SE->DelFd(this);
-                               this->WaitingForWriteEvent = false;
-                               if (!this->Instance->SE->AddFd(this))
-                                       return false;
-
-                               /* Trigger the write event */
-                               n = this->OnWriteReady();
-                       }
-                       else
-                       {
-                               /* Process the read event */
-                               n = this->OnDataReady();
-                       }
-                       return n;
+                       /* Process the read event */
+                       return this->OnDataReady();
                break;
                default:
                break;
@@ -491,10 +475,16 @@ InspSocket::~InspSocket()
        this->Close();
 }
 
-void InspSocket::HandleEvent(EventType et)
+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())
                        {
@@ -505,13 +495,31 @@ void InspSocket::HandleEvent(EventType et)
                        }
                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
                        {
+                               Instance->Log(DEBUG,"State=%d CONNECTED=%d", this->state, I_CONNECTED);
                                if (this->FlushWriteBuffer())
                                {
                                        this->Instance->SE->DelFd(this);