Use a mutex to allow the TAP reader to process packets faster on Windows.

The TAP-Win32 device is not a socket, and select() under Windows only works
with sockets.  Tinc used a separate thread to read from the TAP-Win32 device,
and passed this via a local socket to the main thread which could then select()
from it. We now use a global mutex, which is only unlocked when the main thread
is waiting for select(), to allow the TAP reader thread to process packets
directly.
This commit is contained in:
Guus Sliepen 2009-09-15 22:59:01 +02:00
parent 802a50ffcd
commit b47c17bcde
4 changed files with 25 additions and 117 deletions

View file

@ -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;
@ -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);
@ -378,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) {