Use a mutex to allow the TAP reader to process packets faster on Windows.
[tinc] / src / net.c
index 910e86d..82b0ede 100644 (file)
--- a/src/net.c
+++ b/src/net.c
@@ -149,7 +149,8 @@ static int build_fdset(fd_set *readset, fd_set *writeset)
                        max = listen_socket[i].udp;
        }
 
-       FD_SET(device_fd, readset);
+       if(device_fd >= 0)
+               FD_SET(device_fd, readset);
        if(device_fd > max)
                max = device_fd;
        
@@ -251,7 +252,7 @@ static void check_dead_connections(void)
                        } else {
                                if(c->status.remove) {
                                        logger(LOG_WARNING, _("Old connection_t for %s (%s) status %04x still lingering, deleting..."),
-                                                  c->name, c->hostname, *(uint32_t *)&c->status);
+                                                  c->name, c->hostname, bitfield_to_int(&c->status, sizeof c->status));
                                        connection_del(c);
                                        continue;
                                }
@@ -294,7 +295,7 @@ static void check_network_activity(fd_set * readset, fd_set * writeset)
        cp();
 
        /* check input from kernel */
-       if(FD_ISSET(device_fd, readset)) {
+       if(device_fd >= 0 && FD_ISSET(device_fd, readset)) {
                if(read_packet(&packet)) {
                        packet.priority = 0;
                        route(myself, &packet);
@@ -366,7 +367,6 @@ int main_loop(void)
        last_graph_dump = now;
        
        srand(now);
-       srand48(now);
 
        running = true;
 
@@ -379,7 +379,13 @@ int main_loop(void)
 
                maxfd = build_fdset(&readset, &writeset);
 
+#ifdef HAVE_MINGW
+               LeaveCriticalSection(&mutex);
+#endif
                r = select(maxfd + 1, &readset, &writeset, NULL, &tv);
+#ifdef HAVE_MINGW
+               EnterCriticalSection(&mutex);
+#endif
 
                if(r < 0) {
                        if(errno != EINTR && errno != EAGAIN) {