Windows: Fix use of file descriptors as sockets
authorAsanka Herath <asanka@secure-endpoints.com>
Tue, 24 Aug 2010 04:02:12 +0000 (00:02 -0400)
committerAsanka C. Herath <asanka@secure-endpoints.com>
Tue, 14 Sep 2010 12:03:31 +0000 (08:03 -0400)
Sockets and file descriptors are not interchangeable on Windows.  The
test for checking whether a given value is a socket or an FD was
broken for the case where WinSock was not initialized to begin with.

lib/roken/net_read.c
lib/roken/net_write.c

index 1f959db9588042ab4d6d042b8c7bd21a3ab21cf6..df1ac53def10c3dfc64212e5be988d5bb8dd3fe5 100644 (file)
@@ -86,7 +86,8 @@ net_read(rk_socket_t sock, void *buf, size_t nbytes)
 
        if (use_read == 0 &&
            rk_IS_SOCKET_ERROR(count) &&
-           rk_SOCK_ERRNO == WSAENOTSOCK) {
+            (rk_SOCK_ERRNO == WSANOTINITIALISED ||
+             rk_SOCK_ERRNO == WSAENOTSOCK)) {
            use_read = 1;
 
            count = _read (sock, cbuf, rem);
index 402e209152bf56e8599ced6a34dd88ee83658ff5..e1cfa99074ee29365391feafc3b52bcdb9bf0029 100644 (file)
@@ -83,7 +83,8 @@ net_write(rk_socket_t sock, const void *buf, size_t nbytes)
 
        if (use_write == 0 &&
            rk_IS_SOCKET_ERROR(count) &&
-           rk_SOCK_ERRNO == WSAENOTSOCK) {
+           (rk_SOCK_ERRNO == WSANOTINITIALISED ||
+             rk_SOCK_ERRNO == WSAENOTSOCK)) {
            use_write = 1;
 
            count = _write (sock, cbuf, rem);