ret->config = config_create();
ret->scans = list_create();
ret->protocols = list_create();
+ ret->fd_use = 0;
return ret;
}
void check_establish(OPM_T *scanner)
{
node_t *node1, *node2;
+ unsigned int fd_limit;
OPM_SCAN_T *scan;
OPM_CONNECTION_T *conn;
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);
if(conn->state == OPM_STATE_CLOSED)
{
+
close(conn->fd);
+ scanner->fd_use--;
+
list_remove(scan->connections, node2);
connection_free(conn);
node_free(node2);
if((present - conn->creation) > timeout)
{
+
close(conn->fd);
+ scanner->fd_use--;
+
list_remove(scan->connections, node2);
connection_free(conn);
node_free(node2);
conn->state = OPM_STATE_ESTABLISHED;
time(&(conn->creation)); /* Stamp creation time, for timeout */
+ scanner->fd_use++; /* Increase file descriptor use */
}
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 {