X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fngircd%2Fconn.c;h=1a9ac47abcd55bc8d64f2b143ef550b2ae9dc6af;hb=1361b3742df0c5c8d51272248ff70164d0a3cd11;hp=26e47c1d2cab04e9f5ccdce61ccd6a7cb567e615;hpb=0bb892bb5fe1f0d9d783808d211c039e11e12f3b;p=ngircd-alex.git diff --git a/src/ngircd/conn.c b/src/ngircd/conn.c index 26e47c1d..1a9ac47a 100644 --- a/src/ngircd/conn.c +++ b/src/ngircd/conn.c @@ -9,6 +9,8 @@ * Please read the file COPYING, README and AUTHORS for more information. */ +#undef DEBUG_BUFFER + #define CONN_MODULE #include "portab.h" @@ -1255,9 +1257,11 @@ Handle_Write( CONN_ID Idx ) return true; } +#ifdef DEBUG_BUFFER LogDebug ("Handle_Write() called for connection %d, %ld bytes pending ...", Idx, wdatalen); +#endif #ifdef SSL_SUPPORT if ( Conn_OPTION_ISSET( &My_Connections[Idx], CONN_SSL )) { @@ -1326,6 +1330,8 @@ New_Connection(int Sock) assert(Sock > NONE); + LogDebug("Accepting new connection on socket %d ...", Sock); + new_sock_len = (int)sizeof(new_addr); new_sock = accept(Sock, (struct sockaddr *)&new_addr, (socklen_t *)&new_sock_len); @@ -1753,8 +1759,10 @@ Handle_Buffer(CONN_ID Idx) return 0; /* error -> connection has been closed */ array_moveleft(&My_Connections[Idx].rbuf, 1, len); +#ifdef DEBUG_BUFFER LogDebug("Connection %d: %d bytes left in read buffer.", Idx, array_bytes(&My_Connections[Idx].rbuf)); +#endif #ifdef ZLIB if ((!old_z) && (My_Connections[Idx].options & CONN_ZIP) && (array_bytes(&My_Connections[Idx].rbuf) > 0)) { @@ -1951,6 +1959,12 @@ New_Server( int Server , ng_ipaddr_t *dest) return; } + if (!io_event_create( new_sock, IO_WANTWRITE, cb_connserver)) { + Log(LOG_ALERT, "io_event_create(): could not add fd %d", strerror(errno)); + close(new_sock); + return; + } + My_Connections = array_start(&My_ConnArray); assert(My_Connections[new_sock].sock <= 0); @@ -1961,7 +1975,7 @@ New_Server( int Server , ng_ipaddr_t *dest) c = Client_NewLocal(new_sock, ip_str, CLIENT_UNKNOWNSERVER, false); if (!c) { Log( LOG_ALERT, "Can't establish connection: can't create client structure!" ); - close( new_sock ); + io_close(new_sock); return; } @@ -1978,13 +1992,6 @@ New_Server( int Server , ng_ipaddr_t *dest) strlcpy( My_Connections[new_sock].host, Conf_Server[Server].host, sizeof(My_Connections[new_sock].host )); - /* Register new socket */ - if (!io_event_create( new_sock, IO_WANTWRITE, cb_connserver)) { - Log( LOG_ALERT, "io_event_create(): could not add fd %d", strerror(errno)); - Conn_Close( new_sock, "io_event_create() failed", NULL, false ); - Init_Conn_Struct( new_sock ); - Conf_Server[Server].conn_id = NONE; - } #ifdef SSL_SUPPORT if (Conf_Server[Server].SSLConnect && !ConnSSL_PrepareConnect( &My_Connections[new_sock], &Conf_Server[Server] )) @@ -2025,9 +2032,10 @@ Init_Conn_Struct(CONN_ID Idx) * Initialize options of a new socket. * * For example, we try to set socket options SO_REUSEADDR and IPTOS_LOWDELAY. - * Errors shouldn't be fatal and therefore are ignored. + * The socket is automatically closed if a fatal error is encountered. * * @param Sock Socket handle. + * @returns false if socket was closed due to fatal error. */ static bool Init_Socket( int Sock ) @@ -2051,13 +2059,14 @@ Init_Socket( int Sock ) /* Set type of service (TOS) */ #if defined(IPPROTO_IP) && defined(IPTOS_LOWDELAY) value = IPTOS_LOWDELAY; - LogDebug("Setting IP_TOS on socket %d to IPTOS_LOWDELAY.", Sock); if (setsockopt(Sock, IPPROTO_IP, IP_TOS, &value, (socklen_t) sizeof(value))) { LogDebug("Can't set socket option IP_TOS: %s!", strerror(errno)); /* ignore this error */ - } + } else + LogDebug("IP_TOS on socket %d has been set to IPTOS_LOWDELAY.", + Sock); #endif return true;