diff --git a/contrib/win32/w32-posix-prototype/win32posix/SampleServer/SampleServer.cpp b/contrib/win32/w32-posix-prototype/win32posix/SampleServer/SampleServer.cpp deleted file mode 100644 index 40293e1..0000000 --- a/contrib/win32/w32-posix-prototype/win32posix/SampleServer/SampleServer.cpp +++ /dev/null @@ -1,546 +0,0 @@ - -#undef UNICODE - -#define WIN32_LEAN_AND_MEAN - -#include -#include -extern "C" { -#include "..\win32posix\w32posix.h" -} -// Need to link with Ws2_32.lib -#pragma comment (lib, "Ws2_32.lib") -// #pragma comment (lib, "Mswsock.lib") - -#define DEFAULT_BUFLEN 512 -#define DEFAULT_PORT "27015" - -int regular() -{ - int iResult; - - int ListenSocket; - int ClientSocket; - - struct addrinfo *result = NULL; - struct addrinfo hints; - - int iSendResult; - char recvbuf[DEFAULT_BUFLEN]; - int recvbuflen = DEFAULT_BUFLEN; - - w32posix_initialize(); - - ZeroMemory(&hints, sizeof(hints)); - //hints.ai_family = AF_INET; - hints.ai_socktype = SOCK_STREAM; - //hints.ai_protocol = IPPROTO_TCP; - hints.ai_flags = AI_PASSIVE; - - // Resolve the server address and port - iResult = getaddrinfo("127.0.0.1", DEFAULT_PORT, &hints, &result); - if (iResult != 0) { - printf("getaddrinfo failed with error: %d\n", iResult); - w32posix_done(); - return 1; - } - - // Create a SOCKET for connecting to server - ListenSocket = socket(result->ai_family, result->ai_socktype, result->ai_protocol); - if (ListenSocket == -1) { - printf("socket failed with error: %ld\n", errno); - freeaddrinfo(result); - w32posix_done(); - return 1; - } - - // Setup the TCP listening socket - iResult = bind(ListenSocket, result->ai_addr, (int)result->ai_addrlen); - if (iResult == -1) { - printf("bind failed with error: %d\n", errno); - freeaddrinfo(result); - close(ListenSocket); - w32posix_done(); - return 1; - } - - freeaddrinfo(result); - - iResult = listen(ListenSocket, SOMAXCONN); - if (iResult == -1) { - printf("listen failed with error: %d\n", errno); - close(ListenSocket); - w32posix_done(); - return 1; - } - - // Accept a client socket - ClientSocket = accept(ListenSocket, NULL, NULL); - if (ClientSocket == -1) { - printf("accept failed with error: %d\n", errno); - close(ListenSocket); - w32posix_done(); - return 1; - } - - // No longer need server socket - close(ListenSocket); - - // Receive until the peer shuts down the connection - do { - - iResult = recv(ClientSocket, recvbuf, recvbuflen, 0); - if (iResult > 0) { - printf("Bytes received: %d\n", iResult); - recvbuf[iResult] = '\0'; - printf("%s\n", recvbuf); - - // Echo the buffer back to the sender - iSendResult = send(ClientSocket, recvbuf, iResult, 0); - if (iSendResult == -1) { - printf("send failed with error: %d\n", errno); - close(ClientSocket); - w32posix_done(); - return 1; - } - printf("Bytes sent: %d\n", iSendResult); - } - else if (iResult == 0) - printf("Connection closing...\n"); - else { - printf("recv failed with error: %d\n", errno); - close(ClientSocket); - w32posix_done(); - return 1; - } - - } while (iResult > 0); - - // shutdown the connection since we're done - iResult = shutdown(ClientSocket, SD_SEND); - if (iResult == -1) { - printf("shutdown failed with error: %d\n", errno); - iSendResult = send(ClientSocket, recvbuf, iResult, 0); - if (iSendResult == -1) - printf("send failed with error: %d\n", errno); - close(ClientSocket); - w32posix_done(); - return 1; - } - - // cleanup - close(ClientSocket); - w32posix_done(); - - return 0; -} - -int async() -{ - int iResult; - - int ListenSocket; - int ClientSocket; - - struct addrinfo *result = NULL; - struct addrinfo hints; - - int iSendResult; - char recvbuf[DEFAULT_BUFLEN]; - int recvbuflen = DEFAULT_BUFLEN; - - w32posix_initialize(); - - ZeroMemory(&hints, sizeof(hints)); - hints.ai_family = AF_INET; - hints.ai_socktype = SOCK_STREAM; - hints.ai_protocol = IPPROTO_TCP; - hints.ai_flags = AI_PASSIVE; - - // Resolve the server address and port - iResult = getaddrinfo(NULL, DEFAULT_PORT, &hints, &result); - if (iResult != 0) { - printf("getaddrinfo failed with error: %d\n", iResult); - w32posix_done(); - return 1; - } - - // Create a SOCKET for connecting to server - ListenSocket = socket(result->ai_family, result->ai_socktype, result->ai_protocol); - if (ListenSocket == -1) { - printf("socket failed with error: %ld\n", errno); - freeaddrinfo(result); - w32posix_done(); - return 1; - } - - // Setup the TCP listening socket - iResult = bind(ListenSocket, result->ai_addr, (int)result->ai_addrlen); - if (iResult == -1) { - printf("bind failed with error: %d\n", errno); - freeaddrinfo(result); - close(ListenSocket); - w32posix_done(); - return 1; - } - - freeaddrinfo(result); - - iResult = listen(ListenSocket, SOMAXCONN); - if (iResult == -1) { - printf("listen failed with error: %d\n", errno); - close(ListenSocket); - w32posix_done(); - return 1; - } - - fd_set readset; - memset(&readset, 0, sizeof(fd_set)); - FD_SET(ListenSocket, &readset); - - timeval time; - time.tv_sec = 60 * 60; - if (-1 == select(ListenSocket, &readset, NULL, NULL, &time)) - { - printf("select call failed"); - close(ListenSocket); - w32posix_done(); - return 1; - } - - if (!FD_ISSET(ListenSocket, &readset)) - printf("expected that fd is set"); - - // Accept a client socket - ClientSocket = accept(ListenSocket, NULL, NULL); - if (ClientSocket == -1) { - printf("accept failed with error: %d\n", errno); - close(ListenSocket); - w32posix_done(); - return 1; - } - - // No longer need server socket - close(ListenSocket); - - int fd_flags = fcntl(ClientSocket, F_GETFL); - fcntl(ClientSocket, F_SETFL, fd_flags | O_NONBLOCK); - - - // Receive until the peer shuts down the connection - do { - - memset(&readset, 0, sizeof(fd_set)); - FD_SET(ClientSocket, &readset); - if (-1 == select(ClientSocket, &readset, NULL, NULL, &time)) - { - printf("select call failed"); - close(ListenSocket); - w32posix_done(); - return 1; - } - - iResult = recv(ClientSocket, recvbuf, recvbuflen, 0); - if (iResult > 0) { - printf("Bytes received: %d\n", iResult); - recvbuf[iResult] = '\0'; - printf("%s\n", recvbuf); - - // Echo the buffer back to the sender - iSendResult = send(ClientSocket, recvbuf, iResult, 0); - if (iSendResult == -1) { - printf("send failed with error: %d\n", errno); - close(ClientSocket); - w32posix_done(); - return 1; - } - printf("Bytes sent: %d\n", iSendResult); - } - else if (iResult == 0) - printf("Connection closing...\n"); - else { - printf("recv failed with error: %d\n", errno); - close(ClientSocket); - w32posix_done(); - return 1; - } - - } while (iResult > 0); - - // shutdown the connection since we're done - iResult = shutdown(ClientSocket, SD_SEND); - if (iResult == -1) { - printf("shutdown failed with error: %d\n", errno); - close(ClientSocket); - w32posix_done(); - return 1; - } - - // cleanup - close(ClientSocket); - w32posix_done(); - - return 0; -} - - -#undef DEFAULT_BUFLEN -#define DEFAULT_BUFLEN 1024*1024 -BOOL writemode; -int throughput() -{ - int iResult; - - int ListenSocket; - int ClientSocket; - - struct addrinfo *result = NULL; - struct addrinfo hints; - - char *recvbuf = (char*)malloc(DEFAULT_BUFLEN); - int recvbuflen = DEFAULT_BUFLEN; - - w32posix_initialize(); - - ZeroMemory(&hints, sizeof(hints)); - hints.ai_family = AF_INET; - hints.ai_socktype = SOCK_STREAM; - hints.ai_protocol = IPPROTO_TCP; - hints.ai_flags = AI_PASSIVE; - - // Resolve the server address and port - iResult = getaddrinfo(NULL, DEFAULT_PORT, &hints, &result); - if (iResult != 0) { - printf("getaddrinfo failed with error: %d\n", iResult); - w32posix_done(); - return 1; - } - - // Create a SOCKET for connecting to server - ListenSocket = socket(result->ai_family, result->ai_socktype, result->ai_protocol); - if (ListenSocket == -1) { - printf("socket failed with error: %ld\n", errno); - freeaddrinfo(result); - w32posix_done(); - return 1; - } - - // Setup the TCP listening socket - iResult = bind(ListenSocket, result->ai_addr, (int)result->ai_addrlen); - if (iResult == -1) { - printf("bind failed with error: %d\n", errno); - freeaddrinfo(result); - close(ListenSocket); - w32posix_done(); - return 1; - } - - freeaddrinfo(result); - - iResult = listen(ListenSocket, SOMAXCONN); - if (iResult == -1) { - printf("listen failed with error: %d\n", errno); - close(ListenSocket); - w32posix_done(); - return 1; - } - - // Accept a client socket - ClientSocket = accept(ListenSocket, NULL, NULL); - if (ClientSocket == -1) { - printf("accept failed with error: %d\n", errno); - close(ListenSocket); - w32posix_done(); - return 1; - } - - // No longer need server socket - close(ListenSocket); - - double totalbytes = 0; - - // Receive until the peer shuts down the connection - if (writemode) - { - char *sendbuf = (char*)malloc(DEFAULT_BUFLEN); - int sendbuflen = DEFAULT_BUFLEN; - - while (totalbytes < 50000 * 1024 * 1024) - { - iResult = send(ClientSocket, sendbuf, sendbuflen, 0); - if (iResult == SOCKET_ERROR) { - printf("send failed with error: %d\n", WSAGetLastError()); - close(ClientSocket); - w32posix_done(); - return 1; - } - totalbytes += iResult; - } - - printf("send %f bytes\n", totalbytes); - // shutdown the connection since no more data will be sent - iResult = shutdown(ClientSocket, SD_SEND); - if (iResult == SOCKET_ERROR) { - printf("shutdown failed with error: %d\n", WSAGetLastError()); - close(ClientSocket); - w32posix_done(); - return 1; - } - } - else - { - do { - - iResult = recv(ClientSocket, recvbuf, recvbuflen, 0); - if (iResult > 0) { - totalbytes += iResult; - } - else if (iResult == 0) - printf("Connection closing...\n"); - else { - printf("recv failed with error: %d\n", errno); - close(ClientSocket); - w32posix_done(); - return 1; - } - - } while (iResult > 0); - - printf("Received total bytes %f\n", totalbytes); - } - - // cleanup - close(ClientSocket); - w32posix_done(); - - return 0; -} - -DWORD WINAPI ThreadProcedure(void* param) -{ - Sleep(20*1000); - int writefd = *((int*)param); - close(writefd); - return 0; -} - -int pipetest() -{ - int pipefds[2]; - - w32posix_initialize(); - if (-1 == pipe(pipefds)) - { - printf("creating pipe failed %d\n", errno); - return -1; - } - - int readfd = pipefds[0]; - int writefd = pipefds[1]; - char* buf = "test characters to write"; - char readbuf[512]; - - CreateThread(0, 0, &ThreadProcedure, &readfd, 0, NULL); - int count = 0; - while (1) { - int written = write(writefd, buf, strlen(buf)); - printf("Iteration %d Written %d\n", count++, written); - if (written == -1) { - printf("write to pipe failed %d \n", errno); - close(readfd); - close(writefd); - return -1; - } - } - - /* - int rd = read(readfd, readbuf, 512); - if (rd == -1) { - printf("reading from pipe failed %d \n", errno); - close(readfd); - close(writefd); - return -1; - } - */ - - close(writefd); - - close(readfd); - return 0; -} - -int pipelinetest() -{ - int pipe1[2]; - if (-1 == pipe(pipe1)) - { - printf("creating pipe failed %d\n", errno); - return -1; - } - - int pipe1_out = pipe1[0]; - int pipe1_in = pipe1[1]; - - int fd_flags = fcntl(pipe1_in, F_GETFL); - fcntl(pipe1_in, F_SETFL, fd_flags | O_NONBLOCK); - - fd_flags = fcntl(pipe1_out, F_GETFL); - fcntl(pipe1_out, F_SETFL, fd_flags | O_NONBLOCK); - - - int max_fd = max(pipe1_in, pipe1_out) + 1; - - fd_set read_set, write_set; - - FD_ZERO(&read_set); - FD_ZERO(&write_set); - - FD_SET(pipe1_out, &read_set); - FD_SET(pipe1_in, &write_set); - timeval time; - time.tv_sec = 60000; - time.tv_usec = 0; - char* input = "hi how are you?"; - char read_buf[256]; - - while (-1 != select(max_fd, &read_set, &write_set, NULL, &time)) - { - fd_set read_ret_set = read_set; - fd_set write_ret_set = write_set; - - FD_ZERO(&read_set); - FD_ZERO(&write_set); - - if (FD_ISSET(pipe1_in, &write_ret_set)) - { - int to_write = strlen(input); - int written = write(pipe1_in, input, to_write); - if (written != to_write) - FD_SET(pipe1_in, &write_set); - else - FD_SET(pipe1_out, &read_set); - - } - - if (FD_ISSET(pipe1_out, &read_ret_set)) - { - int bytes_read = read(pipe1_out, read_buf, 256); - if (bytes_read > 0) - { - read_buf[bytes_read] = '\0'; - printf("Received %s \n", read_buf); - } - } - - } -} - - -int __cdecl main(void) -{ - return regular(); - //return async(); - writemode = TRUE; - //return throughput(); - //return pipetest(); -} diff --git a/contrib/win32/w32-posix-prototype/win32posix/SampleServer/SampleServer.vcxproj b/contrib/win32/w32-posix-prototype/win32posix/SampleServer/SampleServer.vcxproj deleted file mode 100644 index 221e12f..0000000 --- a/contrib/win32/w32-posix-prototype/win32posix/SampleServer/SampleServer.vcxproj +++ /dev/null @@ -1,160 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - {D52F8255-C3A9-4416-A0A6-8CE63A4D7E43} - Win32Proj - SampleServer - SampleServer - 8.1 - - - - Application - true - v140 - Unicode - - - Application - true - v140 - Unicode - - - Application - false - v140 - true - Unicode - - - Application - false - v140 - true - Unicode - - - - - - - - - - - - - - - - - - - true - $(ProjectDir)bin\$(Configuration)\ - - - true - $(ProjectDir)bin\$(Platform)\$(Configuration)\ - $(ProjectDir)bin\int\$(Platform)\$(Configuration)\ - - - false - - - false - - - - - - Level3 - Disabled - WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) - - - Console - true - win32posix.lib;%(AdditionalDependencies) - $(SolutionDir)bin\lib\$(Platform)\$(Configuration)\ - - - - - - - Level3 - Disabled - WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) - - - Console - true - win32posix.lib;%(AdditionalDependencies) - $(SolutionDir)bin\lib\$(Platform)\$(Configuration)\ - - - - - Level3 - - - MaxSpeed - true - true - WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) - - - Console - true - true - true - - - - - Level3 - - - MaxSpeed - true - true - WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) - - - Console - true - true - true - - - - - - - - - - - - - \ No newline at end of file diff --git a/contrib/win32/w32-posix-prototype/win32posix/SampleServer/SampleServer.vcxproj.filters b/contrib/win32/w32-posix-prototype/win32posix/SampleServer/SampleServer.vcxproj.filters deleted file mode 100644 index 0b0f6b2..0000000 --- a/contrib/win32/w32-posix-prototype/win32posix/SampleServer/SampleServer.vcxproj.filters +++ /dev/null @@ -1,30 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;hm;inl;inc;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - Header Files - - - Header Files - - - - - Source Files - - - \ No newline at end of file diff --git a/contrib/win32/w32-posix-prototype/win32posix/win32posix.sln b/contrib/win32/w32-posix-prototype/win32posix/win32posix.sln index 446ed86..b5273e8 100644 --- a/contrib/win32/w32-posix-prototype/win32posix/win32posix.sln +++ b/contrib/win32/w32-posix-prototype/win32posix/win32posix.sln @@ -1,15 +1,10 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 -VisualStudioVersion = 14.0.23107.0 +VisualStudioVersion = 14.0.24720.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "win32posix", "win32posix\win32posix.vcxproj", "{D8744F47-1741-4FB8-97D3-EBB9C3A13E67}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SampleServer", "SampleServer\SampleServer.vcxproj", "{D52F8255-C3A9-4416-A0A6-8CE63A4D7E43}" - ProjectSection(ProjectDependencies) = postProject - {D8744F47-1741-4FB8-97D3-EBB9C3A13E67} = {D8744F47-1741-4FB8-97D3-EBB9C3A13E67} - EndProjectSection -EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UnitTests", "UnitTests\UnitTests.vcxproj", "{31E868FF-DE6C-4CF7-9BF0-2C9B51DB58AD}" ProjectSection(ProjectDependencies) = postProject {D8744F47-1741-4FB8-97D3-EBB9C3A13E67} = {D8744F47-1741-4FB8-97D3-EBB9C3A13E67} @@ -31,14 +26,6 @@ Global {D8744F47-1741-4FB8-97D3-EBB9C3A13E67}.Release|Win32.Build.0 = Release|Win32 {D8744F47-1741-4FB8-97D3-EBB9C3A13E67}.Release|x64.ActiveCfg = Release|x64 {D8744F47-1741-4FB8-97D3-EBB9C3A13E67}.Release|x64.Build.0 = Release|x64 - {D52F8255-C3A9-4416-A0A6-8CE63A4D7E43}.Debug|Win32.ActiveCfg = Debug|Win32 - {D52F8255-C3A9-4416-A0A6-8CE63A4D7E43}.Debug|Win32.Build.0 = Debug|Win32 - {D52F8255-C3A9-4416-A0A6-8CE63A4D7E43}.Debug|x64.ActiveCfg = Debug|x64 - {D52F8255-C3A9-4416-A0A6-8CE63A4D7E43}.Debug|x64.Build.0 = Debug|x64 - {D52F8255-C3A9-4416-A0A6-8CE63A4D7E43}.Release|Win32.ActiveCfg = Release|Win32 - {D52F8255-C3A9-4416-A0A6-8CE63A4D7E43}.Release|Win32.Build.0 = Release|Win32 - {D52F8255-C3A9-4416-A0A6-8CE63A4D7E43}.Release|x64.ActiveCfg = Release|x64 - {D52F8255-C3A9-4416-A0A6-8CE63A4D7E43}.Release|x64.Build.0 = Release|x64 {31E868FF-DE6C-4CF7-9BF0-2C9B51DB58AD}.Debug|Win32.ActiveCfg = Debug|Win32 {31E868FF-DE6C-4CF7-9BF0-2C9B51DB58AD}.Debug|Win32.Build.0 = Debug|Win32 {31E868FF-DE6C-4CF7-9BF0-2C9B51DB58AD}.Debug|x64.ActiveCfg = Debug|x64