Try both fd and socket ops for net_read() and net_write()
When using WinSock, a socket is not a file descriptor and does not interoperate with read()/write(). File descriptors do not work with send()/recv(). However, for net_read() and net_write(), we don't know whether we are dealing with a socket or a file descriptor. So try one, and if it fails, try the other. This is an ugly hack until we clean up the users of this API so it doesn't use sockets and fds interchangably.
This commit is contained in:
@@ -70,9 +70,27 @@ net_write(rk_socket_t sock, const void *buf, size_t nbytes)
|
||||
const char *cbuf = (const char *)buf;
|
||||
ssize_t count;
|
||||
size_t rem = nbytes;
|
||||
#ifdef SOCKET_IS_NOT_AN_FD
|
||||
int use_write = 0;
|
||||
#endif
|
||||
|
||||
while (rem > 0) {
|
||||
#ifdef SOCKET_IS_NOT_AN_FD
|
||||
if (use_write)
|
||||
count = _write (sock, cbuf, rem);
|
||||
else
|
||||
count = send (sock, cbuf, rem, 0);
|
||||
|
||||
if (use_write == 0 &&
|
||||
rk_IS_SOCKET_ERROR(count) &&
|
||||
rk_SOCK_ERRNO == WSAENOTSOCK) {
|
||||
use_write = 1;
|
||||
|
||||
count = _write (sock, cbuf, rem);
|
||||
}
|
||||
#else
|
||||
count = send (sock, cbuf, rem, 0);
|
||||
#endif
|
||||
if (count < 0) {
|
||||
if (errno == EINTR)
|
||||
continue;
|
||||
|
Reference in New Issue
Block a user