]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Remove WaitingForWriteEvent, it seems to do *nothing* except confuse things. Also...
authorw00t <w00t@e03df62e-2008-0410-955e-edbf42e46eb7>
Thu, 11 Sep 2008 00:15:28 +0000 (00:15 +0000)
committerw00t <w00t@e03df62e-2008-0410-955e-edbf42e46eb7>
Thu, 11 Sep 2008 00:15:28 +0000 (00:15 +0000)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@10509 e03df62e-2008-0410-955e-edbf42e46eb7

include/inspsocket.h
src/inspsocket.cpp
src/modules/m_httpd.cpp

index f61bf133dc15de957cfe63bd7fa04802a21c5c65..c3b24ad8f3b6c6aa152675d55e5a827f546d7e45 100644 (file)
@@ -159,6 +159,7 @@ class CoreExport BufferedSocket : public EventHandler
        socklen_t length;
 
        /** Flushes the write buffer
        socklen_t length;
 
        /** Flushes the write buffer
+        * @returns true if the writing failed, false if it was successful
         */
        bool FlushWriteBuffer();
 
         */
        bool FlushWriteBuffer();
 
@@ -176,12 +177,6 @@ class CoreExport BufferedSocket : public EventHandler
         */
        bool ClosePending;
 
         */
        bool ClosePending;
 
-       /** Set to true when we're waiting for a write event.
-        * If this is true and a write event comes in, we
-        * call the write instead of the read method.
-        */
-       bool WaitingForWriteEvent;
-
        /**
         * Bind to an address
         * @param ip IP to bind to
        /**
         * Bind to an address
         * @param ip IP to bind to
@@ -256,13 +251,23 @@ class CoreExport BufferedSocket : public EventHandler
        /**
         * When it is ok to write to the socket, and a 
         * write event was requested, this method is
        /**
         * When it is ok to write to the socket, and a 
         * write event was requested, this method is
-        * triggered. Within this method you should call
+        * triggered.
+        *
+        * Within this method you should call
         * write() or send() etc, to send data to the
         * write() or send() etc, to send data to the
-        * other end of the socket. Further write events
-        * will not be triggered unless you call WantWrite().
+        * other end of the socket.
+        *
+        * Further write events will not be triggered
+        * unless you call WantWrite().
+        *
+        * The default behaviour of this method is to
+        * flush the write buffer, respecting the IO
+        * hooking modules.
+        *
+        * XXX: this used to be virtual, ask us if you need it to be so.
         * @return false to close the socket
         */
         * @return false to close the socket
         */
-       virtual bool OnWriteReady();
+       bool OnWriteReady();
 
        /**
         * When an outbound connection fails, and the
 
        /**
         * When an outbound connection fails, and the
index 0c3f3ea17293fbc27866ab280c68e1ebb96c9ad1..ea0534f24b704a575f5ba2316ac8efb408596e23 100644 (file)
@@ -20,7 +20,7 @@
 
 bool BufferedSocket::Readable()
 {
 
 bool BufferedSocket::Readable()
 {
-       return ((this->state != I_CONNECTING) && (this->WaitingForWriteEvent == false));
+       return (this->state != I_CONNECTING);
 }
 
 BufferedSocket::BufferedSocket(InspIRCd* SI)
 }
 
 BufferedSocket::BufferedSocket(InspIRCd* SI)
@@ -28,7 +28,6 @@ BufferedSocket::BufferedSocket(InspIRCd* SI)
        this->Timeout = NULL;
        this->state = I_DISCONNECTED;
        this->fd = -1;
        this->Timeout = NULL;
        this->state = I_DISCONNECTED;
        this->fd = -1;
-       this->WaitingForWriteEvent = false;
        this->Instance = SI;
 }
 
        this->Instance = SI;
 }
 
@@ -38,7 +37,6 @@ BufferedSocket::BufferedSocket(InspIRCd* SI, int newfd, const char* ip)
        this->fd = newfd;
        this->state = I_CONNECTED;
        strlcpy(this->IP,ip,MAXBUF);
        this->fd = newfd;
        this->state = I_CONNECTED;
        strlcpy(this->IP,ip,MAXBUF);
-       this->WaitingForWriteEvent = false;
        this->Instance = SI;
        if (this->fd > -1)
                this->Instance->SE->AddFd(this);
        this->Instance = SI;
        if (this->fd > -1)
                this->Instance->SE->AddFd(this);
@@ -50,7 +48,6 @@ BufferedSocket::BufferedSocket(InspIRCd* SI, const std::string &ipaddr, int apor
        this->fd = -1;
        this->Instance = SI;
        strlcpy(host,ipaddr.c_str(),MAXBUF);
        this->fd = -1;
        this->Instance = SI;
        strlcpy(host,ipaddr.c_str(),MAXBUF);
-       this->WaitingForWriteEvent = false;
        this->Timeout = NULL;
 
        strlcpy(this->host,ipaddr.c_str(),MAXBUF);
        this->Timeout = NULL;
 
        strlcpy(this->host,ipaddr.c_str(),MAXBUF);
@@ -98,7 +95,6 @@ BufferedSocket::BufferedSocket(InspIRCd* SI, const std::string &ipaddr, int apor
 void BufferedSocket::WantWrite()
 {
        this->Instance->SE->WantWrite(this);
 void BufferedSocket::WantWrite()
 {
        this->Instance->SE->WantWrite(this);
-       this->WaitingForWriteEvent = true;
 }
 
 void BufferedSocket::SetQueues(int nfd)
 }
 
 void BufferedSocket::SetQueues(int nfd)
@@ -595,7 +591,11 @@ bool BufferedSocket::OnConnected() { return true; }
 void BufferedSocket::OnError(BufferedSocketError) { return; }
 int BufferedSocket::OnDisconnect() { return 0; }
 bool BufferedSocket::OnDataReady() { return true; }
 void BufferedSocket::OnError(BufferedSocketError) { return; }
 int BufferedSocket::OnDisconnect() { return 0; }
 bool BufferedSocket::OnDataReady() { return true; }
-bool BufferedSocket::OnWriteReady() { return true; }
+bool BufferedSocket::OnWriteReady()
+{
+       // Default behaviour: just try write some.
+       return !this->FlushWriteBuffer();
+}
 void BufferedSocket::OnTimeout() { return; }
 void BufferedSocket::OnClose() { return; }
 
 void BufferedSocket::OnTimeout() { return; }
 void BufferedSocket::OnClose() { return; }
 
@@ -644,16 +644,6 @@ void BufferedSocket::HandleEvent(EventType et, int errornum)
                        }
                break;
                case EVENT_WRITE:
                        }
                break;
                case EVENT_WRITE:
-                       if (this->WaitingForWriteEvent)
-                       {
-                               this->WaitingForWriteEvent = false;
-                               if (!this->OnWriteReady())
-                               {
-                                       if (this->Instance->SocketCull.find(this) == this->Instance->SocketCull.end())
-                                               this->Instance->SocketCull[this] = this;
-                                       return;
-                               }
-                       }
                        if (this->state == I_CONNECTING)
                        {
                                /* This might look wrong as if we should be actually calling
                        if (this->state == I_CONNECTING)
                        {
                                /* This might look wrong as if we should be actually calling
@@ -667,7 +657,7 @@ void BufferedSocket::HandleEvent(EventType et, int errornum)
                        }
                        else
                        {
                        }
                        else
                        {
-                               if (this->FlushWriteBuffer())
+                               if (!this->OnWriteReady())
                                {
                                        if (this->Instance->SocketCull.find(this) == this->Instance->SocketCull.end())
                                                this->Instance->SocketCull[this] = this;
                                {
                                        if (this->Instance->SocketCull.find(this) == this->Instance->SocketCull.end())
                                                this->Instance->SocketCull[this] = this;
index 777ba5567bf25e3d9aca9238fdf9a21279cfab57..eaf6712671ccfb39b73f5996099d4255096aa1ea 100644 (file)
@@ -165,7 +165,6 @@ class HttpServerSocket : public BufferedSocket
 
                SendHeaders(data.length(), response, empty);
                this->Write(data);
 
                SendHeaders(data.length(), response, empty);
                this->Write(data);
-               this->FlushWriteBuffer();
        }
 
        void SendHeaders(unsigned long size, int response, HTTPHeaders &rheaders)
        }
 
        void SendHeaders(unsigned long size, int response, HTTPHeaders &rheaders)
@@ -251,7 +250,6 @@ class HttpServerSocket : public BufferedSocket
                                if (request_type.empty() || uri.empty() || http_version.empty())
                                {
                                        SendHTTPError(400);
                                if (request_type.empty() || uri.empty() || http_version.empty())
                                {
                                        SendHTTPError(400);
-                                       SetWrite();
                                        return;
                                }
 
                                        return;
                                }
 
@@ -265,7 +263,6 @@ class HttpServerSocket : public BufferedSocket
                        if ((fieldsep == std::string::npos) || (fieldsep == 0) || (fieldsep == cheader.length() - 1))
                        {
                                SendHTTPError(400);
                        if ((fieldsep == std::string::npos) || (fieldsep == 0) || (fieldsep == cheader.length() - 1))
                        {
                                SendHTTPError(400);
-                               SetWrite();
                                return;
                        }
 
                                return;
                        }
 
@@ -282,7 +279,6 @@ class HttpServerSocket : public BufferedSocket
                if ((http_version != "HTTP/1.1") && (http_version != "HTTP/1.0"))
                {
                        SendHTTPError(505);
                if ((http_version != "HTTP/1.1") && (http_version != "HTTP/1.0"))
                {
                        SendHTTPError(505);
-                       SetWrite();
                        return;
                }
 
                        return;
                }
 
@@ -319,8 +315,6 @@ class HttpServerSocket : public BufferedSocket
                        HTTPHeaders empty;
                        SendHeaders(index->ContentSize(), 200, empty);
                        this->Write(index->Contents());
                        HTTPHeaders empty;
                        SendHeaders(index->ContentSize(), 200, empty);
                        this->Write(index->Contents());
-                       this->FlushWriteBuffer();
-                       SetWrite();
                }
                else
                {
                }
                else
                {
@@ -335,32 +329,15 @@ class HttpServerSocket : public BufferedSocket
                                if (!claimed)
                                {
                                        SendHTTPError(404);
                                if (!claimed)
                                {
                                        SendHTTPError(404);
-                                       SetWrite();
                                }
                        }
                }
        }
 
                                }
                        }
                }
        }
 
-
-       bool OnWriteReady()
-       {
-               Instance->Logs->Log("m_httpd",DEBUG,"OnWriteReady()");
-               return false;
-       }
-
        void Page(std::stringstream* n, int response, HTTPHeaders *hheaders)
        {
                SendHeaders(n->str().length(), response, *hheaders);
                this->Write(n->str());
        void Page(std::stringstream* n, int response, HTTPHeaders *hheaders)
        {
                SendHeaders(n->str().length(), response, *hheaders);
                this->Write(n->str());
-               this->FlushWriteBuffer();
-               SetWrite();
-       }
-
-       void SetWrite()
-       {
-               Instance->Logs->Log("m_httpd",DEBUG,"SetWrite()");
-               this->WaitingForWriteEvent = true;
-               Instance->SE->WantWrite(this);
        }
 };
 
        }
 };