1
0
mirror of https://github.com/osmarks/ngircd.git synced 2024-10-28 04:46:17 +00:00

- If the server can't close a socket, it panics now.

- Quite enhanced logging :-)
This commit is contained in:
Alexander Barton 2002-12-27 13:20:13 +00:00
parent 15e4f67402
commit e21b9d842c

View File

@ -14,7 +14,7 @@
#include "portab.h" #include "portab.h"
static char UNUSED id[] = "$Id: conn.c,v 1.109 2002/12/26 17:04:54 alex Exp $"; static char UNUSED id[] = "$Id: conn.c,v 1.110 2002/12/27 13:20:13 alex Exp $";
#include "imp.h" #include "imp.h"
#include <assert.h> #include <assert.h>
@ -567,8 +567,8 @@ Conn_Write( CONN_ID Idx, CHAR *Data, INT Len )
GLOBAL VOID GLOBAL VOID
Conn_Close( CONN_ID Idx, CHAR *LogMsg, CHAR *FwdMsg, BOOLEAN InformClient ) Conn_Close( CONN_ID Idx, CHAR *LogMsg, CHAR *FwdMsg, BOOLEAN InformClient )
{ {
/* Verbindung schliessen. Evtl. noch von Resolver /* Close connection. Open pipes of asyncronous resolver
* Sub-Prozessen offene Pipes werden geschlossen. */ * sub-processes are closed down. */
CLIENT *c; CLIENT *c;
DOUBLE in_k, out_k; DOUBLE in_k, out_k;
@ -580,34 +580,47 @@ Conn_Close( CONN_ID Idx, CHAR *LogMsg, CHAR *FwdMsg, BOOLEAN InformClient )
assert( Idx > NONE ); assert( Idx > NONE );
assert( My_Connections[Idx].sock > NONE ); assert( My_Connections[Idx].sock > NONE );
/* Search client, if any */
c = Client_GetFromConn( Idx ); c = Client_GetFromConn( Idx );
/* Should the client be informed? */
if( InformClient ) if( InformClient )
{ {
#ifndef STRICT_RFC #ifndef STRICT_RFC
/* Statistik an Client melden, wenn User */ /* Send statistics to client if registered as user: */
if(( c != NULL ) && ( Client_Type( c ) == CLIENT_USER )) if(( c != NULL ) && ( Client_Type( c ) == CLIENT_USER ))
{ {
Conn_WriteStr( Idx, "NOTICE %s :%sConnection statistics: client %.1f kb, server %.1f kb.", Client_ThisServer( ), NOTICE_TXTPREFIX, (DOUBLE)My_Connections[Idx].bytes_in / 1024, (DOUBLE)My_Connections[Idx].bytes_out / 1024 ); Conn_WriteStr( Idx, "NOTICE %s :%sConnection statistics: client %.1f kb, server %.1f kb.", Client_ThisServer( ), NOTICE_TXTPREFIX, (DOUBLE)My_Connections[Idx].bytes_in / 1024, (DOUBLE)My_Connections[Idx].bytes_out / 1024 );
} }
#endif #endif
/* ERROR an Client schicken (von RFC so vorgesehen!) */ /* Send ERROR to client (see RFC!) */
if( FwdMsg ) Conn_WriteStr( Idx, "ERROR :%s", FwdMsg ); if( FwdMsg ) Conn_WriteStr( Idx, "ERROR :%s", FwdMsg );
else Conn_WriteStr( Idx, "ERROR :Closing connection." ); else Conn_WriteStr( Idx, "ERROR :Closing connection." );
if( My_Connections[Idx].sock == NONE ) return; if( My_Connections[Idx].sock == NONE ) return;
} }
/* zunaechst versuchen, noch im Schreibpuffer vorhandene /* Try to write out the write buffer */
* Daten auf den Socket zu schreiben ... */
Try_Write( Idx ); Try_Write( Idx );
/* Shut down socket */
if( close( My_Connections[Idx].sock ) != 0 ) 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, My_Connections[Idx].host, ntohs( My_Connections[Idx].addr.sin_port), strerror( errno )); /* Oops, we can't close the socket!? This is fatal! */
Log( LOG_EMERG, "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 ));
Log( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE );
exit( 1 );
} }
else
{ /* Mark socket as invalid: */
FD_CLR( My_Connections[Idx].sock, &My_Sockets );
FD_CLR( My_Connections[Idx].sock, &My_Connects );
My_Connections[Idx].sock = NONE;
/* If there is still a client, unregister it now */
if( c ) Client_Destroy( c, LogMsg, FwdMsg, TRUE );
/* Calculate statistics and log information */
in_k = (DOUBLE)My_Connections[Idx].bytes_in / 1024; in_k = (DOUBLE)My_Connections[Idx].bytes_in / 1024;
out_k = (DOUBLE)My_Connections[Idx].bytes_out / 1024; out_k = (DOUBLE)My_Connections[Idx].bytes_out / 1024;
#ifdef USE_ZLIB #ifdef USE_ZLIB
@ -624,25 +637,18 @@ Conn_Close( CONN_ID Idx, CHAR *LogMsg, CHAR *FwdMsg, BOOLEAN InformClient )
{ {
Log( LOG_INFO, "Connection %d with %s:%d closed (in: %.1fk, out: %.1fk).", Idx, My_Connections[Idx].host, ntohs( My_Connections[Idx].addr.sin_port ), in_k, out_k ); Log( LOG_INFO, "Connection %d with %s:%d closed (in: %.1fk, out: %.1fk).", Idx, My_Connections[Idx].host, ntohs( My_Connections[Idx].addr.sin_port ), in_k, out_k );
} }
}
/* Socket als "ungueltig" markieren */
FD_CLR( My_Connections[Idx].sock, &My_Sockets );
FD_CLR( My_Connections[Idx].sock, &My_Connects );
My_Connections[Idx].sock = NONE;
if( c ) Client_Destroy( c, LogMsg, FwdMsg, TRUE );
/* Is there a resolver sub-process running? */
if( My_Connections[Idx].res_stat ) if( My_Connections[Idx].res_stat )
{ {
/* Resolver-Strukturen freigeben, wenn noch nicht geschehen */ /* Free resolver structures */
FD_CLR( My_Connections[Idx].res_stat->pipe[0], &Resolver_FDs ); FD_CLR( My_Connections[Idx].res_stat->pipe[0], &Resolver_FDs );
close( My_Connections[Idx].res_stat->pipe[0] ); close( My_Connections[Idx].res_stat->pipe[0] );
close( My_Connections[Idx].res_stat->pipe[1] ); close( My_Connections[Idx].res_stat->pipe[1] );
free( My_Connections[Idx].res_stat ); free( My_Connections[Idx].res_stat );
} }
/* Startzeit des naechsten Connect-Versuchs modifizieren? */ /* Servers: Modify time of next connect attempt? */
if(( My_Connections[Idx].our_server > NONE ) && ( Conf_Server[My_Connections[Idx].our_server].lasttry < time( NULL ) - Conf_ConnectRetry )) if(( My_Connections[Idx].our_server > NONE ) && ( Conf_Server[My_Connections[Idx].our_server].lasttry < time( NULL ) - Conf_ConnectRetry ))
{ {
/* Okay, die Verbindung stand schon "genuegend lange": /* Okay, die Verbindung stand schon "genuegend lange":
@ -653,7 +659,7 @@ Conn_Close( CONN_ID Idx, CHAR *LogMsg, CHAR *FwdMsg, BOOLEAN InformClient )
} }
#ifdef USE_ZLIB #ifdef USE_ZLIB
/* Ggf. zlib abmelden */ /* Clean up zlib, if link was compressed */
if( Conn_Options( Idx ) & CONN_ZIP ) if( Conn_Options( Idx ) & CONN_ZIP )
{ {
inflateEnd( &My_Connections[Idx].zip.in ); inflateEnd( &My_Connections[Idx].zip.in );
@ -661,7 +667,7 @@ Conn_Close( CONN_ID Idx, CHAR *LogMsg, CHAR *FwdMsg, BOOLEAN InformClient )
} }
#endif #endif
/* Connection-Struktur loeschen (=freigeben) */ /* Clean up connection structure (=free it) */
Init_Conn_Struct( Idx ); Init_Conn_Struct( Idx );
} /* Conn_Close */ } /* Conn_Close */