* 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")
*/
} /* 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 )
{
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 */
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 );
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 )
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 )
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 )
{
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 );
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 );
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 */
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] );