]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Much more detailed logging of lowlevel socket errors to the +l snomask
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Tue, 1 May 2007 20:18:10 +0000 (20:18 +0000)
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Tue, 1 May 2007 20:18:10 +0000 (20:18 +0000)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@6856 e03df62e-2008-0410-955e-edbf42e46eb7

src/inspsocket.cpp
src/modules/m_spanningtree/treesocket1.cpp

index cdc0dc26f62623df832c5199074eba773946dda6..3face10f6f462ea16cdf76e2006920f608931161 100644 (file)
@@ -119,10 +119,10 @@ InspSocket::InspSocket(InspIRCd* SI, const std::string &ipaddr, int aport, bool
                if (!ipvalid)
                {
                        this->Instance->Log(DEBUG,"BUG: Hostname passed to InspSocket, rather than an IP address!");
+                       this->OnError(I_ERR_CONNECT);
                        this->Close();
                        this->fd = -1;
                        this->state = I_ERROR;
-                       this->OnError(I_ERR_RESOLVE);
                        return;
                }
                else
@@ -131,10 +131,10 @@ InspSocket::InspSocket(InspIRCd* SI, const std::string &ipaddr, int aport, bool
                        timeout_val = maxtime;
                        if (!this->DoConnect())
                        {
+                               this->OnError(I_ERR_CONNECT);
                                this->Close();
                                this->fd = -1;
                                this->state = I_ERROR;
-                               this->OnError(I_ERR_CONNECT);
                                return;
                        }
                }
@@ -715,6 +715,23 @@ void InspSocket::HandleEvent(EventType et, int errornum)
        switch (et)
        {
                case EVENT_ERROR:
+                       switch (errornum)
+                       {
+                               case ETIMEDOUT:
+                                       this->OnError(I_ERR_TIMEOUT);
+                               break;
+                               case ECONNREFUSED:
+                               case 0:
+                                       this->OnError(this->state == I_CONNECTING ? I_ERR_CONNECT : I_ERR_WRITE);
+                               break;
+                               case EADDRINUSE:
+                                       this->OnError(I_ERR_BIND);
+                               break;
+                               case EPIPE:
+                               case EIO:
+                                       this->OnError(I_ERR_WRITE);
+                               break;
+                       }
                        if (this->Instance->SocketCull.find(this) == this->Instance->SocketCull.end())
                                this->Instance->SocketCull[this] = this;
                        return;
index 21c6de11803ae60881e502666a57e99a27a355f8..6176d02015c178f38f1ccf5eb2157448e3fb0f23 100644 (file)
@@ -205,24 +205,35 @@ bool TreeSocket::OnConnected()
 
 void TreeSocket::OnError(InspSocketError e)
 {
-       /* We don't handle this method, because all our
-        * dirty work is done in OnClose() (see below)
-        * which is still called on error conditions too.
-        */
-       if (e == I_ERR_CONNECT)
-       {
-               this->Instance->SNO->WriteToSnoMask('l',"Connection failed: Connection to \002"+myhost+"\002 refused");
-               Link* MyLink = Utils->FindLink(myhost);
-               if (MyLink)
-                       Utils->DoFailOver(MyLink);
-       }
-       else
+       Link* MyLink;
+
+       switch (e)
        {
-               if ((errno) && (errno != EINPROGRESS) && (errno != EAGAIN))
-               {
-                       std::string errstr = strerror(errno);
-                       this->Instance->SNO->WriteToSnoMask('l',"Connection to \002"+myhost+"\002 failed with error: " + errstr);
-               }
+               case I_ERR_CONNECT:
+                       this->Instance->SNO->WriteToSnoMask('l',"Connection failed: Connection to \002"+myhost+"\002 refused");
+                       MyLink = Utils->FindLink(myhost);
+                       if (MyLink)
+                               Utils->DoFailOver(MyLink);
+               break;
+               case I_ERR_SOCKET:
+                       this->Instance->SNO->WriteToSnoMask('l',"Connection failed: Could not create socket");
+               break;
+               case I_ERR_BIND:
+                       this->Instance->SNO->WriteToSnoMask('l',"Connection failed: Error binding socket to address or port");
+               break;
+               case I_ERR_WRITE:
+                       this->Instance->SNO->WriteToSnoMask('l',"Connection failed: I/O error on connection");
+               break;
+               case I_ERR_NOMOREFDS:
+                       this->Instance->SNO->WriteToSnoMask('l',"Connection failed: Operating system is out of file descriptors!");
+               break;
+               default:
+                       if ((errno) && (errno != EINPROGRESS) && (errno != EAGAIN))
+                       {
+                               std::string errstr = strerror(errno);
+                               this->Instance->SNO->WriteToSnoMask('l',"Connection to \002"+myhost+"\002 failed with OS error: " + errstr);
+                       }
+               break;
        }
 }