/*
* ngIRCd -- The Next Generation IRC Daemon
- * Copyright (c)2001-2018 Alexander Barton (alex@barton.de) and Contributors.
+ * Copyright (c)2001-2019 Alexander Barton (alex@barton.de) and Contributors.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
*/
#define CONN_MODULE
+#define CONN_MODULE_GLOBAL_INIT
#include "portab.h"
struct timeval tv;
time_t t;
+ Log(LOG_NOTICE, "Server \"%s\" (on \"%s\") ready.",
+ Client_ID(Client_ThisServer()), Client_Hostname(Client_ThisServer()));
+
while (!NGIRCd_SignalQuit && !NGIRCd_SignalRestart) {
t = time(NULL);
* the calculation of in_p and out_p: in_z_k and out_z_k
* are non-zero, that's guaranteed by the protocol until
* compression can be enabled. */
- if (! in_z_k)
+ if (in_z_k <= 0)
in_z_k = in_k;
- if (! out_z_k)
+ if (out_z_k <= 0)
out_z_k = out_k;
in_p = (int)(( in_k * 100 ) / in_z_k );
out_p = (int)(( out_k * 100 ) / out_z_k );
if (errno == EAGAIN || errno == EINTR)
return true;
+ /* Log write errors but do not close the connection yet.
+ * Calling Conn_Close() now could result in too many recursive calls.
+ */
if (!Conn_OPTION_ISSET(&My_Connections[Idx], CONN_ISCLOSING))
Log(LOG_ERR,
"Write error on connection %d (socket %d): %s!",
else
LogDebug("Recursive write error on connection %d (socket %d): %s!",
Idx, My_Connections[Idx].sock, strerror(errno));
- Conn_Close(Idx, "Write error", NULL, false);
+
return false;
}
Read_Request( CONN_ID Idx )
{
ssize_t len;
+ size_t readbuf_limit = READBUFFER_LEN;
static const unsigned int maxbps = COMMAND_LEN / 2;
- char readbuf[READBUFFER_LEN];
+ char readbuf[READBUFFER_MAX_LEN];
time_t t;
CLIENT *c;
assert( Idx > NONE );
assert( My_Connections[Idx].sock > NONE );
+ /* Make sure that there still exists a CLIENT structure associated
+ * with this connection and check if this is a server or not: */
+ c = Conn_GetClient(Idx);
+ if (c) {
+ /* Servers do get special read buffer limits, so they can
+ * process all the messages that are required while peering. */
+ if (Client_Type(c) == CLIENT_SERVER)
+ readbuf_limit = READBUFFER_SLINK_LEN;
+ } else
+ LogDebug("Read request without client (connection %d)!?", Idx);
+
#ifdef ZLIB
- if ((array_bytes(&My_Connections[Idx].rbuf) >= READBUFFER_LEN) ||
- (array_bytes(&My_Connections[Idx].zip.rbuf) >= READBUFFER_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
{
/* Read buffer is full */
Log(LOG_ERR,
"Receive buffer space exhausted (connection %d): %d/%d bytes",
- Idx, array_bytes(&My_Connections[Idx].rbuf), READBUFFER_LEN);
+ Idx, array_bytes(&My_Connections[Idx].rbuf), readbuf_limit);
Conn_Close(Idx, "Receive buffer space exhausted", NULL, false);
return;
}
#ifdef SSL_SUPPORT
if (Conn_OPTION_ISSET(&My_Connections[Idx], CONN_SSL))
- len = ConnSSL_Read( &My_Connections[Idx], readbuf, sizeof(readbuf));
+ len = ConnSSL_Read( &My_Connections[Idx], readbuf, readbuf_limit);
else
#endif
- len = read(My_Connections[Idx].sock, readbuf, sizeof(readbuf));
+ len = read(My_Connections[Idx].sock, readbuf, readbuf_limit);
if (len == 0) {
LogDebug("Client \"%s:%u\" is closing connection %d ...",
My_Connections[Idx].host,