]> arthur.barton.de Git - ngircd-alex.git/blobdiff - src/ngircd/conn.c
New function Conn_GetProcStat()
[ngircd-alex.git] / src / ngircd / conn.c
index 91ff779677c969ec9b8ee299de386cd75f606097..f4efff1655002f5687b44b8beb9f9cb38c90fbf2 100644 (file)
@@ -68,7 +68,6 @@
 #include "log.h"
 #include "ng_ipaddr.h"
 #include "parse.h"
-#include "proc.h"
 #include "resolve.h"
 #include "tool.h"
 
@@ -756,7 +755,8 @@ Conn_Handler(void)
                                continue; /* TLS/SSL layer needs to write data; deal with this first */
 #endif
                        if (Proc_InProgress(&My_Connections[i].proc_stat)) {
-                               /* Wait for completion of resolver sub-process ... */
+                               /* Wait for completion of forked subprocess
+                                * and ignore the socket in the meantime ... */
                                io_event_del(My_Connections[i].sock,
                                             IO_WANTREAD);
                                continue;
@@ -772,6 +772,7 @@ Conn_Handler(void)
                                             IO_WANTREAD);
                                continue;
                        }
+
                        io_event_add(My_Connections[i].sock, IO_WANTREAD);
                }
 
@@ -1073,7 +1074,7 @@ Conn_Close( CONN_ID Idx, const char *LogMsg, const char *FwdMsg, bool InformClie
                    in_k, out_k);
        }
 
-       /* cancel running resolver */
+       /* Kill possibly running subprocess */
        if (Proc_InProgress(&My_Connections[Idx].proc_stat))
                Proc_Kill(&My_Connections[Idx].proc_stat);
 
@@ -1380,11 +1381,6 @@ New_Connection(int Sock)
                Resolve_Addr(&My_Connections[new_sock].proc_stat, &new_addr,
                             identsock, cb_Read_Resolver_Result);
 
-       /* ngIRCd waits up to 4 seconds for the result of the asynchronous
-        * DNS and IDENT resolver subprocess using the "penalty" mechanism.
-        * If there are results earlier, the delay is aborted. */
-       Conn_SetPenalty(new_sock, 4);
-
        Account_Connection();
        return new_sock;
 } /* New_Connection */
@@ -1989,7 +1985,7 @@ cb_Read_Resolver_Result( int r_fd, UNUSED short events )
         * IDENT user name.*/
 
        CLIENT *c;
-       int i;
+       CONN_ID i;
        size_t len;
        char *identptr;
 #ifdef IDENTAUTH
@@ -1999,14 +1995,8 @@ cb_Read_Resolver_Result( int r_fd, UNUSED short events )
 #endif
 
        LogDebug("Resolver: Got callback on fd %d, events %d", r_fd, events );
-
-       /* Search associated connection ... */
-       for( i = 0; i < Pool_Size; i++ ) {
-               if(( My_Connections[i].sock != NONE )
-                 && (Proc_GetPipeFd(&My_Connections[i].proc_stat) == r_fd))
-                       break;
-       }
-       if( i >= Pool_Size ) {
+       i = Conn_GetFromProc(r_fd);
+       if (i == NONE) {
                /* Ops, none found? Probably the connection has already
                 * been closed!? We'll ignore that ... */
                io_close( r_fd );
@@ -2058,8 +2048,6 @@ cb_Read_Resolver_Result( int r_fd, UNUSED short events )
 #ifdef DEBUG
                else Log( LOG_DEBUG, "Resolver: discarding result for already registered connection %d.", i );
 #endif
-       /* Reset penalty time */
-       Conn_ResetPenalty( i );
 } /* cb_Read_Resolver_Result */
 
 
@@ -2110,6 +2098,42 @@ Conn_GetClient( CONN_ID Idx )
        return c ? c->client : NULL;
 }
 
+/**
+ * Get PROC_STAT sub-process structure of a connection.
+ * @param Idx Connection index number
+ * @return PROC_STAT structure
+ */
+GLOBAL PROC_STAT *
+Conn_GetProcStat(CONN_ID Idx)
+{
+       CONNECTION *c;
+
+       assert(Idx >= 0);
+       c = array_get(&My_ConnArray, sizeof (CONNECTION), (size_t)Idx);
+       assert(c != NULL);
+       return &c->proc_stat;
+} /* Conn_GetProcStat */
+
+
+/**
+ * Get CONN_ID from file descriptor associated to a subprocess structure.
+ * @param fd File descriptor
+ * @return CONN_ID or NONE (-1)
+ */
+GLOBAL CONN_ID
+Conn_GetFromProc(int fd)
+{
+       int i;
+
+       assert(fd > 0);
+       for (i = 0; i < Pool_Size; i++) {
+               if ((My_Connections[i].sock != NONE)
+                   && (Proc_GetPipeFd(&My_Connections[i].proc_stat) == fd))
+                       return i;
+       }
+       return NONE;
+} /* Conn_GetFromProc */
+
 
 #ifdef SSL_SUPPORT