summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlexander Barton <alex@barton.de>2020-05-01 23:41:49 +0200
committerAlexander Barton <alex@barton.de>2020-05-04 00:46:56 +0200
commit9f05f5ee61d23292d55edef09439c38936b86037 (patch)
tree49d42b2ab1592b67c4d34f342db3097c500bb8b4
parent629a45ee0f4469729f6a9c22a983000fcc39fe61 (diff)
downloadngircd-9f05f5ee61d23292d55edef09439c38936b86037.tar.gz
ngircd-9f05f5ee61d23292d55edef09439c38936b86037.zip
Read_Request(): Clean up code and add some more comments
No functional changes.
-rw-r--r--src/ngircd/conn.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/src/ngircd/conn.c b/src/ngircd/conn.c
index 92d9939a..7d1576e1 100644
--- a/src/ngircd/conn.c
+++ b/src/ngircd/conn.c
@@ -1543,15 +1543,16 @@ Socket2Index( int Sock )
  * @param Idx	Connection index.
  */
 static void
-Read_Request( CONN_ID Idx )
+Read_Request(CONN_ID Idx)
 {
 	ssize_t len;
 	static const unsigned int maxbps = COMMAND_LEN / 2;
 	char readbuf[READBUFFER_LEN];
 	time_t t;
 	CLIENT *c;
-	assert( Idx > NONE );
-	assert( My_Connections[Idx].sock > NONE );
+
+	assert(Idx > NONE);
+	assert(My_Connections[Idx].sock > NONE);
 
 #ifdef ZLIB
 	if ((array_bytes(&My_Connections[Idx].rbuf) >= READBUFFER_LEN) ||
@@ -1568,12 +1569,14 @@ Read_Request( CONN_ID Idx )
 		return;
 	}
 
+	/* Now read new data from the network, up to READBUFFER_LEN bytes ... */
 #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, sizeof(readbuf));
 	else
 #endif
-	len = read(My_Connections[Idx].sock, readbuf, sizeof(readbuf));
+		len = read(My_Connections[Idx].sock, readbuf, sizeof(readbuf));
+
 	if (len == 0) {
 		LogDebug("Client \"%s:%u\" is closing connection %d ...",
 			 My_Connections[Idx].host,
@@ -1583,13 +1586,20 @@ Read_Request( CONN_ID Idx )
 	}
 
 	if (len < 0) {
-		if( errno == EAGAIN ) return;
+		if (errno == EAGAIN)
+			return;
+
 		Log(LOG_ERR, "Read error on connection %d (socket %d): %s!",
 		    Idx, My_Connections[Idx].sock, strerror(errno));
 		Conn_Close(Idx, "Read error", "Client closed connection",
 			   false);
 		return;
 	}
+
+	/* Now append the newly received data to the connection buffer.
+	 * NOTE: This can lead to connection read buffers being bigger(!) than
+	 * READBUFFER_LEN bytes, as we add up to READBUFFER_LEN new bytes to a
+	 * buffer possibly being "almost" READBUFFER_LEN bytes already! */
 #ifdef ZLIB
 	if (Conn_OPTION_ISSET(&My_Connections[Idx], CONN_ZIP)) {
 		if (!array_catb(&My_Connections[Idx].zip.rbuf, readbuf,