]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/inspsocket.cpp
Add $ModDep: special comment, similar to $CompileFlags and $LinkerFlags.
[user/henk/code/inspircd.git] / src / inspsocket.cpp
index eb0ee86c82f524d8a5c48311f5847d055ed00ccf..c7e68df6c23c0f860392d13b0a7e8b8e92314b2a 100644 (file)
@@ -331,17 +331,24 @@ int InspSocket::Write(const std::string &data)
 
 bool InspSocket::FlushWriteBuffer()
 {
+       errno = 0;
        if ((this->fd > -1) && (this->state == I_CONNECTED))
        {
-               if (outbuffer.size())
+               /* If we have multiple lines, try to send them all,
+                * not just the first one -- Brain
+                */
+               while (outbuffer.size() && (errno != EAGAIN))
                {
+                       /* Send a line */
                        int result = write(this->fd,outbuffer[0].c_str(),outbuffer[0].length());
                        if (result > 0)
                        {
                                if ((unsigned int)result == outbuffer[0].length())
                                {
                                        /* The whole block was written (usually a line)
-                                        * Pop the block off the front of the queue
+                                        * Pop the block off the front of the queue,
+                                        * dont set errno, because we are clear of errors
+                                        * and want to try and write the next block too.
                                         */
                                        outbuffer.pop_front();
                                }
@@ -349,6 +356,12 @@ bool InspSocket::FlushWriteBuffer()
                                {
                                        std::string temp = outbuffer[0].substr(result);
                                        outbuffer[0] = temp;
+                                       /* We didnt get the whole line out. arses.
+                                        * Try again next time, i guess. Set errno,
+                                        * because we shouldnt be writing any more now,
+                                        * until the socketengine says its safe to do so.
+                                        */
+                                       errno = EAGAIN;
                                }
                        }
                        else if ((result == -1) && (errno != EAGAIN))
@@ -369,7 +382,7 @@ void SocketTimeout::Tick(time_t now)
 {
        if (ServerInstance->SE->GetRef(this->sfd) != this->sock)
        {
-               ServerInstance->Log(DEBUG,"No FD or socket ref");
+               ServerInstance->Log(DEBUG,"Our socket has been deleted before the timeout was reached.");
                return;
        }
 
@@ -383,8 +396,12 @@ void SocketTimeout::Tick(time_t now)
                this->sock->OnTimeout();
                this->sock->OnError(I_ERR_TIMEOUT);
                this->sock->timeout = true;
-               this->sock->state = I_ERROR;
                ServerInstance->SE->DelFd(this->sock);
+               /* NOTE: We must set this AFTER DelFd, as we added
+                * this socket whilst writeable. This means that we
+                * must DELETE the socket whilst writeable too!
+                */
+               this->sock->state = I_ERROR;
                this->sock->Close();
                delete this->sock;
                return;