version 1.1, 2005/03/04 01:00:48
|
version 1.3, 2005/03/05 01:32:48
|
|
|
#include "winsock2.h" | #include "winsock2.h" |
#include "windows.h" | #include "windows.h" |
| |
|
#include <wine/test.h> |
|
#include <winbase.h> |
|
|
/* The #pragma directives offer a way for each compiler to offer machine- | /* The #pragma directives offer a way for each compiler to offer machine- |
and operating-system-specific features while retaining overall | and operating-system-specific features while retaining overall |
compatibility with the C and C++ languages. | compatibility with the C and C++ languages. |
The next line places a library-search record, ws2_32, in the object file. */ | The next line places a library-search record, ws2_32, in the object file. */ |
#pragma comment ( lib, "ws2_32" ) |
// #pragma comment ( lib, "ws2_32" ) |
| |
/* constants */ | /* constants */ |
#define ASYNC_EVENT (WM_USER +5) // the message we'll use for our async notification | #define ASYNC_EVENT (WM_USER +5) // the message we'll use for our async notification |
|
|
if( errCode != WSAVERNOTSUPPORTED ) { | if( errCode != WSAVERNOTSUPPORTED ) { |
| |
// print out the Error Code to be thorough | // print out the Error Code to be thorough |
printf( "%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 |
printf( "%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(); |
printf( "%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 ){ |
printf( "%d: WSAEAFNOSUPPORT test failed: %d %ld\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 ){ |
printf( "%d: WSAEPROTONOSUPPORT test failed: %d %ld\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 ){ |
printf( "%d: WSAEPROTONOSUPPORT test failed: %d %ld\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 ){ |
printf( "%d: Error at socket(): %ld\n", __LINE__, WSAGetLastError() ); |
trace( "Error at socket(): %d\n", WSAGetLastError() ); |
} | } |
| |
return m_socket; | return m_socket; |
|
|
*/ | */ |
static LRESULT CALLBACK WndProcedure( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ) | static LRESULT CALLBACK WndProcedure( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ) |
{ | { |
|
int eventCode = 0; |
switch( msg ) | switch( msg ) |
{ | { |
case ASYNC_EVENT: | case ASYNC_EVENT: |
int eventCode = WSAGETSELECTEVENT( lParam ); |
eventCode = WSAGETSELECTEVENT( lParam ); |
SOCKET socket = (SOCKET) wParam; | SOCKET socket = (SOCKET) wParam; |
SOCKET acceptSock; | SOCKET acceptSock; |
int bytesRecv = 0; | int bytesRecv = 0; |
int i = 0, j = 0; | int i = 0, j = 0; |
int ret; |
|
char* buf; | char* buf; |
if( GetCurrentThreadId() == ServerThread.id ) | if( GetCurrentThreadId() == ServerThread.id ) |
buf = ServerThread.packet; | buf = ServerThread.packet; |
|
|
switch( eventCode ) | switch( eventCode ) |
{ | { |
case FD_ACCEPT: | case FD_ACCEPT: |
printf( "%d 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 ){ |
printf( "%d: accept error %ld\n", __LINE__, WSAGetLastError() ); |
trace( "accept error %d\n", WSAGetLastError() ); |
closesocket( socket ); | closesocket( socket ); |
ExitThread( TH_ACCEPT_ERROR ); | ExitThread( TH_ACCEPT_ERROR ); |
} | } |
printf( "%d: connection accepted\n", GetCurrentThreadId() ); |
trace( "%ld: connection accepted\n", GetCurrentThreadId() ); |
break; | break; |
| |
case FD_CONNECT: | case FD_CONNECT: |
| |
// a call to connect() has completed | // a call to connect() has completed |
printf("%d CONNECTED!\n", GetCurrentThreadId() ); |
trace("%ld CONNECTED!\n", GetCurrentThreadId() ); |
break; | break; |
| |
case FD_CLOSE: | case FD_CLOSE: |
| |
// a connection has been closed | // a connection has been closed |
closesocket( socket ); | closesocket( socket ); |
printf( "%d: Closed socket\n", GetCurrentThreadId()); |
trace( "%ld: Closed socket\n", GetCurrentThreadId()); |
WSACleanup(); | WSACleanup(); |
ExitThread( 0 ); | ExitThread( 0 ); |
break; | break; |
|
|
// WinSock has data waiting to be read | // WinSock has data waiting to be read |
bytesRecv = recv( socket, buf, PACKET_SZ, 0 ); | bytesRecv = recv( socket, buf, PACKET_SZ, 0 ); |
| |
printf( "%d 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 ){ |
printf( "%c", buf[i] ); | printf( "%c", buf[i] ); |
i++; | i++; |
|
|
// check if the network buffer is full and can send no more | // check if the network buffer is full and can send no more |
// data. If so then break from the loop | // data. If so then break from the loop |
if( WSAGetLastError() == WSAEWOULDBLOCK ){ | if( WSAGetLastError() == WSAEWOULDBLOCK ){ |
// break from the loop – buffer is full |
// break from the loop – buffer is full |
printf( "woud block send!\n" ); |
trace( "woud block send!\n" ); |
break; | break; |
} | } |
else{ // another error | else{ // another error |
printf(" some send error\n" ); |
trace(" some send error\n" ); |
return 0; | return 0; |
} | } |
} | } |
| |
printf( "%d sent back %d bytes: ", GetCurrentThreadId(), bytesRecv ); |
trace( "%ld sent back %d bytes: ", GetCurrentThreadId(), bytesRecv ); |
j = 0; | j = 0; |
while( j < bytesRecv ){ | while( j < bytesRecv ){ |
printf( "%c", buf[j] ); | printf( "%c", buf[j] ); |
|
|
// Client: close the connection when it received back FILE_SZ | // Client: close the connection when it received back FILE_SZ |
ClientThread.bytesRecvd += bytesRecv; | ClientThread.bytesRecvd += bytesRecv; |
if( ClientThread.bytesRecvd >= FILE_SZ ){ | if( ClientThread.bytesRecvd >= FILE_SZ ){ |
printf( "%d closing socket\n", GetCurrentThreadId() ); |
trace( "%ld closing socket\n", GetCurrentThreadId() ); |
closesocket( socket ); | closesocket( socket ); |
WSACleanup(); | WSACleanup(); |
ResumeThread( ServerThread.handle ); |
|
ExitThread( 0 ); | ExitThread( 0 ); |
} | } |
} | } |
|
|
// check if the network buffer is full and can send no more | // check if the network buffer is full and can send no more |
// data. If so then break from the loop | // data. If so then break from the loop |
if( WSAGetLastError() == WSAEWOULDBLOCK ){ | if( WSAGetLastError() == WSAEWOULDBLOCK ){ |
// break from the loop – buffer is full |
// break from the loop – buffer is full |
break; | break; |
} | } |
else{ // another error | else{ // another error |
|
|
} | } |
} | } |
| |
printf( "%d 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 ){ |
printf( "%c", buf[j] ); | printf( "%c", buf[j] ); |
|
|
static HWND WineCreateWindow( HINSTANCE hInstance ) | static HWND WineCreateWindow( HINSTANCE hInstance ) |
{ | { |
// initialize the window class attributes. | // initialize the window class attributes. |
WNDCLASS *windowClass; |
WNDCLASS windowClass; |
windowClass = new WNDCLASS; |
//windowClass = new WNDCLASS; |
windowClass->lpszClassName = "Hidden_Winsock_Window"; |
windowClass.lpszClassName = "Hidden_Winsock_Window"; |
windowClass->style = CS_HREDRAW | CS_VREDRAW; |
windowClass.style = CS_HREDRAW | CS_VREDRAW; |
windowClass->lpfnWndProc = WndProcedure; |
windowClass.lpfnWndProc = WndProcedure; |
windowClass->cbClsExtra = 0; |
windowClass.cbClsExtra = 0; |
windowClass->cbWndExtra = 0; |
windowClass.cbWndExtra = 0; |
windowClass->hInstance = hInstance; |
windowClass.hInstance = hInstance; |
windowClass->hIcon = NULL; |
windowClass.hIcon = NULL; |
windowClass->hCursor = NULL; |
windowClass.hCursor = NULL; |
windowClass->hbrBackground = (HBRUSH)(COLOR_WINDOW+1); |
windowClass.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); |
windowClass->lpszMenuName = NULL; |
windowClass.lpszMenuName = NULL; |
RegisterClass(windowClass); |
RegisterClass(&windowClass); |
| |
// create window | // create window |
return CreateWindow( | return CreateWindow( |
|
|
// Create a window | // Create a window |
HWND hwnd = WineCreateWindow( hInstance ); | HWND hwnd = WineCreateWindow( hInstance ); |
if( hwnd == NULL ){ | if( hwnd == NULL ){ |
printf( "%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 |
printf( "%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 ){ |
printf( "%d: socket error: %ld\n", __LINE__, WSAGetLastError() ); |
trace( "socket error: %d\n", WSAGetLastError() ); |
ExitThread( TH_SOCKET_ERROR ); | ExitThread( TH_SOCKET_ERROR ); |
} | } |
| |
// Bind the socket. | // Bind the socket. |
sockaddr_in sockAddr; |
SOCKADDR_IN sockAddr; |
sockAddr.sin_family = AF_INET; | sockAddr.sin_family = AF_INET; |
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 ){ |
printf( "%d: bind failed weith error code %ld\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 ){ |
printf( "%d: listen error with error code %ld.\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 ){ |
| |
printf( "%d: WSAAsyncSelect Failed %ld\n", __LINE__, WSAGetLastError() ); |
trace( "WSAAsyncSelect Failed %d\n", WSAGetLastError() ); |
closesocket( sock ); | closesocket( sock ); |
ExitThread( TH_SELECT_ERROR ); | ExitThread( TH_SELECT_ERROR ); |
| |
} | } |
| |
printf( "listening and going to loop %d\n", GetCurrentThreadId() ); |
trace( "listening and going to loop %ld\n", GetCurrentThreadId() ); |
| |
BOOL retVal; | BOOL retVal; |
MSG msg; | MSG msg; |
|
|
if( retVal == -1 ){ | if( retVal == -1 ){ |
| |
// handle the error and possibly exit | // handle the error and possibly exit |
printf( "%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 ); |
| |
printf( "%d 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 ){ |
printf( "%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 |
printf( "%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 ) { |
printf( "%d: socket returned with error code: %ld\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 ){ |
printf( "%d: WSAAsyncSelect Failed %ld\n", __LINE__, WSAGetLastError() ); |
trace( "WSAAsyncSelect Failed %d\n", WSAGetLastError() ); |
closesocket( sock ); | closesocket( sock ); |
ExitThread( TH_SELECT_ERROR ); | ExitThread( TH_SELECT_ERROR ); |
} | } |
| |
/* connect */ | /* connect */ |
sockaddr_in sockAddr; |
SOCKADDR_IN sockAddr; |
sockAddr.sin_family = AF_INET; | sockAddr.sin_family = AF_INET; |
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( connect( sock, (SOCKADDR*) &sockAddr, sizeof( sockAddr ) ) == SOCKET_ERROR ){ | if( connect( sock, (SOCKADDR*) &sockAddr, sizeof( sockAddr ) ) == SOCKET_ERROR ){ |
if( WSAGetLastError() != WSAEWOULDBLOCK ){ | if( WSAGetLastError() != WSAEWOULDBLOCK ){ |
printf( "%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 |
printf( "%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 ); |
| |
//printf( "%d still here?\n", GetCurrentThreadId() ); |
|
ResumeThread( ServerThread.handle ); |
|
} | } |
return 0; | return 0; |
} | } |
|
|
FileBuf[FILE_SZ - 1] = (char) EOF; | FileBuf[FILE_SZ - 1] = (char) EOF; |
} | } |
| |
void main() |
START_TEST( WineWinsockAsyncTest ) |
{ | { |
// Create the file that we are going to send. | // Create the file that we are going to send. |
WineCreateFile(); | WineCreateFile(); |
|
|
| |
if( ServerThread.handle == NULL ){ | if( ServerThread.handle == NULL ){ |
| |
printf( "%d: CreateThread failed %d\n", __LINE__, GetLastError() ); |
trace( "CreateThread failed %ld\n", GetLastError() ); |
WineThreadCleanUp(); | WineThreadCleanUp(); |
return; | return; |
} | } |
| |
printf( "%d: server thread %d created\n", GetCurrentThreadId(), ServerThread.id ); |
trace( "%ld: server thread %ld created\n", GetCurrentThreadId(), ServerThread.id ); |
| |
// Wait for three seconds to let server start | // Wait for three seconds to let server start |
DWORD waitRet = WaitForSingleObject( ServerThread.handle, SERVER_START_TIME ); | DWORD waitRet = WaitForSingleObject( ServerThread.handle, SERVER_START_TIME ); |
if( waitRet == WAIT_FAILED ){ | if( waitRet == WAIT_FAILED ){ |
| |
// WaitForSingleObject failed for whatever reason | // WaitForSingleObject failed for whatever reason |
printf( "%d: WaitForSingleObject failed with error code %d\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 ){ |
| |
printf( "%d: GetExitCodeThread failed with error code %ld\n", __LINE__, GetLastError() ); |
trace( "GetExitCodeThread failed with error code %ld\n",GetLastError() ); |
WineThreadCleanUp(); | WineThreadCleanUp(); |
return; | return; |
| |
} | } |
| |
printf( "%d: server started successfully now creating client thread\n", GetCurrentThreadId() ); |
trace( "%ld: server started successfully now creating client thread\n", GetCurrentThreadId() ); |
| |
// Create client thread in suspended state | // Create client thread in suspended state |
ClientThread.handle = CreateThread( NULL, 0, (LPTHREAD_START_ROUTINE)WineRunClient, | ClientThread.handle = CreateThread( NULL, 0, (LPTHREAD_START_ROUTINE)WineRunClient, |
|
|
| |
if( ClientThread.handle == NULL ){ | if( ClientThread.handle == NULL ){ |
| |
printf( "%d: CreateThread failed %d\n", __LINE__, GetLastError() ); |
trace( "CreateThread failed %ld\n", GetLastError() ); |
WineThreadCleanUp(); | WineThreadCleanUp(); |
return; | return; |
} | } |
| |
printf( "%d: client thread %d created. Now wait.\n", GetCurrentThreadId(), ClientThread.id ); |
trace( "%ld: client thread %ld created. Now wait.\n", GetCurrentThreadId(), ClientThread.id ); |
| |
// Wait for this server to suspsend itself | // Wait for this server to suspsend itself |
HANDLE threadHandles[NUM_THREADS_TO_WAIT] = { ServerThread.handle, ClientThread.handle }; | HANDLE threadHandles[NUM_THREADS_TO_WAIT] = { ServerThread.handle, ClientThread.handle }; |
|
|
if( waitRet == WAIT_FAILED ){ | if( waitRet == WAIT_FAILED ){ |
| |
// WaitForSingleObject failed for whatever reason | // WaitForSingleObject failed for whatever reason |
printf( "%d: WaitForMultipleObjects failed with error code %d\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 ){ |
| |
printf( "%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; |
| |
|
|
// clean up the threads | // clean up the threads |
WineThreadCleanUp(); | WineThreadCleanUp(); |
| |
printf( "%d: main thread exiting...\n", GetCurrentThreadId() ); |
trace( "%ld: main thread exiting...\n", GetCurrentThreadId() ); |
while(1); |
|
} | } |