* 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.97 2002/11/28 12:17:38 alex Exp $
+ * $Id: conn.c,v 1.101 2002/12/02 13:19:37 alex Exp $
*
* connect.h: Verwaltung aller Netz-Verbindungen ("connections")
*/
CHAR wbuf[WRITEBUFFER_LEN]; /* Schreibpuffer */
INT wdatalen; /* Laenge der Daten im Schreibpuffer */
INT our_server; /* wenn von uns zu connectender Server: ID */
+ time_t starttime; /* Startzeit des Links */
time_t lastdata; /* Letzte Aktivitaet */
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 */
+ LONG bytes_in, bytes_out; /* Empfangene uns gesendete Bytes */
+ LONG msg_in, msg_out; /* Empfangene uns gesendete Nachtichten */
INT flag; /* "Markierungs-Flag" (vgl. "irc-write"-Modul) */
INT options; /* Link-Optionen */
#ifdef USE_ZLIB
strcat( buffer, "\r\n" );
ok = Conn_Write( Idx, buffer, strlen( buffer ));
+ My_Connections[Idx].msg_out++;
va_end( ap );
return ok;
if( InformClient )
{
+#ifndef STRICT_RFC
/* Statistik an Client melden, wenn 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 );
}
+#endif
/* ERROR an Client schicken (von RFC so vorgesehen!) */
if( FwdMsg ) Conn_WriteStr( Idx, "ERROR :%s", FwdMsg );
if( My_Connections[Idx].sock == NONE ) return;
}
+ /* zunaechst versuchen, noch im Schreibpuffer vorhandene
+ * Daten auf den Socket zu schreiben ... */
+ Try_Write( Idx );
+
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 ));
return TRUE;
} /* Conn_InitZip */
+
+GLOBAL LONG
+Conn_SendBytesZip( CONN_ID Idx )
+{
+ /* Anzahl gesendeter Bytes (komprimiert!) liefern */
+
+ assert( Idx > NONE );
+ return My_Connections[Idx].zip.bytes_out;
+} /* Conn_SendBytesZip */
+
+
+GLOBAL LONG
+Conn_RecvBytesZip( CONN_ID Idx )
+{
+ /* Anzahl gesendeter Bytes (komprimiert!) liefern */
+
+ assert( Idx > NONE );
+ return My_Connections[Idx].zip.bytes_in;
+} /* Conn_RecvBytesZip */
+
#endif
+GLOBAL time_t
+Conn_StartTime( CONN_ID Idx )
+{
+ /* Zeitpunkt des Link-Starts liefern (in Sekunden) */
+
+ assert( Idx > NONE );
+ return My_Connections[Idx].starttime;
+} /* Conn_Uptime */
+
+
+GLOBAL INT
+Conn_SendQ( CONN_ID Idx )
+{
+ /* Laenge der Daten im Schreibbuffer liefern */
+
+ assert( Idx > NONE );
+#ifdef USE_ZLIB
+ return My_Connections[Idx].zip.wdatalen;
+#else
+ return My_Connections[Idx].wdatalen;
+#endif
+} /* Conn_SendQ */
+
+
+GLOBAL LONG
+Conn_SendMsg( CONN_ID Idx )
+{
+ /* Anzahl gesendeter Nachrichten liefern */
+
+ assert( Idx > NONE );
+ return My_Connections[Idx].msg_out;
+} /* Conn_SendMsg */
+
+
+GLOBAL LONG
+Conn_SendBytes( CONN_ID Idx )
+{
+ /* Anzahl gesendeter Bytes (unkomprimiert) liefern */
+
+ assert( Idx > NONE );
+ return My_Connections[Idx].bytes_out;
+} /* Conn_SendBytes */
+
+
+GLOBAL INT
+Conn_RecvQ( CONN_ID Idx )
+{
+ /* Laenge der Daten im Lesebuffer liefern */
+
+ assert( Idx > NONE );
+#ifdef USE_ZLIB
+ return My_Connections[Idx].zip.rdatalen;
+#else
+ return My_Connections[Idx].rdatalen;
+#endif
+} /* Conn_RecvQ */
+
+
+GLOBAL LONG
+Conn_RecvMsg( CONN_ID Idx )
+{
+ /* Anzahl empfangener Nachrichten liefern */
+
+ assert( Idx > NONE );
+ return My_Connections[Idx].msg_in;
+} /* Conn_RecvMsg */
+
+
+GLOBAL LONG
+Conn_RecvBytes( CONN_ID Idx )
+{
+ /* Anzahl empfangener Bytes (unkomprimiert) liefern */
+
+ assert( Idx > NONE );
+ return My_Connections[Idx].bytes_in;
+} /* Conn_RecvBytes */
+
+
LOCAL BOOLEAN
Try_Write( CONN_ID Idx )
{
- /* Versuchen, Daten aus dem Schreib-Puffer in den
- * Socket zu schreiben. */
+ /* Versuchen, Daten aus dem Schreib-Puffer in den Socket zu
+ * schreiben. TRUE wird geliefert, wenn entweder keine Daten
+ * zum Versenden vorhanden sind oder erfolgreich bearbeitet
+ * werden konnten. Im Fehlerfall wird FALSE geliefert und
+ * die Verbindung geschlossen. */
fd_set write_socket;
struct timeval tv;
assert( Idx > NONE );
assert( My_Connections[Idx].sock > NONE );
- assert( My_Connections[Idx].wdatalen > 0 );
+
+ /* sind ueberhaupt Daten vorhanden? */
+#ifdef USE_ZLIB
+ if(( ! My_Connections[Idx].wdatalen > 0 ) && ( ! My_Connections[Idx].zip.wdatalen )) return TRUE;
+#else
+ if( ! My_Connections[Idx].wdatalen > 0 ) return TRUE;
+#endif
/* Timeout initialisieren: 0 Sekunden, also nicht blockieren */
tv.tv_sec = 0; tv.tv_usec = 0;
if( s )
{
/* Sub-Prozess wurde asyncron gestartet */
- Conn_WriteStr( idx, "NOTICE AUTH :%sLooking up your hostname ...", NOTICE_TXTPREFIX );
My_Connections[idx].res_stat = s;
}
* Tritt ein Fehler auf, so wird der Socket geschlossen. */
INT len, bsize;
+#ifdef USE_ZLIB
CLIENT *c;
+#endif
assert( Idx > NONE );
assert( My_Connections[Idx].sock > NONE );
if( len > delta )
{
/* Es wurde ein Request gelesen */
+ My_Connections[Idx].msg_in++;
if( ! Parse_Request( Idx, My_Connections[Idx].rbuf )) return FALSE;
else action = TRUE;
}
My_Connections[Idx].wbuf[0] = '\0';
My_Connections[Idx].wdatalen = 0;
My_Connections[Idx].our_server = NONE;
+ My_Connections[Idx].starttime = time( NULL );
My_Connections[Idx].lastdata = time( NULL );
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;
+ My_Connections[Idx].msg_in = 0;
+ My_Connections[Idx].msg_out = 0;
My_Connections[Idx].flag = 0;
My_Connections[Idx].options = 0;
assert( c != NULL );
strcpy( My_Connections[i].host, result );
Client_SetHostname( c, result );
-
- Conn_WriteStr( i, "NOTICE AUTH :%sGot your hostname.", NOTICE_TXTPREFIX );
}
else
{