windows: Provide a read(2) wrapper that uses recv(2) on sockets
This commit is contained in:
@@ -643,6 +643,22 @@ ssize_t windows_sendto(int sockfd, const void *buf, size_t len, int flags,
|
|||||||
return outlen;
|
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
|
* See header
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -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,
|
ssize_t windows_sendto(int sockfd, const void *buf, size_t len, int flags,
|
||||||
const struct sockaddr *dest_addr, socklen_t addrlen);
|
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
|
#if _WIN32_WINNT < 0x0600
|
||||||
/**
|
/**
|
||||||
* Define pollfd and flags on our own if not specified
|
* Define pollfd and flags on our own if not specified
|
||||||
|
|||||||
Reference in New Issue
Block a user