]> jfr.im git - irc/ircd-hybrid/libopm.git/commitdiff
Added fd_limit functionality
authorstrtok <redacted>
Mon, 9 Sep 2002 18:44:13 +0000 (18:44 +0000)
committerstrtok <redacted>
Mon, 9 Sep 2002 18:44:13 +0000 (18:44 +0000)
Added unsigned int fd_use in OPM_T

src/libopm.c
src/opm.h

index 17c795c4c0446bc3a26daf8fe5ed20709dc14de4..800049ac21e7925dbe16ac1c10a9573ac0f17ff3 100644 (file)
@@ -93,6 +93,7 @@ OPM_T *opm_create()
    ret->config = config_create();
    ret->scans = list_create();
    ret->protocols = list_create();
+   ret->fd_use = 0;
 
    return ret;
 }
@@ -487,6 +488,7 @@ void opm_cycle(OPM_T *scanner)
 void check_establish(OPM_T *scanner)
 {
    node_t *node1, *node2;
+   unsigned int fd_limit;
 
    OPM_SCAN_T *scan;
    OPM_CONNECTION_T *conn;
@@ -494,11 +496,17 @@ void check_establish(OPM_T *scanner)
    if(LIST_SIZE(scanner->scans) == 0)
       return;
 
+   fd_limit = *(int *) config(scanner->config, OPM_CONFIG_FD_LIMIT);
+
    LIST_FOREACH(node1, scanner->scans->head)
    {
       scan = (OPM_SCAN_T *) node1->data;
       LIST_FOREACH(node2, scan->connections->head)
       {
+         /* Only scan if we have free file descriptors */
+         if(scanner->fd_use >= fd_limit)
+            return;
+
          conn = (OPM_CONNECTION_T *) node2->data;
          if(conn->state == OPM_STATE_UNESTABLISHED)
             do_connect(scanner, scan, conn);
@@ -550,7 +558,10 @@ void check_closed(OPM_T *scanner)
 
          if(conn->state == OPM_STATE_CLOSED)
          {
+
             close(conn->fd);
+            scanner->fd_use--;
+
             list_remove(scan->connections, node2);
             connection_free(conn);
             node_free(node2);
@@ -558,7 +569,10 @@ void check_closed(OPM_T *scanner)
 
          if((present - conn->creation) > timeout)
          {
+
             close(conn->fd);
+            scanner->fd_use--;         
+
             list_remove(scan->connections, node2);
             connection_free(conn);
             node_free(node2);
@@ -616,6 +630,7 @@ void do_connect(OPM_T * scanner, OPM_SCAN_T *scan, OPM_CONNECTION_T *conn)
 
    conn->state = OPM_STATE_ESTABLISHED;
    time(&(conn->creation));   /* Stamp creation time, for timeout */
+   scanner->fd_use++;         /* Increase file descriptor use */
 }
 
 
index 428c59f33b0e912565fdd781027151c5eb8a0fef..2c5f6b64afd241167fc725f129fd30354f93b9d1 100644 (file)
--- a/src/opm.h
+++ b/src/opm.h
@@ -20,6 +20,7 @@ struct _OPM {
    OPM_CONFIG_T *config;               /* Individual scanner configuration */
    list_t       *scans;                /* List of scans (each scan containing a list of connections) */
    list_t       *protocols;            /* List of protocols this scanner handles */
+   unsigned int  fd_use;               /* Number of file descriptors in use */
 };
 
 struct _OPM_REMOTE {