1
0
mirror of https://github.com/osmarks/ngircd.git synced 2024-12-12 09:50:29 +00:00

remove ZBUFFER constants and increase max buffer size of server links

This commit is contained in:
Florian Westphal 2007-05-09 08:55:14 +00:00
parent 508b55126f
commit 09416f36bf
3 changed files with 33 additions and 32 deletions

View File

@ -22,7 +22,7 @@
/* enable more zlib related debug messages: */
/* #define DEBUG_ZLIB */
static char UNUSED id[] = "$Id: conn-zip.c,v 1.11 2006/07/23 15:19:20 alex Exp $";
static char UNUSED id[] = "$Id: conn-zip.c,v 1.12 2007/05/09 08:55:14 fw Exp $";
#include "imp.h"
#include <assert.h>
@ -85,22 +85,23 @@ Zip_InitConn( CONN_ID Idx )
GLOBAL bool
Zip_Buffer( CONN_ID Idx, char *Data, size_t Len )
{
/* Daten zum Komprimieren im "Kompressions-Puffer" sammeln.
* Es wird true bei Erfolg, sonst false geliefert. */
size_t buflen;
assert( Idx > NONE );
assert( Data != NULL );
assert( Len > 0 );
assert( Len <= ZWRITEBUFFER_LEN );
if (Len > ZWRITEBUFFER_LEN)
return false;
if ( array_bytes( &My_Connections[Idx].zip.wbuf ) >= ZWRITEBUFFER_LEN ) {
buflen = array_bytes(&My_Connections[Idx].zip.wbuf);
if (buflen >= WRITEBUFFER_LEN) {
/* compression buffer is full, flush */
if( ! Zip_Flush( Idx )) return false;
}
/* check again; if zip buf is still too large do not append data:
* otherwise the zip wbuf would grow too large */
buflen = array_bytes(&My_Connections[Idx].zip.wbuf);
if (buflen >= WRITEBUFFER_LEN)
return false;
return array_catb(&My_Connections[Idx].zip.wbuf, Data, Len);
} /* Zip_Buffer */
@ -140,6 +141,7 @@ Zip_Flush( CONN_ID Idx )
}
assert(out->avail_out <= WRITEBUFFER_LEN);
assert(out->avail_out > 0); /* 0 might indicate not all data was compressed... */
zipbuf_used = WRITEBUFFER_LEN - out->avail_out;
#ifdef DEBUG_ZIP
Log(LOG_DEBUG, "zipbuf_used: %d", zipbuf_used);

View File

@ -17,7 +17,7 @@
#include "portab.h"
#include "io.h"
static char UNUSED id[] = "$Id: conn.c,v 1.205 2007/05/02 12:34:31 fw Exp $";
static char UNUSED id[] = "$Id: conn.c,v 1.206 2007/05/09 08:55:14 fw Exp $";
#include "imp.h"
#include <assert.h>
@ -613,10 +613,16 @@ Conn_Write( CONN_ID Idx, char *Data, size_t Len )
/* Daten in Socket schreiben. Bei "fatalen" Fehlern wird
* der Client disconnectiert und false geliefert. */
CLIENT *c;
size_t writebuf_limit = WRITEBUFFER_LEN;
assert( Idx > NONE );
assert( Data != NULL );
assert( Len > 0 );
c = Conn_GetClient(Idx);
assert( c != NULL);
if (Client_Type(c) == CLIENT_SERVER)
writebuf_limit = WRITEBUFFER_LEN * 10;
/* Ist der entsprechende Socket ueberhaupt noch offen? In einem
* "Handler-Durchlauf" kann es passieren, dass dem nicht mehr so
* ist, wenn einer von mehreren Conn_Write()'s fehlgeschlagen ist.
@ -629,14 +635,15 @@ Conn_Write( CONN_ID Idx, char *Data, size_t Len )
/* Pruefen, ob im Schreibpuffer genuegend Platz ist. Ziel ist es,
* moeglichts viel im Puffer zu haben und _nicht_ gleich alles auf den
* Socket zu schreiben (u.a. wg. Komprimierung). */
if( array_bytes(&My_Connections[Idx].wbuf) >= WRITEBUFFER_LEN) {
if (array_bytes(&My_Connections[Idx].wbuf) >= writebuf_limit) {
/* Der Puffer ist dummerweise voll. Jetzt versuchen, den Puffer
* zu schreiben, wenn das nicht klappt, haben wir ein Problem ... */
if( ! Handle_Write( Idx )) return false;
/* check again: if our writebuf is twice als large as the initial limit: Kill connection */
if( array_bytes(&My_Connections[Idx].wbuf) >= (WRITEBUFFER_LEN*2)) {
Log( LOG_NOTICE, "Write buffer overflow (connection %d)!", Idx );
if (array_bytes(&My_Connections[Idx].wbuf) >= (writebuf_limit*2)) {
Log(LOG_NOTICE, "Write buffer overflow (connection %d, size %lu byte)!", Idx,
(unsigned long) array_bytes(&My_Connections[Idx].wbuf));
Conn_Close( Idx, "Write buffer overflow!", NULL, false );
return false;
}
@ -1048,18 +1055,22 @@ Read_Request( CONN_ID Idx )
/* Daten von Socket einlesen und entsprechend behandeln.
* Tritt ein Fehler auf, so wird der Socket geschlossen. */
size_t readbuf_limit = READBUFFER_LEN;
ssize_t len;
char readbuf[1024];
char readbuf[READBUFFER_LEN];
CLIENT *c;
assert( Idx > NONE );
assert( My_Connections[Idx].sock > NONE );
c = Conn_GetClient(Idx);
assert ( c != NULL);
if (Client_Type(c) == CLIENT_SERVER)
readbuf_limit = READBUFFER_LEN * 10;
#ifdef ZLIB
if (( array_bytes(&My_Connections[Idx].rbuf) >= READBUFFER_LEN ) ||
( array_bytes(&My_Connections[Idx].zip.rbuf) >= ZREADBUFFER_LEN ))
if ((array_bytes(&My_Connections[Idx].rbuf) >= readbuf_limit) ||
(array_bytes(&My_Connections[Idx].zip.rbuf) >= readbuf_limit))
#else
if ( array_bytes(&My_Connections[Idx].rbuf) >= READBUFFER_LEN )
if (array_bytes(&My_Connections[Idx].rbuf) >= readbuf_limit)
#endif
{
/* Der Lesepuffer ist voll */
@ -1069,7 +1080,7 @@ Read_Request( CONN_ID Idx )
return;
}
len = read( My_Connections[Idx].sock, readbuf, sizeof readbuf -1 );
len = read(My_Connections[Idx].sock, readbuf, sizeof(readbuf));
if( len == 0 ) {
Log( LOG_INFO, "%s:%d (%s) is closing the connection ...",
My_Connections[Idx].host, ntohs( My_Connections[Idx].addr.sin_port),
@ -1218,11 +1229,6 @@ Handle_Buffer( CONN_ID Idx )
/* The last Command activated Socket-Compression.
* Data that was read after that needs to be copied to Unzip-buf
* for decompression */
if( array_bytes(&My_Connections[Idx].rbuf)> ZREADBUFFER_LEN ) {
Log( LOG_ALERT, "Connection %d: No space left in unzip buf (need %u bytes)!",
Idx, array_bytes(&My_Connections[Idx].rbuf ));
return false;
}
if (!array_copy( &My_Connections[Idx].zip.rbuf, &My_Connections[Idx].rbuf ))
return false;

View File

@ -8,7 +8,7 @@
* (at your option) any later version.
* Please read the file COPYING, README and AUTHORS for more information.
*
* $Id: defines.h,v 1.58 2006/06/15 20:28:15 alex Exp $
* $Id: defines.h,v 1.59 2007/05/09 08:55:14 fw Exp $
*/
@ -66,18 +66,11 @@
#define COMMAND_LEN 513 /* Max. IRC command length, see. RFC
2812 section 3.2 */
#define READBUFFER_LEN 2048 /* Size of the read buffer of a
#define READBUFFER_LEN 4096 /* Size of the read buffer of a
connection in bytes. */
#define WRITEBUFFER_LEN 4096 /* Size of the write buffer of a
connection in bytes. */
#ifdef ZLIB
#define ZREADBUFFER_LEN 1024 /* Size of the compressed read buffer
of a connection in bytes. */
#define ZWRITEBUFFER_LEN 4096 /* Size of the compressed write buffer
of a connection in bytes. */
#endif
#define PROTOVER "0210" /* Implemented IRC protocol version,
see RFC 2813 section 4.1.1. */
#define PROTOIRC "-IRC" /* Protocol suffix, see RFC 2813