patch: fix WSARecv invocation; report WSA errors
Denis Bilenko
denis.bilenko at gmail.com
Fri May 11 23:43:22 CEST 2012
WSARecv() sometimes fails with WSAEFAULT if lpFlags parameter is zero.
See comment at the end of this page:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms741688%28v=vs.85%29.aspx
The patch below fixes that. It also reports errors to stderr so that
bugs like this are easier to catch in the future.
--- /home/denis/work/libev-cvs/ev.c 2012-05-10 20:47:37.064383729 +0400
+++ libev/ev.c 2012-05-12 01:36:54.925647219 +0400
@@ -1880,7 +1880,17 @@
DWORD sent;
buf.buf = &buf;
buf.len = 1;
- WSASend (EV_FD_TO_WIN32_HANDLE (evpipe [1]), &buf, 1,
&sent, 0, 0, 0);
+ if (WSASend(EV_FD_TO_WIN32_HANDLE (evpipe [1]), &buf, 1,
&sent, 0, 0, 0))
+ {
+ int error;
+ error = GetLastError();
+ if (error != WSAEWOULDBLOCK)
+#if EV_AVOID_STDIO
+ ev_printerr ("(libev) WSASend failed.\n");
+#else
+ fprintf(stderr, "(libev) WSASend failed with error
%d\n", error);
+#endif
+ }
#else
write (evpipe [1], &(evpipe [1]), 1);
#endif
@@ -1912,9 +1922,22 @@
#ifdef _WIN32
WSABUF buf;
DWORD recvd;
+ DWORD flags;
buf.buf = dummy;
buf.len = sizeof (dummy);
- WSARecv (EV_FD_TO_WIN32_HANDLE (evpipe [0]), &buf, 1,
&recvd, 0, 0, 0);
+ flags = 0;
+ if (WSARecv(EV_FD_TO_WIN32_HANDLE(evpipe[0]), &buf, 1,
&recvd, &flags, 0, 0))
+ {
+ int error;
+ error = GetLastError();
+ if (error != WSAEWOULDBLOCK)
+#if EV_AVOID_STDIO
+ ev_printerr ("(libev) WSARecv failed.\n");
+#else
+ fprintf(stderr, "(libev) WSARecv failed with error
%d\n", error);
+#endif
+ }
+
#else
read (evpipe [0], &dummy, sizeof (dummy));
#endif
More information about the libev
mailing list