X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=src%2Fngircd%2Fconn.c;h=257801564efb2acc4b07cc6933435b984faaebaa;hb=c7b55aa6f45b75b52fb67419b7ca5af3940016a4;hp=aeef7a3e00d5bb4c0314c138d3f1a5fbe1c3447f;hpb=c50ecda71559f78b0548840f3ced3098b8896055;p=ngircd-alex.git diff --git a/src/ngircd/conn.c b/src/ngircd/conn.c index aeef7a3e..25780156 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.73 2002/09/26 15:59:02 alex Exp $ + * $Id: conn.c,v 1.78 2002/10/09 16:53:02 alex Exp $ * * connect.h: Verwaltung aller Netz-Verbindungen ("connections") */ @@ -75,6 +75,7 @@ typedef struct _Connection time_t lastping; /* Letzter PING */ time_t lastprivmsg; /* Letzte PRIVMSG */ time_t delaytime; /* Nicht beachten bis ("penalty") */ + LONG bytes_in, bytes_out; /* Counter fuer Statistik */ } CONNECTION; @@ -400,7 +401,7 @@ Conn_Write( CONN_ID Idx, CHAR *Data, INT Len ) * dem nicht mehr so ist, wenn einer von mehreren * Conn_Write()'s fehlgeschlagen ist. In diesem Fall * wird hier einfach ein Fehler geliefert. */ - if( ! My_Connections[Idx].sock > NONE ) + if( My_Connections[Idx].sock <= NONE ) { Log( LOG_DEBUG, "Skipped write on closed socket (connection %d).", Idx ); return FALSE; @@ -447,8 +448,17 @@ Conn_Close( CONN_ID Idx, CHAR *LogMsg, CHAR *FwdMsg, BOOLEAN InformClient ) assert( Idx >= 0 ); assert( My_Connections[Idx].sock > NONE ); + c = Client_GetFromConn( Idx ); + if( InformClient ) { + /* Statistik an Client melden, wenn User */ + if(( c != NULL ) && ( Client_Type( c ) == CLIENT_USER )) + { + Conn_WriteStr( Idx, "NOTICE %s :%sConnection statistics: %.1f kb received, %.1f kb sent.", Client_ThisServer( ), NOTICE_TXTPREFIX, (double)My_Connections[Idx].bytes_in / 1024, (double)My_Connections[Idx].bytes_out / 1024 ); + } + + /* ERROR an Client schicken (von RFC so vorgesehen!) */ if( FwdMsg ) Conn_WriteStr( Idx, "ERROR :%s", FwdMsg ); else Conn_WriteStr( Idx, "ERROR :Closing connection." ); if( My_Connections[Idx].sock == NONE ) return; @@ -463,7 +473,6 @@ Conn_Close( CONN_ID Idx, CHAR *LogMsg, CHAR *FwdMsg, BOOLEAN InformClient ) Log( LOG_INFO, "Connection %d with %s:%d closed.", Idx, inet_ntoa( My_Connections[Idx].addr.sin_addr ), ntohs( My_Connections[Idx].addr.sin_port )); } - c = Client_GetFromConn( Idx ); if( c ) Client_Destroy( c, LogMsg, FwdMsg, TRUE ); if( My_Connections[Idx].res_stat ) @@ -663,6 +672,9 @@ Handle_Write( CONN_ID Idx ) return FALSE; } + /* Connection-Statistik aktualisieren */ + My_Connections[Idx].bytes_out += len; + /* Puffer anpassen */ My_Connections[Idx].wdatalen -= len; memmove( My_Connections[Idx].wbuf, My_Connections[Idx].wbuf + len, My_Connections[Idx].wdatalen ); @@ -727,6 +739,7 @@ New_Connection( INT Sock ) if( s ) { /* Sub-Prozess wurde asyncron gestartet */ + Conn_WriteStr( idx, "NOTICE AUTH :%sLooking up your hostname ...", NOTICE_TXTPREFIX ); My_Connections[idx].res_stat = s; } else @@ -794,6 +807,9 @@ Read_Request( CONN_ID Idx ) return; } + /* Connection-Statistik aktualisieren */ + My_Connections[Idx].bytes_in += len; + /* Lesebuffer updaten */ My_Connections[Idx].rdatalen += len; assert( My_Connections[Idx].rdatalen < READBUFFER_LEN ); @@ -1092,6 +1108,8 @@ Init_Conn_Struct( INT Idx ) My_Connections[Idx].lastping = 0; My_Connections[Idx].lastprivmsg = time( NULL ); My_Connections[Idx].delaytime = 0; + My_Connections[Idx].bytes_in = 0; + My_Connections[Idx].bytes_out = 0; } /* Init_Conn_Struct */ @@ -1133,7 +1151,7 @@ Read_Resolver_Result( INT r_fd ) FD_CLR( r_fd, &Resolver_FDs ); /* Anfrage vom Parent lesen */ - len = read( r_fd, result, HOST_LEN); + len = read( r_fd, result, HOST_LEN - 1 ); if( len < 0 ) { /* Fehler beim Lesen aus der Pipe */ @@ -1170,6 +1188,8 @@ Read_Resolver_Result( INT r_fd ) assert( c != NULL ); strcpy( My_Connections[i].host, result ); Client_SetHostname( c, result ); + + Conn_WriteStr( i, "NOTICE AUTH :%sGot your hostname.", NOTICE_TXTPREFIX ); } else {