windows: Provide a read(2) wrapper that uses recv(2) on sockets

This commit is contained in:
Martin Willi
2014-11-21 12:02:08 +01:00
parent f518b52c2d
commit 09624c6cec
2 changed files with 25 additions and 0 deletions
+16
View File
@@ -643,6 +643,22 @@ ssize_t windows_sendto(int sockfd, const void *buf, size_t len, int flags,
return outlen;
}
/**
* See header
*/
#undef read
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 = read(fd, buf, count);
}
return ret;
}
/**
* See header
*/
+9
View File
@@ -362,6 +362,15 @@ ssize_t windows_send(int sockfd, const void *buf, size_t len, int flags);
ssize_t windows_sendto(int sockfd, const void *buf, size_t len, int flags,
const struct sockaddr *dest_addr, socklen_t addrlen);
/**
* read(2) working on files and sockets, cancellable on sockets only
*
* On Windows, there does not seem to be a way how a cancellable read can
* be implemented on Low level I/O functions for files, _pipe()s or stdio.
*/
#define read windows_read
ssize_t windows_read(int fd, void *buf, size_t count);
#if _WIN32_WINNT < 0x0600
/**
* Define pollfd and flags on our own if not specified