]> arthur.barton.de Git - ngircd-alex.git/blobdiff - src/ngircd/conn.c
Add Doxygen @file documentation to each source and header file
[ngircd-alex.git] / src / ngircd / conn.c
index b798e6e75cd51b44eccf2c5c9e553505b77c0d81..e73dd3060e9d51887f21a610418c34b408e4c7f6 100644 (file)
@@ -7,8 +7,6 @@
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version.
  * Please read the file COPYING, README and AUTHORS for more information.
- *
- * Connection management
  */
 
 
 #include "conf-ssl.h"
 #include "io.h"
 
+/**
+ * @file
+ * Connection management
+ */
+
 #include "imp.h"
 #include <assert.h>
 #ifdef PROTOTYPES
@@ -238,8 +241,10 @@ cb_connserver(int sock, UNUSED short what)
 static void
 server_login(CONN_ID idx)
 {
-       Log( LOG_INFO, "Connection %d with \"%s:%d\" established. Now logging in ...", idx,
-                       My_Connections[idx].host, Conf_Server[Conf_GetServer( idx )].port );
+       Log(LOG_INFO,
+           "Connection %d (socket %d) with \"%s:%d\" established. Now logging in ...",
+           idx, My_Connections[idx].sock, My_Connections[idx].host,
+           Conf_Server[Conf_GetServer(idx)].port);
 
        io_event_setcb( My_Connections[idx].sock, cb_clientserver);
        io_event_add( My_Connections[idx].sock, IO_WANTREAD|IO_WANTWRITE);
@@ -856,7 +861,7 @@ static bool
 Conn_Write( CONN_ID Idx, char *Data, size_t Len )
 {
        CLIENT *c;
-       size_t writebuf_limit = WRITEBUFFER_LEN;
+       size_t writebuf_limit = WRITEBUFFER_MAX_LEN;
        assert( Idx > NONE );
        assert( Data != NULL );
        assert( Len > 0 );
@@ -892,7 +897,7 @@ Conn_Write( CONN_ID Idx, char *Data, size_t Len )
                /* Uncompressed link:
                 * Check if outbound buffer has enough space for the data. */
                if (array_bytes(&My_Connections[Idx].wbuf) + Len >=
-                   writebuf_limit) {
+                   WRITEBUFFER_FLUSH_LEN) {
                        /* Buffer is full, flush it. Handle_Write deals with
                         * low-level errors, if any. */
                        if (!Handle_Write(Idx))
@@ -904,8 +909,8 @@ Conn_Write( CONN_ID Idx, char *Data, size_t Len )
                if (array_bytes(&My_Connections[Idx].wbuf) + Len >=
                    writebuf_limit) {
                        Log(LOG_NOTICE,
-                           "Write buffer overflow (connection %d, size %lu byte)!",
-                           Idx,
+                           "Write buffer overflow (connection %d, limit is %lu bytes, %lu bytes new, %lu bytes pending)!",
+                           Idx, writebuf_limit, Len,
                            (unsigned long)array_bytes(&My_Connections[Idx].wbuf));
                        Conn_Close(Idx, "Write buffer overflow!", NULL, false);
                        return false;
@@ -978,7 +983,7 @@ Conn_Close( CONN_ID Idx, const char *LogMsg, const char *FwdMsg, bool InformClie
                if (FwdMsg)
                        Conn_WriteStr(Idx, "ERROR :%s", FwdMsg);
                else
-                       Conn_WriteStr(Idx, "ERROR :Closing connection.");
+                       Conn_WriteStr(Idx, "ERROR :Closing connection");
        }
 
        /* Try to write out the write buffer. Note: Handle_Write() eventually
@@ -1274,7 +1279,7 @@ New_Connection(int Sock)
                    "Refused connection from %s: too may connections (%ld) from this IP address!",
                    ip_str, cnt);
                Simple_Message(new_sock,
-                              "ERROR :Connection refused, too many connections from your IP address!");
+                              "ERROR :Connection refused, too many connections from your IP address");
                close(new_sock);
                return -1;
        }
@@ -1453,16 +1458,21 @@ Read_Request( CONN_ID Idx )
 
        /* Update connection statistics */
        My_Connections[Idx].bytes_in += len;
+       My_Connections[Idx].bps += Handle_Buffer(Idx);
+
+       /* Make sure that there is still a valid client registered */
+       c = Conn_GetClient(Idx);
+       if (!c)
+               return;
 
        /* Update timestamp of last data received if this connection is
         * registered as a user, server or service connection. Don't update
         * otherwise, so users have at least Conf_PongTimeout seconds time to
         * register with the IRC server -- see Check_Connections().
         * Update "lastping", too, if time shifted backwards ... */
-       c = Conn_GetClient(Idx);
-       if (c && (Client_Type(c) == CLIENT_USER
-                 || Client_Type(c) == CLIENT_SERVER
-                 || Client_Type(c) == CLIENT_SERVICE)) {
+       if (Client_Type(c) == CLIENT_USER
+           || Client_Type(c) == CLIENT_SERVER
+           || Client_Type(c) == CLIENT_SERVICE) {
                t = time(NULL);
                if (My_Connections[Idx].lastdata != t)
                        My_Connections[Idx].bps = 0;
@@ -1473,7 +1483,6 @@ Read_Request( CONN_ID Idx )
        }
 
        /* Look at the data in the (read-) buffer of this connection */
-       My_Connections[Idx].bps += Handle_Buffer(Idx);
        if (Client_Type(c) != CLIENT_SERVER
            && Client_Type(c) != CLIENT_UNKNOWNSERVER
            && Client_Type(c) != CLIENT_SERVICE
@@ -1765,14 +1774,17 @@ New_Server( int Server , ng_ipaddr_t *dest)
                return;
        }
 
-       Log(LOG_INFO, "Establishing connection for \"%s\" to \"%s\" (%s) port %d ... ",
-           Conf_Server[Server].name, Conf_Server[Server].host, ip_str,
-           Conf_Server[Server].port);
-
        af_dest = ng_ipaddr_af(dest);
        new_sock = socket(af_dest, SOCK_STREAM, 0);
+
+       Log(LOG_INFO,
+           "Establishing connection for \"%s\" to \"%s:%d\" (%s), socket %d ...",
+           Conf_Server[Server].name, Conf_Server[Server].host,
+           Conf_Server[Server].port, ip_str, new_sock);
+
        if (new_sock < 0) {
-               Log( LOG_CRIT, "Can't create socket (af %d) : %s!", af_dest, strerror( errno ));
+               Log(LOG_CRIT, "Can't create socket (af %d): %s!",
+                   af_dest, strerror(errno));
                return;
        }