From 720818154f3a94e958dc3f1d0ccbb84ca6efd482 Mon Sep 17 00:00:00 2001 From: manojampalam Date: Sun, 28 Feb 2016 12:59:20 -0800 Subject: [PATCH] 2-28 C2 --- .../win32posix/SampleServer/SampleServer.cpp | 6 +++--- .../win32posix/Tests/socketiotests.cpp | 12 ++++++++---- .../win32posix/win32posix/socketio.c | 6 +++--- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/contrib/win32/w32-posix-prototype/win32posix/SampleServer/SampleServer.cpp b/contrib/win32/w32-posix-prototype/win32posix/SampleServer/SampleServer.cpp index 084e61b..40293e1 100644 --- a/contrib/win32/w32-posix-prototype/win32posix/SampleServer/SampleServer.cpp +++ b/contrib/win32/w32-posix-prototype/win32posix/SampleServer/SampleServer.cpp @@ -32,13 +32,13 @@ int regular() w32posix_initialize(); ZeroMemory(&hints, sizeof(hints)); - hints.ai_family = AF_INET; + //hints.ai_family = AF_INET; hints.ai_socktype = SOCK_STREAM; - hints.ai_protocol = IPPROTO_TCP; + //hints.ai_protocol = IPPROTO_TCP; hints.ai_flags = AI_PASSIVE; // Resolve the server address and port - iResult = getaddrinfo(NULL, DEFAULT_PORT, &hints, &result); + iResult = getaddrinfo("127.0.0.1", DEFAULT_PORT, &hints, &result); if (iResult != 0) { printf("getaddrinfo failed with error: %d\n", iResult); w32posix_done(); diff --git a/contrib/win32/w32-posix-prototype/win32posix/Tests/socketiotests.cpp b/contrib/win32/w32-posix-prototype/win32posix/Tests/socketiotests.cpp index 19fbd33..dedb26d 100644 --- a/contrib/win32/w32-posix-prototype/win32posix/Tests/socketiotests.cpp +++ b/contrib/win32/w32-posix-prototype/win32posix/Tests/socketiotests.cpp @@ -99,7 +99,7 @@ namespace UnitTests hints.ai_socktype = SOCK_STREAM; hints.ai_flags = AI_PASSIVE; // use my IP - if ((rv = getaddrinfo("127.0.0.1", PORT, &hints, &servinfo)) != 0) { + if ((rv = getaddrinfo("::1", PORT, &hints, &servinfo)) != 0) { fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv)); return; } @@ -186,7 +186,8 @@ namespace UnitTests //FD_SET(listen_fd, &read_set); //FD_SET(connect_fd, &write_set); - HANDLE thread = CreateThread(NULL, 0, MyThreadFunction, &connect_fd, 0, NULL); + //HANDLE thread = CreateThread(NULL, 0, MyThreadFunction, &connect_fd, 0, NULL); + //sin_size = sizeof(their_addr); //accept_fd = accept(listen_fd, (struct sockaddr *)&their_addr, &sin_size); @@ -196,8 +197,11 @@ namespace UnitTests ret = connect(connect_fd, servinfo->ai_addr, servinfo->ai_addrlen); Assert::AreEqual(ret, 0, L"", LINE_INFO()); - WaitForSingleObject(thread, INFINITE); - CloseHandle(thread); + MyThreadFunction(NULL); + + + //WaitForSingleObject(thread, INFINITE); + //CloseHandle(thread); int i = 9; /* accept_fd = accept(listen_fd, (struct sockaddr *)&their_addr, &sin_size); diff --git a/contrib/win32/w32-posix-prototype/win32posix/win32posix/socketio.c b/contrib/win32/w32-posix-prototype/win32posix/win32posix/socketio.c index a46e564..faafa06 100644 --- a/contrib/win32/w32-posix-prototype/win32posix/win32posix/socketio.c +++ b/contrib/win32/w32-posix-prototype/win32posix/win32posix/socketio.c @@ -93,7 +93,7 @@ int socketio_acceptEx(struct w32_io* pio) { //create accepting socket //todo - get socket parameters from listening socket - context->accept_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); + context->accept_socket = socket(AF_UNSPEC, SOCK_STREAM, IPPROTO_TCP); if (context->accept_socket == INVALID_SOCKET) { errno = errno_from_WSALastError(); debug("ERROR:%d, io:%p", errno, pio); @@ -104,8 +104,8 @@ int socketio_acceptEx(struct w32_io* pio) { context->accept_socket, context->lpOutputBuf, 0, - sizeof(struct sockaddr_in) + 16, - sizeof(struct sockaddr_in) + 16, + sizeof(struct sockaddr_in6) + 16, + sizeof(struct sockaddr_in6) + 16, &context->bytes_received, &pio->read_overlapped)) {