+/*
+ put all file descriptors in an fd_set array
+ While we're at it, purge stuff that needs to be removed.
+*/
+void build_fdset(fd_set *fs)
+{
+ avl_node_t *node, *next;
+ connection_t *c;
+ int i;
+cp
+ FD_ZERO(fs);
+
+ for(node = connection_tree->head; node; node = next)
+ {
+ next = node->next;
+ c = (connection_t *)node->data;
+
+ if(c->status.remove)
+ connection_del(c);
+ else
+ FD_SET(c->socket, fs);
+ }
+
+ if(!connection_tree->head)
+ purge();
+
+ for(i = 0; i < listen_sockets; i++)
+ {
+ FD_SET(listen_socket[i].tcp, fs);
+ FD_SET(listen_socket[i].udp, fs);
+ }
+
+ FD_SET(device_fd, fs);
+cp
+}
+