]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/inspsocket.cpp
2.0.0 release
[user/henk/code/inspircd.git] / src / inspsocket.cpp
index 65b554006a3207f86248b00b629f92c68b3ce5c7..92625ac29e91691ce94bf5ca5949b5aef987d3a7 100644 (file)
@@ -104,7 +104,7 @@ BufferedSocketError BufferedSocket::BeginConnect(const irc::sockets::sockaddrs&
 
        this->state = I_CONNECTING;
 
-       if (!ServerInstance->SE->AddFd(this, FD_WANT_NO_READ | FD_WANT_SINGLE_WRITE))
+       if (!ServerInstance->SE->AddFd(this, FD_WANT_NO_READ | FD_WANT_SINGLE_WRITE | FD_WRITE_WILL_BLOCK))
                return I_ERR_NOMOREFDS;
 
        this->Timeout = new SocketTimeout(this->GetFd(), this, timeout, ServerInstance->Time());
@@ -216,6 +216,9 @@ void StreamSocket::DoRead()
        }
 }
 
+/* Don't try to prepare huge blobs of data to send to a blocked socket */
+static const int MYIOV_MAX = IOV_MAX < 128 ? IOV_MAX : 128;
+
 void StreamSocket::DoWrite()
 {
        if (sendq.empty())
@@ -330,11 +333,11 @@ void StreamSocket::DoWrite()
                {
                        // Prepare a writev() call to write all buffers efficiently
                        int bufcount = sendq.size();
-               
-                       // cap the number of buffers at IOV_MAX
-                       if (bufcount > IOV_MAX)
+
+                       // cap the number of buffers at MYIOV_MAX
+                       if (bufcount > MYIOV_MAX)
                        {
-                               bufcount = IOV_MAX;
+                               bufcount = MYIOV_MAX;
                        }
 
                        int rv_max = 0;
@@ -443,11 +446,6 @@ void SocketTimeout::Tick(time_t)
                // connection.
                this->sock->OnTimeout();
                this->sock->OnError(I_ERR_TIMEOUT);
-
-               /* 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;
 
                ServerInstance->GlobalCulls.AddItem(sock);