diff --git a/contrib/win32/w32-posix-prototype/win32posix/Tests/socketiotests.cpp b/contrib/win32/w32-posix-prototype/win32posix/Tests/socketiotests.cpp index c33f0c3..30a7fc5 100644 --- a/contrib/win32/w32-posix-prototype/win32posix/Tests/socketiotests.cpp +++ b/contrib/win32/w32-posix-prototype/win32posix/Tests/socketiotests.cpp @@ -74,6 +74,9 @@ int socket_prepare(char* ip) return 0; } +#define READ_BUf_SIZE 1024 * 1024 * 2 +#define WRITE_BUF_SIZE 1024 * 1024 * 5 + namespace UnitTests { TEST_CLASS(SocketIOTests) @@ -99,7 +102,7 @@ namespace UnitTests w32posix_done(); } - TEST_METHOD(TestMethod1) + TEST_METHOD(socketio) { int ret; ret = socket_prepare("::1"); @@ -117,10 +120,9 @@ namespace UnitTests set_nonblock(c); set_nonblock(s); -#define WRITE_BUF_SIZE 1024 * 1024 * 5 - char to_write[1024 * 1024 * 5]; //5MB -#define READ_BUf_SIZE 1024 * 1024 * 2 - char read_to[READ_BUf_SIZE]; //2MB + char *to_write = (char*)malloc(WRITE_BUF_SIZE); //5MB + + char *read_to = (char*)malloc(READ_BUf_SIZE); //2MB //write from c, read from s fd_set read_set; @@ -177,7 +179,7 @@ namespace UnitTests } - //Assert::AreEqual(bytes_written, bytes_read, L"", LINE_INFO()); + Assert::AreEqual((bytes_written == bytes_read)? 1:0, TRUE, L"", LINE_INFO()); } TEST_METHOD(TestMethod) diff --git a/contrib/win32/w32-posix-prototype/win32posix/win32posix/socketio.c b/contrib/win32/w32-posix-prototype/win32posix/win32posix/socketio.c index e1a069a..4d8246e 100644 --- a/contrib/win32/w32-posix-prototype/win32posix/win32posix/socketio.c +++ b/contrib/win32/w32-posix-prototype/win32posix/win32posix/socketio.c @@ -716,8 +716,7 @@ int socketio_connect(struct w32_io* pio, const struct sockaddr* name, int namele //close event handle CloseHandle(pio->write_overlapped.hEvent); - pio->write_overlapped.hEvent = 0; - + if (pio->write_details.error) { errno = errno_from_WSAError(pio->write_details.error); debug("ERROR: async io completed with error: %d, io:%p", errno, pio); @@ -726,12 +725,14 @@ int socketio_connect(struct w32_io* pio, const struct sockaddr* name, int namele if (0 != setsockopt(pio->sock, SOL_SOCKET, SO_UPDATE_ACCEPT_CONTEXT, NULL, 0)) { + int i = WSAGetLastError(); errno = errno_from_WSALastError(); debug("ERROR: setsockopt failed:%d, io:%p", errno, pio); - return NULL; + return -1; } - + //Reset any state used during connect + ZeroMemory(&pio->write_details, sizeof(pio->write_details)); pio->type = SOCK_FD; return 0; } diff --git a/contrib/win32/w32-posix-prototype/win32posix/win32posix/w32fd.c b/contrib/win32/w32-posix-prototype/win32posix/win32posix/w32fd.c index 6b3a281..d20acf3 100644 --- a/contrib/win32/w32-posix-prototype/win32posix/win32posix/w32fd.c +++ b/contrib/win32/w32-posix-prototype/win32posix/win32posix/w32fd.c @@ -84,7 +84,7 @@ BOOL w32_io_is_blocking(struct w32_io* pio) } BOOL w32_io_is_io_available(struct w32_io* pio, BOOL rd) { - if ((pio->type == LISTEN_FD) || (pio->type == SOCK_FD)) { + if (pio->type <= SOCK_FD) { return socketio_is_io_available(pio, rd); } else { diff --git a/contrib/win32/w32-posix-prototype/win32posix/win32posix/w32fd.h b/contrib/win32/w32-posix-prototype/win32posix/win32posix/w32fd.h index 6ee2f72..971a09b 100644 --- a/contrib/win32/w32-posix-prototype/win32posix/win32posix/w32fd.h +++ b/contrib/win32/w32-posix-prototype/win32posix/win32posix/w32fd.h @@ -2,6 +2,7 @@ #include #include "debug.h" +//order to be maintained enum w32_io_type { UNKOWN_FD = 0, LISTEN_FD,