X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=ngircd-alex.git;a=blobdiff_plain;f=src%2Fngircd%2Fconn.c;h=85a9966b9859283926d36603b374040ab793ca84;hp=bef5b149f9598d3951fbc4180974a667485139da;hb=a0c032b2ff96c04d8a2a5215f4183b99296826c3;hpb=b2615bcc765a791d9fb836848fd953641bba48ec diff --git a/src/ngircd/conn.c b/src/ngircd/conn.c index bef5b149..85a9966b 100644 --- a/src/ngircd/conn.c +++ b/src/ngircd/conn.c @@ -9,7 +9,7 @@ * Naehere Informationen entnehmen Sie bitter der Datei COPYING. Eine Liste * der an ngIRCd beteiligten Autoren finden Sie in der Datei AUTHORS. * - * $Id: conn.c,v 1.90 2002/11/19 12:50:20 alex Exp $ + * $Id: conn.c,v 1.93 2002/11/22 17:58:19 alex Exp $ * * connect.h: Verwaltung aller Netz-Verbindungen ("connections") */ @@ -187,6 +187,43 @@ Conn_Exit( VOID ) } /* Conn_Exit */ +GLOBAL INT +Conn_InitListeners( VOID ) +{ + /* Ports, auf denen der Server Verbindungen entgegennehmen + * soll, initialisieren */ + + INT created, i; + + created = 0; + for( i = 0; i < Conf_ListenPorts_Count; i++ ) + { + if( Conn_NewListener( Conf_ListenPorts[i] )) created++; + else Log( LOG_ERR, "Can't listen on port %u!", Conf_ListenPorts[i] ); + } + return created; +} /* Conn_InitListeners */ + + +GLOBAL VOID +Conn_ExitListeners( VOID ) +{ + /* Alle "Listen-Sockets" schliessen */ + + INT i; + + Log( LOG_INFO, "Shutting down all listening sockets ..." ); + for( i = 0; i < Conn_MaxFD + 1; i++ ) + { + if( FD_ISSET( i, &My_Sockets ) && FD_ISSET( i, &My_Listeners )) + { + close( i ); + Log( LOG_DEBUG, "Listening socket %d closed.", i ); + } + } +} /* Conn_ExitListeners */ + + GLOBAL BOOLEAN Conn_NewListener( CONST UINT Port ) { @@ -500,11 +537,11 @@ Conn_Close( CONN_ID Idx, CHAR *LogMsg, CHAR *FwdMsg, BOOLEAN InformClient ) if( close( My_Connections[Idx].sock ) != 0 ) { - Log( LOG_ERR, "Error closing connection %d (socket %d) with %s:%d - %s!", Idx, My_Connections[Idx].sock, inet_ntoa( My_Connections[Idx].addr.sin_addr ), ntohs( My_Connections[Idx].addr.sin_port), strerror( errno )); + Log( LOG_ERR, "Error closing connection %d (socket %d) with %s:%d - %s!", Idx, My_Connections[Idx].sock, My_Connections[Idx].host, ntohs( My_Connections[Idx].addr.sin_port), strerror( errno )); } else { - Log( LOG_INFO, "Connection %d (socket %d) with %s:%d closed.", Idx, My_Connections[Idx].sock, inet_ntoa( My_Connections[Idx].addr.sin_addr ), ntohs( My_Connections[Idx].addr.sin_port )); + Log( LOG_INFO, "Connection %d (socket %d) with %s:%d closed (%.1fK in/%.1fK out).", Idx, My_Connections[Idx].sock, My_Connections[Idx].host, ntohs( My_Connections[Idx].addr.sin_port ), (DOUBLE)My_Connections[Idx].bytes_in / 1024, (DOUBLE)My_Connections[Idx].bytes_out / 1024 ); } /* Socket als "ungueltig" markieren */ @@ -789,6 +826,9 @@ Handle_Write( CONN_ID Idx ) len = send( My_Connections[Idx].sock, My_Connections[Idx].wbuf, My_Connections[Idx].wdatalen, 0 ); if( len < 0 ) { + /* Operation haette Socket "nur" blockiert ... */ + if( errno == EAGAIN ) return TRUE; + /* Oops, ein Fehler! */ Log( LOG_ERR, "Write error on connection %d (socket %d): %s!", Idx, My_Connections[Idx].sock, strerror( errno )); Conn_Close( Idx, "Write error!", NULL, FALSE ); @@ -822,6 +862,7 @@ New_Connection( INT Sock ) assert( Sock > NONE ); + /* Connection auf Listen-Socket annehmen */ new_sock_len = sizeof( new_addr ); new_sock = accept( Sock, (struct sockaddr *)&new_addr, (socklen_t *)&new_sock_len ); if( new_sock < 0 ) @@ -830,6 +871,9 @@ New_Connection( INT Sock ) return; } + /* Socket initialisieren */ + Init_Socket( new_sock ); + /* Freie Connection-Struktur suchen */ for( idx = 0; idx < Pool_Size; idx++ ) if( My_Connections[idx].sock == NONE ) break; if( idx >= Pool_Size ) @@ -900,6 +944,8 @@ New_Connection( INT Sock ) Log( LOG_INFO, "Accepted connection %d from %s:%d on socket %d.", idx, inet_ntoa( new_addr.sin_addr ), ntohs( new_addr.sin_port), Sock ); /* Hostnamen ermitteln */ + strcpy( My_Connections[idx].host, inet_ntoa( new_addr.sin_addr )); + Client_SetHostname( c, My_Connections[idx].host ); s = Resolve_Addr( &new_addr ); if( s ) { @@ -907,12 +953,6 @@ New_Connection( INT Sock ) Conn_WriteStr( idx, "NOTICE AUTH :%sLooking up your hostname ...", NOTICE_TXTPREFIX ); My_Connections[idx].res_stat = s; } - else - { - /* kann Namen nicht aufloesen, daher wird die IP-Adresse verwendet */ - strcpy( My_Connections[idx].host, inet_ntoa( new_addr.sin_addr )); - Client_SetHostname( c, My_Connections[idx].host ); - } /* Penalty-Zeit setzen */ Conn_SetPenalty( idx, 4 ); @@ -972,6 +1012,9 @@ Read_Request( CONN_ID Idx ) if( len < 0 ) { + /* Operation haette Socket "nur" blockiert ... */ + if( errno == EAGAIN ) return; + /* Fehler beim Lesen */ Log( LOG_ERR, "Read error on connection %d (socket %d): %s!", Idx, My_Connections[Idx].sock, strerror( errno )); Conn_Close( Idx, "Read error!", "Client closed connection", FALSE ); @@ -1162,19 +1205,16 @@ Check_Servers( VOID ) My_Connections[idx].sock = SERVER_WAIT; My_Connections[idx].our_server = i; - /* Hostnamen in IP aufloesen */ + /* Hostnamen in IP aufloesen (Default bzw. im Fehlerfall: versuchen, den + * konfigurierten Text direkt als IP-Adresse zu verwenden ... */ + strcpy( Conf_Server[My_Connections[idx].our_server].ip, Conf_Server[i].host ); + strcpy( My_Connections[idx].host, Conf_Server[i].host ); s = Resolve_Name( Conf_Server[i].host ); if( s ) { /* Sub-Prozess wurde asyncron gestartet */ My_Connections[idx].res_stat = s; } - else - { - /* kann Namen nicht aufloesen: nun versuchen wir einfach, - * den "Text" direkt als IP-Adresse zu verwenden ... */ - strcpy( Conf_Server[My_Connections[idx].our_server].ip, Conf_Server[i].host ); - } } } /* Check_Servers */ @@ -1352,6 +1392,8 @@ Read_Resolver_Result( INT r_fd ) return; } + Log( LOG_DEBUG, "Resolver: %s is \"%s\".", My_Connections[i].host, result ); + /* Aufraeumen */ close( My_Connections[i].res_stat->pipe[0] ); close( My_Connections[i].res_stat->pipe[1] );