Async Watcher Issue on Windows
Anton Kirilov
akirilov at minervanetworks.com
Thu Feb 16 17:07:13 CET 2012
Hello,
I have stumbled upon an issue with async watchers on Windows that has been previously reported on the mail list - ev_async_send() fails (silently) to signal the watcher. My OS is Windows XP SP3, and I have a fully updated version of Visual C++ Express 2010.
The problem is caused by the fact that in my case the implementation of write() uses WriteFile(), but seems to assume that the handle associated with the passed file descriptor is not in overlapped mode, always sets the lpOverlapped parameter to NULL, and the lpNumberOfBytesWritten
argument to a non-NULL value. Furthermore, socket() creates a socket in overlapped mode by default according to MSDN:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms740506(v=vs.85).aspx
Finally, WriteFile() fails because it has specific expectations for its parameters that are not satisfied, as documented here:
http://msdn.microsoft.com/en-us/library/windows/desktop/aa365747(v=vs.85).aspx
The solution is simple - call WSASocket() instead of socket(), since the former allows us to set or unset the overlapped attribute explicitly. It is also identical with respect to OS version, header file and library dependencies.
I have attached a sample patch; would you please merge it into the libev source code?
Yours faithfully,
Anton Kirilov
--- ev_win32.c.orig 2011-02-16 10:02:50.000000000 +0200
+++ ev_win32.c 2012-02-16 17:06:19.598675577 +0200
@@ -59,7 +59,7 @@
SOCKET listener;
SOCKET sock [2] = { -1, -1 };
- if ((listener = socket (AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET)
+ if ((listener = WSASocket (AF_INET, SOCK_STREAM, 0, NULL, 0, 0)) == INVALID_SOCKET)
return -1;
addr.sin_family = AF_INET;
More information about the libev
mailing list