mirror of
https://github.com/osmarks/ngircd.git
synced 2025-01-05 21:30:29 +00:00
- buffer werden nun periodisch geprueft, keine haengenden Clients mehr.
This commit is contained in:
parent
45d447d971
commit
9ab186c40c
@ -9,11 +9,14 @@
|
||||
* Naehere Informationen entnehmen Sie bitter der Datei COPYING. Eine Liste
|
||||
* der an comBase beteiligten Autoren finden Sie in der Datei AUTHORS.
|
||||
*
|
||||
* $Id: conn.c,v 1.10 2001/12/25 22:03:47 alex Exp $
|
||||
* $Id: conn.c,v 1.11 2001/12/25 23:15:16 alex Exp $
|
||||
*
|
||||
* connect.h: Verwaltung aller Netz-Verbindungen ("connections")
|
||||
*
|
||||
* $Log: conn.c,v $
|
||||
* Revision 1.11 2001/12/25 23:15:16 alex
|
||||
* - buffer werden nun periodisch geprueft, keine haengenden Clients mehr.
|
||||
*
|
||||
* Revision 1.10 2001/12/25 22:03:47 alex
|
||||
* - Conn_Close() eingefuehrt: war die lokale Funktion Close_Connection().
|
||||
*
|
||||
@ -111,6 +114,7 @@ LOCAL VOID New_Connection( INT Sock );
|
||||
LOCAL CONN_ID Socket2Index( INT Sock );
|
||||
LOCAL VOID Read_Request( CONN_ID Idx );
|
||||
LOCAL BOOLEAN Try_Write( CONN_ID Idx );
|
||||
LOCAL VOID Handle_Buffer( CONN_ID Idx );
|
||||
|
||||
|
||||
LOCAL fd_set My_Listener;
|
||||
@ -233,12 +237,16 @@ GLOBAL VOID Conn_Handler( INT Timeout )
|
||||
{
|
||||
fd_set read_sockets, write_sockets;
|
||||
struct timeval tv;
|
||||
time_t start;
|
||||
INT i;
|
||||
|
||||
/* Timeout initialisieren */
|
||||
tv.tv_sec = Timeout;
|
||||
tv.tv_usec = 0;
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = 50000;
|
||||
|
||||
start = time( NULL );
|
||||
while( time( NULL ) - start < Timeout )
|
||||
{
|
||||
/* noch volle Schreib-Puffer suchen */
|
||||
FD_ZERO( &write_sockets );
|
||||
for( i = 0; i < MAX_CONNECTIONS; i++ )
|
||||
@ -250,6 +258,16 @@ GLOBAL VOID Conn_Handler( INT Timeout )
|
||||
}
|
||||
}
|
||||
|
||||
/* noch volle Lese-Buffer suchen */
|
||||
for( i = 0; i < MAX_CONNECTIONS; i++ )
|
||||
{
|
||||
if(( My_Connections[i].sock >= 0 ) && ( My_Connections[i].rdatalen > 0 ))
|
||||
{
|
||||
/* Kann aus dem Buffer noch ein Befehl extrahiert werden? */
|
||||
Handle_Buffer( i );
|
||||
}
|
||||
}
|
||||
|
||||
read_sockets = My_Sockets;
|
||||
if( select( My_Max_Fd + 1, &read_sockets, &write_sockets, NULL, &tv ) == -1 )
|
||||
{
|
||||
@ -268,6 +286,7 @@ GLOBAL VOID Conn_Handler( INT Timeout )
|
||||
{
|
||||
if( FD_ISSET( i, &read_sockets )) Handle_Read( i );
|
||||
}
|
||||
}
|
||||
} /* Conn_Handler */
|
||||
|
||||
|
||||
@ -521,7 +540,6 @@ LOCAL VOID Read_Request( CONN_ID Idx )
|
||||
* Tritt ein Fehler auf, so wird der Socket geschlossen. */
|
||||
|
||||
INT len;
|
||||
CHAR *ptr;
|
||||
|
||||
assert( Idx >= 0 );
|
||||
assert( My_Connections[Idx].sock >= 0 );
|
||||
@ -559,15 +577,38 @@ LOCAL VOID Read_Request( CONN_ID Idx )
|
||||
return;
|
||||
}
|
||||
|
||||
Handle_Buffer( Idx );
|
||||
} /* Read_Request */
|
||||
|
||||
|
||||
LOCAL VOID Handle_Buffer( CONN_ID Idx )
|
||||
{
|
||||
CHAR *ptr, *ptr1, *ptr2;
|
||||
INT len, delta;
|
||||
|
||||
/* Eine komplette Anfrage muss mit CR+LF enden, vgl.
|
||||
* RFC 2812. Haben wir eine? */
|
||||
ptr = strstr( My_Connections[Idx].rbuf, "\r\n" );
|
||||
|
||||
if( ptr ) delta = 2;
|
||||
else
|
||||
{
|
||||
/* Nicht RFC-konforme Anfrage mit nur CR oder LF? Leider
|
||||
* machen soetwas viele Clients, u.a. "mIRC" :-( */
|
||||
ptr1 = strchr( My_Connections[Idx].rbuf, '\r' );
|
||||
ptr2 = strchr( My_Connections[Idx].rbuf, '\n' );
|
||||
delta = 1;
|
||||
if( ptr1 && ptr2 ) ptr = ptr1 > ptr2 ? ptr2 : ptr1;
|
||||
else if( ptr1 ) ptr = ptr1;
|
||||
else if( ptr2 ) ptr = ptr2;
|
||||
}
|
||||
|
||||
if( ptr )
|
||||
{
|
||||
/* Ende der Anfrage (CR+LF) wurde gefunden */
|
||||
/* Ende der Anfrage wurde gefunden */
|
||||
*ptr = '\0';
|
||||
len = ( ptr - My_Connections[Idx].rbuf ) + 2;
|
||||
if( len > 2 )
|
||||
len = ( ptr - My_Connections[Idx].rbuf ) + delta;
|
||||
if( len > delta )
|
||||
{
|
||||
/* Es wurde ein Request gelesen */
|
||||
if( ! Parse_Request( Idx, My_Connections[Idx].rbuf )) return;
|
||||
@ -578,7 +619,7 @@ LOCAL VOID Read_Request( CONN_ID Idx )
|
||||
My_Connections[Idx].rdatalen -= len;
|
||||
memmove( My_Connections[Idx].rbuf, My_Connections[Idx].rbuf + len, My_Connections[Idx].rdatalen );
|
||||
}
|
||||
} /* Read_Request */
|
||||
} /* Handle_Buffer */
|
||||
|
||||
|
||||
/* -eof- */
|
||||
|
Loading…
Reference in New Issue
Block a user