]> jfr.im git - irc/rizon/znc.git/commitdiff
Update to latest Csocket
authorpsychon <redacted>
Fri, 29 Aug 2008 18:59:05 +0000 (18:59 +0000)
committerpsychon <redacted>
Fri, 29 Aug 2008 18:59:05 +0000 (18:59 +0000)
SockError() is now called with the correct errno if accept() fails.
This is some preparation for a later patch which will handle EMFILE.

git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1179 726aef4b-f618-498e-8847-2d620e286838

Csocket.cpp

index a3088a3b8e6e6179c19e84f44d4153650285c981..0294468a1e4a60fca265f7822a2ecc4bd8d63f3b 100644 (file)
@@ -28,7 +28,7 @@
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 *
-* $Revision: 1.82 $
+* $Revision: 1.83 $
 */
 
 #include "Csocket.h"
@@ -851,9 +851,12 @@ int Csock::Accept( CS_STRING & sHost, u_short & iRPort )
                struct sockaddr_in client;
                socklen_t clen = sizeof( client );
                iSock = accept( m_iReadSock, (struct sockaddr *) &client, &clen );
-               getpeername( iSock, (struct sockaddr *) &client, &clen );
-               sHost = inet_ntoa( client.sin_addr );
-               iRPort = ntohs( client.sin_port );
+               if( iSock != -1 )
+               {
+                       getpeername( iSock, (struct sockaddr *) &client, &clen );
+                       sHost = inet_ntoa( client.sin_addr );
+                       iRPort = ntohs( client.sin_port );
+               }
        }
 #ifdef HAVE_IPV6
        else
@@ -862,11 +865,14 @@ int Csock::Accept( CS_STRING & sHost, u_short & iRPort )
                struct sockaddr_in6 client;
                socklen_t clen = sizeof( client );
                iSock = accept( m_iReadSock, (struct sockaddr *) &client, &clen );
-               getpeername( iSock, (struct sockaddr *) &client, &clen );
-               if( inet_ntop( AF_INET6, &client.sin6_addr, straddr, sizeof(straddr) ) > 0 )
+               if( iSock != -1 )
                {
-                       sHost = straddr;
-                       iRPort = ntohs( client.sin6_port );
+                       getpeername( iSock, (struct sockaddr *) &client, &clen );
+                       if( inet_ntop( AF_INET6, &client.sin6_addr, straddr, sizeof(straddr) ) > 0 )
+                       {
+                               sHost = straddr;
+                               iRPort = ntohs( client.sin6_port );
+                       }
                }
        }
 #endif /* HAVE_IPV6 */