unbound: util/winsock_event.h File Reference

unbound 0.1

winsock_event.h File Reference

This file contains interface functions with the WinSock2 API on Windows. More...

## Detailed Description

This file contains interface functions with the WinSock2 API on Windows.

It uses the winsock WSAWaitForMultipleEvents interface on a number of sockets.

Note that windows can only wait for max 64 events at one time.

Also, file descriptors cannot be waited for.

Named pipes are not easily available (and are not usable in select() ). For interprocess communication, it is possible to wait for a hEvent to be signaled by another thread.

When a socket becomes readable, then it will not be flagged as readable again until you have gotten WOULDBLOCK from a recv routine. That means the event handler must store the readability (edge notify) and process the incoming data until it blocks. The function performing recv then has to inform the event handler that the socket has blocked, and the event handler can mark it as such. Thus, this file transforms the edge notify from windows to a level notify that is compatible with UNIX. The WSAEventSelect page says that it does do level notify, as long as you call a recv/write/accept at least once when it is signalled. This last bit is not true, even though documented in server2008 api docs from microsoft, it does not happen at all. Instead you have to test for WSAEWOULDBLOCK on a tcp stream, and only then retest the socket. And before that remember the previous result as still valid.

To stay 'fair', instead of emptying a socket completely, the event handler can test the other (marked as blocking) sockets for new events.

Additionally, TCP accept sockets get special event support.

Socket numbers are not starting small, they can be any number (say 33060). Therefore, bitmaps are not used, but arrays.

on winsock, you must use recv() and send() for TCP reads and writes, not read() and write(), those work only on files.

Also fseek and fseeko do not work if a FILE is not fopen-ed in binary mode.

When under a high load windows gives out lots of errors, from recvfrom on udp sockets for example (WSAECONNRESET). Even though the udp socket has no connection per se.