|
version 1.2, 2005/03/05 00:30:41
|
version 1.3, 2005/03/05 01:32:48
|
|
|
|
| if( errCode != WSAVERNOTSUPPORTED ) { | if( errCode != WSAVERNOTSUPPORTED ) { |
| | |
| // print out the Error Code to be thorough | // print out the Error Code to be thorough |
| trace( "%d: WSAVERNOTSUPPORTED test failed with error code: %d\n", __LINE__, errCode ); |
trace( "WSAVERNOTSUPPORTED test failed with error code: %d\n", errCode ); |
| errCode = 0; | errCode = 0; |
| } | } |
| | |
|
|
|
| if( errCode != WSAEFAULT ) { | if( errCode != WSAEFAULT ) { |
| | |
| // print out the Error Code to be thorough | // print out the Error Code to be thorough |
| trace( "%d: WSAFAULT test failed with error code: %d\n", __LINE__, errCode ); |
trace( "WSAFAULT test failed with error code: %d\n", errCode ); |
| errCode = 0; | errCode = 0; |
| } | } |
| | |
|
|
|
| | |
| // print out the Error Code to be thorough | // print out the Error Code to be thorough |
| errCode = WSAGetLastError(); | errCode = WSAGetLastError(); |
| trace( "%d: WSAStartup() failed with error code: %d\n", __LINE__, errCode ); |
trace( "WSAStartup() failed with error code: %d\n", errCode ); |
| } | } |
| | |
| return errCode; | return errCode; |
|
|
|
| // WSAEAFNOSUPPORT test | // WSAEAFNOSUPPORT test |
| m_socket = socket( -999, SOCK_STREAM, IPPROTO_TCP ); | m_socket = socket( -999, SOCK_STREAM, IPPROTO_TCP ); |
| if( m_socket != INVALID_SOCKET || WSAGetLastError() != WSAEAFNOSUPPORT ){ | if( m_socket != INVALID_SOCKET || WSAGetLastError() != WSAEAFNOSUPPORT ){ |
| trace( "%d: WSAEAFNOSUPPORT test failed: %d %d\n", __LINE__, m_socket, WSAGetLastError() ); |
trace( "WSAEAFNOSUPPORT test failed: %d %d\n", m_socket, WSAGetLastError() ); |
| } | } |
| | |
| // WSAEPROTONOSUPPORT test | // WSAEPROTONOSUPPORT test |
| m_socket = socket( AF_INET, SOCK_STREAM, -999 ); | m_socket = socket( AF_INET, SOCK_STREAM, -999 ); |
| if( m_socket != INVALID_SOCKET || WSAGetLastError() != WSAEPROTONOSUPPORT ){ | if( m_socket != INVALID_SOCKET || WSAGetLastError() != WSAEPROTONOSUPPORT ){ |
| trace( "%d: WSAEPROTONOSUPPORT test failed: %d %d\n", __LINE__, m_socket, WSAGetLastError() ); |
trace( "WSAEPROTONOSUPPORT test failed: %d %d\n", m_socket, WSAGetLastError() ); |
| } | } |
| | |
| // WSAESOCKTNOSUPPORT test | // WSAESOCKTNOSUPPORT test |
| m_socket = socket( AF_INET, -999, IPPROTO_TCP ); | m_socket = socket( AF_INET, -999, IPPROTO_TCP ); |
| if( m_socket != INVALID_SOCKET || WSAGetLastError() != WSAESOCKTNOSUPPORT ){ | if( m_socket != INVALID_SOCKET || WSAGetLastError() != WSAESOCKTNOSUPPORT ){ |
| trace( "%d: WSAEPROTONOSUPPORT test failed: %d %d\n", __LINE__, m_socket, WSAGetLastError() ); |
trace( "WSAEPROTONOSUPPORT test failed: %d %d\n", m_socket, WSAGetLastError() ); |
| } | } |
| | |
| m_socket = socket( af, type, protocol ); | m_socket = socket( af, type, protocol ); |
| if( m_socket == INVALID_SOCKET ){ | if( m_socket == INVALID_SOCKET ){ |
| trace( "%d: Error at socket(): %d\n", __LINE__, WSAGetLastError() ); |
trace( "Error at socket(): %d\n", WSAGetLastError() ); |
| } | } |
| | |
| return m_socket; | return m_socket; |
|
|
|
| trace( "%ld accept called\n", GetCurrentThreadId() ); | trace( "%ld accept called\n", GetCurrentThreadId() ); |
| acceptSock = accept( socket, NULL, NULL ); | acceptSock = accept( socket, NULL, NULL ); |
| if( acceptSock == INVALID_SOCKET ){ | if( acceptSock == INVALID_SOCKET ){ |
| trace( "%d: accept error %d\n", __LINE__, WSAGetLastError() ); |
trace( "accept error %d\n", WSAGetLastError() ); |
| closesocket( socket ); | closesocket( socket ); |
| ExitThread( TH_ACCEPT_ERROR ); | ExitThread( TH_ACCEPT_ERROR ); |
| } | } |
|
|
|
| | |
| trace( "%ld received %d bytes: ", GetCurrentThreadId(), bytesRecv ); | trace( "%ld received %d bytes: ", GetCurrentThreadId(), bytesRecv ); |
| while( i < PACKET_SZ && buf[i] != (char)EOF ){ | while( i < PACKET_SZ && buf[i] != (char)EOF ){ |
| trace( "%c", buf[i] ); |
printf( "%c", buf[i] ); |
| i++; | i++; |
| } | } |
| trace( "\n" ); |
printf( "\n" ); |
| | |
| // Now send it back if you're the server | // Now send it back if you're the server |
| if( GetCurrentThreadId() == ServerThread.id ){ | if( GetCurrentThreadId() == ServerThread.id ){ |
|
|
|
| trace( "%ld sent back %d bytes: ", GetCurrentThreadId(), bytesRecv ); | trace( "%ld sent back %d bytes: ", GetCurrentThreadId(), bytesRecv ); |
| j = 0; | j = 0; |
| while( j < bytesRecv ){ | while( j < bytesRecv ){ |
| trace( "%c", buf[j] ); |
printf( "%c", buf[j] ); |
| j++; | j++; |
| } | } |
| trace( "\n" ); |
printf( "\n" ); |
| | |
| } | } |
| else{ | else{ |
|
|
|
| trace( "%ld closing socket\n", GetCurrentThreadId() ); | trace( "%ld closing socket\n", GetCurrentThreadId() ); |
| closesocket( socket ); | closesocket( socket ); |
| WSACleanup(); | WSACleanup(); |
| ResumeThread( ServerThread.handle ); |
|
| ExitThread( 0 ); | ExitThread( 0 ); |
| } | } |
| } | } |
|
|
|
| trace( "%ld sent: ", GetCurrentThreadId() ); | trace( "%ld sent: ", GetCurrentThreadId() ); |
| j = 0; | j = 0; |
| while( j < PACKET_SZ && buf[j] != (char)EOF ){ | while( j < PACKET_SZ && buf[j] != (char)EOF ){ |
| trace( "%c", buf[j] ); |
printf( "%c", buf[j] ); |
| j++; | j++; |
| } | } |
| trace( "\n" ); |
printf( "\n" ); |
| } | } |
| break; | break; |
| } | } |
|
|
|
| // Create a window | // Create a window |
| HWND hwnd = WineCreateWindow( hInstance ); | HWND hwnd = WineCreateWindow( hInstance ); |
| if( hwnd == NULL ){ | if( hwnd == NULL ){ |
| trace( "%d: Window could not be created %ld\n", __LINE__, GetLastError() ); |
trace( "Window could not be created %ld\n", GetLastError() ); |
| ExitThread( TH_WINDOW_ERROR ); | ExitThread( TH_WINDOW_ERROR ); |
| } | } |
| | |
|
|
|
| if( WSAStartup_w( MAKEWORD( 2, 2 ), &wsaData ) != 0 ){ | if( WSAStartup_w( MAKEWORD( 2, 2 ), &wsaData ) != 0 ){ |
| | |
| // print out the Error Code to be thorough | // print out the Error Code to be thorough |
| trace( "%d: WSAStartup() failed with error code: %d\n", __LINE__, WSAGetLastError() ); |
trace( "WSAStartup() failed with error code: %d\n", WSAGetLastError() ); |
| ExitThread( TH_START_ERROR ); | ExitThread( TH_START_ERROR ); |
| } | } |
| | |
| // Create a socket. | // Create a socket. |
| SOCKET sock = socket_w( AF_INET, SOCK_STREAM, IPPROTO_TCP );
if( sock == INVALID_SOCKET ){ | SOCKET sock = socket_w( AF_INET, SOCK_STREAM, IPPROTO_TCP );
if( sock == INVALID_SOCKET ){ |
| trace( "%d: socket error: %d\n", __LINE__, WSAGetLastError() ); |
trace( "socket error: %d\n", WSAGetLastError() ); |
| ExitThread( TH_SOCKET_ERROR ); | ExitThread( TH_SOCKET_ERROR ); |
| } | } |
| | |
|
|
|
| sockAddr.sin_addr.s_addr = inet_addr( "127.0.0.1" ); | sockAddr.sin_addr.s_addr = inet_addr( "127.0.0.1" ); |
| sockAddr.sin_port = htons( PORT_NUM ); | sockAddr.sin_port = htons( PORT_NUM ); |
| if( bind( sock, (SOCKADDR*) &sockAddr, sizeof( sockAddr ) ) == SOCKET_ERROR ){ | if( bind( sock, (SOCKADDR*) &sockAddr, sizeof( sockAddr ) ) == SOCKET_ERROR ){ |
| trace( "%d: bind failed weith error code %d\n", __LINE__, WSAGetLastError() ); |
trace( "bind failed weith error code %d\n", WSAGetLastError() ); |
| closesocket( sock ); | closesocket( sock ); |
| ExitThread( TH_BIND_ERROR ); | ExitThread( TH_BIND_ERROR ); |
| | |
|
|
|
| | |
| // Listen on the socket. | // Listen on the socket. |
| if ( listen( sock, 1 ) == SOCKET_ERROR ){ | if ( listen( sock, 1 ) == SOCKET_ERROR ){ |
| trace( "%d: listen error with error code %d.\n", __LINE__, WSAGetLastError() ); |
trace( "listen error with error code %d.\n", WSAGetLastError() ); |
| closesocket( sock );
ExitThread( TH_LISTEN_ERROR );
} | closesocket( sock );
ExitThread( TH_LISTEN_ERROR );
} |
| | |
| // make the socket asynchronous and notify of read, write, connect and close events | // make the socket asynchronous and notify of read, write, connect and close events |
| if( WSAAsyncSelect( sock, hwnd, ASYNC_EVENT, FD_WRITE | FD_ACCEPT |FD_READ | FD_CLOSE ) == SOCKET_ERROR ){ | if( WSAAsyncSelect( sock, hwnd, ASYNC_EVENT, FD_WRITE | FD_ACCEPT |FD_READ | FD_CLOSE ) == SOCKET_ERROR ){ |
| | |
| trace( "%d: WSAAsyncSelect Failed %d\n", __LINE__, WSAGetLastError() ); |
trace( "WSAAsyncSelect Failed %d\n", WSAGetLastError() ); |
| closesocket( sock ); | closesocket( sock ); |
| ExitThread( TH_SELECT_ERROR ); | ExitThread( TH_SELECT_ERROR ); |
| | |
|
|
|
| if( retVal == -1 ){ | if( retVal == -1 ){ |
| | |
| // handle the error and possibly exit | // handle the error and possibly exit |
| trace( "%d: GetMessage error %ld\n", __LINE__, GetLastError() ); |
trace( "GetMessage error %ld\n", GetLastError() ); |
| closesocket( sock ); | closesocket( sock ); |
| ExitThread( TH_MSG_ERROR ); | ExitThread( TH_MSG_ERROR ); |
| } | } |
| | |
| // suspend the other thread |
|
| SuspendThread( ClientThread.handle ); |
|
| |
|
| // Translate and dispatch the message | // Translate and dispatch the message |
| TranslateMessage( &msg ); | TranslateMessage( &msg ); |
| DispatchMessage( &msg ); | DispatchMessage( &msg ); |
| | |
| trace( "%ld still here?\n", GetCurrentThreadId() ); |
|
| |
|
| ResumeThread( ClientThread.handle ); |
|
| |
|
| } | } |
| | |
| return 0; | return 0; |
|
|
|
| // Create a window | // Create a window |
| HWND hwnd = WineCreateWindow( hInstance ); | HWND hwnd = WineCreateWindow( hInstance ); |
| if( hwnd == NULL ){ | if( hwnd == NULL ){ |
| trace( "%d: Window could not be created %ld\n", __LINE__, GetLastError() ); |
trace( "Window could not be created %ld\n", GetLastError() ); |
| ExitThread( TH_WINDOW_ERROR ); | ExitThread( TH_WINDOW_ERROR ); |
| } | } |
| | |
|
|
|
| if( WSAStartup_w( MAKEWORD( 2, 2 ), &wsaData ) != 0 ){ | if( WSAStartup_w( MAKEWORD( 2, 2 ), &wsaData ) != 0 ){ |
| | |
| // print out the Error Code to be thorough | // print out the Error Code to be thorough |
| trace( "%d: WSAStartup() failed with error code: %d\n", __LINE__, WSAGetLastError() ); |
trace( "WSAStartup() failed with error code: %d\n", WSAGetLastError() ); |
| ExitThread( TH_START_ERROR ); | ExitThread( TH_START_ERROR ); |
| } | } |
| | |
| // Create a socket. -- This is a TCP test | // Create a socket. -- This is a TCP test |
| SOCKET sock = socket_w( AF_INET, SOCK_STREAM, IPPROTO_TCP ); | SOCKET sock = socket_w( AF_INET, SOCK_STREAM, IPPROTO_TCP ); |
| if ( sock == INVALID_SOCKET ) { | if ( sock == INVALID_SOCKET ) { |
| trace( "%d: socket returned with error code: %d\n", __LINE__, WSAGetLastError() ); |
trace( "socket returned with error code: %d\n", WSAGetLastError() ); |
| ExitThread( TH_SOCKET_ERROR ); | ExitThread( TH_SOCKET_ERROR ); |
| } | } |
| | |
| // make the socket asynchronous and notify of read, write, connect and close events | // make the socket asynchronous and notify of read, write, connect and close events |
| // this is the client socket | // this is the client socket |
| if( WSAAsyncSelect( sock, hwnd, ASYNC_EVENT, FD_WRITE | FD_CONNECT | FD_READ | FD_CLOSE ) == SOCKET_ERROR ){ | if( WSAAsyncSelect( sock, hwnd, ASYNC_EVENT, FD_WRITE | FD_CONNECT | FD_READ | FD_CLOSE ) == SOCKET_ERROR ){ |
| trace( "%d: WSAAsyncSelect Failed %d\n", __LINE__, WSAGetLastError() ); |
trace( "WSAAsyncSelect Failed %d\n", WSAGetLastError() ); |
| closesocket( sock ); | closesocket( sock ); |
| ExitThread( TH_SELECT_ERROR ); | ExitThread( TH_SELECT_ERROR ); |
| } | } |
|
|
|
| sockAddr.sin_port = htons( PORT_NUM ); | sockAddr.sin_port = htons( PORT_NUM ); |
| if( connect( sock, (SOCKADDR*) &sockAddr, sizeof( sockAddr ) ) == SOCKET_ERROR ){ | if( connect( sock, (SOCKADDR*) &sockAddr, sizeof( sockAddr ) ) == SOCKET_ERROR ){ |
| if( WSAGetLastError() != WSAEWOULDBLOCK ){ | if( WSAGetLastError() != WSAEWOULDBLOCK ){ |
| trace( "%d: Failed to connect.: %d\n", __LINE__, WSAGetLastError() ); |
trace( "Failed to connect.: %d\n", WSAGetLastError() ); |
| closesocket( sock ); | closesocket( sock ); |
| ExitThread( TH_CONNECT_ERROR ); | ExitThread( TH_CONNECT_ERROR ); |
| } | } |
|
|
|
| if( retVal == -1 ){ | if( retVal == -1 ){ |
| | |
| // handle the error and possibly exit | // handle the error and possibly exit |
| trace( "%d: GetMessage error %ld\n", __LINE__, GetLastError() ); |
trace( "GetMessage error %ld\n", GetLastError() ); |
| closesocket( sock ); | closesocket( sock ); |
| ExitThread( TH_MSG_ERROR ); | ExitThread( TH_MSG_ERROR ); |
| } | } |
| | |
| SuspendThread( ServerThread.handle ); |
|
| |
|
| // Translate and dispatch the message | // Translate and dispatch the message |
| TranslateMessage( &msg ); | TranslateMessage( &msg ); |
| DispatchMessage( &msg ); | DispatchMessage( &msg ); |
| | |
| //trace( "%ld still here?\n", GetCurrentThreadId() ); |
|
| ResumeThread( ServerThread.handle ); |
|
| } | } |
| return 0; | return 0; |
| } | } |
|
|
|
| | |
| if( ServerThread.handle == NULL ){ | if( ServerThread.handle == NULL ){ |
| | |
| trace( "%d: CreateThread failed %ld\n", __LINE__, GetLastError() ); |
trace( "CreateThread failed %ld\n", GetLastError() ); |
| WineThreadCleanUp(); | WineThreadCleanUp(); |
| return; | return; |
| } | } |
|
|
|
| if( waitRet == WAIT_FAILED ){ | if( waitRet == WAIT_FAILED ){ |
| | |
| // WaitForSingleObject failed for whatever reason | // WaitForSingleObject failed for whatever reason |
| trace( "%d: WaitForSingleObject failed with error code %ld\n", __LINE__, GetLastError() ); |
trace( "WaitForSingleObject failed with error code %ld\n", GetLastError() ); |
| WineThreadCleanUp(); | WineThreadCleanUp(); |
| return; | return; |
| | |
|
|
|
| DWORD threadStatus = 0; | DWORD threadStatus = 0; |
| if( GetExitCodeThread( ServerThread.handle, &threadStatus ) == 0 ){ | if( GetExitCodeThread( ServerThread.handle, &threadStatus ) == 0 ){ |
| | |
| trace( "%d: GetExitCodeThread failed with error code %ld\n", __LINE__, GetLastError() ); |
trace( "GetExitCodeThread failed with error code %ld\n",GetLastError() ); |
| WineThreadCleanUp(); | WineThreadCleanUp(); |
| return; | return; |
| | |
|
|
|
| | |
| if( ClientThread.handle == NULL ){ | if( ClientThread.handle == NULL ){ |
| | |
| trace( "%d: CreateThread failed %ld\n", __LINE__, GetLastError() ); |
trace( "CreateThread failed %ld\n", GetLastError() ); |
| WineThreadCleanUp(); | WineThreadCleanUp(); |
| return; | return; |
| } | } |
|
|
|
| if( waitRet == WAIT_FAILED ){ | if( waitRet == WAIT_FAILED ){ |
| | |
| // WaitForSingleObject failed for whatever reason | // WaitForSingleObject failed for whatever reason |
| trace( "%d: WaitForMultipleObjects failed with error code %ld\n", __LINE__, GetLastError() ); |
trace( "WaitForMultipleObjects failed with error code %ld\n", GetLastError() ); |
| WineThreadCleanUp(); | WineThreadCleanUp(); |
| return; | return; |
| | |
| } | } |
| else if( waitRet == WAIT_TIMEOUT ){ | else if( waitRet == WAIT_TIMEOUT ){ |
| | |
| trace( "%d: Timed out while waiting for threads to finish\n", __LINE__ ); |
trace( "Timed out while waiting for threads to finish\n" ); |
| WineThreadCleanUp(); | WineThreadCleanUp(); |
| return; | return; |
| | |
|
|
|
| WineThreadCleanUp(); | WineThreadCleanUp(); |
| | |
| trace( "%ld: main thread exiting...\n", GetCurrentThreadId() ); | trace( "%ld: main thread exiting...\n", GetCurrentThreadId() ); |
| while(1); |
|
| } | } |