windows: Properly set errno for read/write functions using Winsock
authorMartin Willi <martin@revosec.ch>
Thu, 27 Nov 2014 17:15:45 +0000 (18:15 +0100)
committerMartin Willi <martin@revosec.ch>
Fri, 28 Nov 2014 11:45:58 +0000 (12:45 +0100)
src/libstrongswan/utils/compat/windows.c

index e2be64d..1f22ffa 100644 (file)
@@ -651,8 +651,8 @@ ssize_t windows_read(int fd, void *buf, size_t count)
 {
        ssize_t ret;
 
-       ret = recv(fd, buf, count, 0);
-       if (ret == -1 && WSAGetLastError() == WSAENOTSOCK)
+       ret = wserr(recv(fd, buf, count, 0));
+       if (ret == -1 && errno == ENOTSOCK)
        {
                ret = read(fd, buf, count);
        }
@@ -667,8 +667,8 @@ ssize_t windows_write(int fd, void *buf, size_t count)
 {
        ssize_t ret;
 
-       ret = send(fd, buf, count, 0);
-       if (ret == -1 && WSAGetLastError() == WSAENOTSOCK)
+       ret = wserr(send(fd, buf, count, 0));
+       if (ret == -1 && errno == ENOTSOCK)
        {
                ret = write(fd, buf, count);
        }