This commit is contained in:
manojampalam 2016-02-29 20:59:25 -08:00
parent afbfa98759
commit a4163ba0a3
2 changed files with 23 additions and 16 deletions

View File

@ -216,6 +216,7 @@ void socket_syncio_tests()
TEST_START("basic recv s->c"); TEST_START("basic recv s->c");
ret = recv(connect_fd, small_recv_buf, SMALL_RECV_BUF_SIZE, 0); ret = recv(connect_fd, small_recv_buf, SMALL_RECV_BUF_SIZE, 0);
ASSERT_INT_EQ(ret, strlen(small_send_buf)); ASSERT_INT_EQ(ret, strlen(small_send_buf));
small_recv_buf[ret] = '\0';
ASSERT_STRING_EQ(small_send_buf, small_recv_buf); ASSERT_STRING_EQ(small_send_buf, small_recv_buf);
memset(small_recv_buf, 0, sizeof(small_recv_buf)); memset(small_recv_buf, 0, sizeof(small_recv_buf));
TEST_DONE(); TEST_DONE();
@ -225,6 +226,7 @@ void socket_syncio_tests()
ASSERT_INT_EQ(ret, strlen(small_send_buf)); ASSERT_INT_EQ(ret, strlen(small_send_buf));
ret = recv(accept_fd, small_recv_buf, SMALL_RECV_BUF_SIZE, 0); ret = recv(accept_fd, small_recv_buf, SMALL_RECV_BUF_SIZE, 0);
ASSERT_INT_EQ(ret, strlen(small_send_buf)); ASSERT_INT_EQ(ret, strlen(small_send_buf));
small_recv_buf[ret] = '\0';
ASSERT_STRING_EQ(small_send_buf, small_recv_buf); ASSERT_STRING_EQ(small_send_buf, small_recv_buf);
memset(small_recv_buf, 0, sizeof(small_recv_buf)); memset(small_recv_buf, 0, sizeof(small_recv_buf));
TEST_DONE(); TEST_DONE();

View File

@ -13,23 +13,18 @@
static int errno_from_WSAError(int wsaerrno) static int errno_from_WSAError(int wsaerrno)
{ {
switch (wsaerrno) {
if (wsaerrno == WSAEWOULDBLOCK) case WSAEWOULDBLOCK:
{
return EAGAIN; return EAGAIN;
} case WSAEFAULT:
if (wsaerrno == WSAEFAULT)
{
return EFAULT; return EFAULT;
} case WSAEINVAL:
if (wsaerrno == WSAEINVAL)
{
return EINVAL; return EINVAL;
} case WSAESHUTDOWN:
return ECONNRESET;
default:
return wsaerrno; return wsaerrno;
}
} }
int socketio_initialize() { int socketio_initialize() {
@ -271,10 +266,20 @@ int socketio_recv(struct w32_io* pio, void *buf, size_t len, int flags) {
//if io is already pending //if io is already pending
if (pio->read_details.pending) { if (pio->read_details.pending) {
//if recv is now in blocking mode, wait for data to be available
if (w32_io_is_blocking(pio)) {
debug2("socket was previously non-blocing but now in blocking mode, waiting for io");
while (socketio_is_io_available(pio, TRUE) == FALSE) {
if (0 != wait_for_any_event(NULL, 0, INFINITE))
return -1;
}
}
else {
errno = EAGAIN; errno = EAGAIN;
debug2("Read is already pending, io:%p", pio); debug2("Read is already pending, io:%p", pio);
return -1; return -1;
} }
}
//if we have some buffer copy it and return #bytes copied //if we have some buffer copy it and return #bytes copied
if (pio->read_details.remaining) if (pio->read_details.remaining)