/*
    This function illustrates the ideal send and recv scenario where
    one thread does the recv independently until it gets a 0 or an error
    and the other thread (in this case, the current thread) does sends
    until all data is sent. This is the truly asynchronous implementation
    of the client unlike the earlier scenarios which were mostly meant
    for testing specific sequence of events in the server and understanding
    the need for different parts of the server code.
*/
void DoIdealSendRecv()
{
    HANDLE hThread;

    // start the receiver thread.
    hThread = CreateThread(NULL, 0, ReceiverThread, NULL, 0, NULL);
    if (hThread == NULL)
    {
        printf("ERROR: CreateThread failed. Error = %d\n", GetLastError());
        goto CLEANUP;
    }

    // In this thread, send all data until done.
    DoSendUntilDone();
    DoShutDown();

    // wait till recv thread is done.
    if (WaitForSingleObject(hThread, INFINITE) != WAIT_OBJECT_0)
    {
        printf("ERROR: WaitForSingleObject failed: %d\n", GetLastError());
        goto CLEANUP;
    }
    printf("Recv Thread done.\n");

CLEANUP:
    
    return;
}
/*
    This function implements the scenario to test the server to get
    a FD_WRITE event before an FD_READ event.
*/
void DoWaitSendRecv()
{
    printf("Waiting before doing initial send ...\n");
    Sleep(g_ClientContext.delay);
    DoSendUntilDone();
    DoShutDown();        
    DoRecvUntilDone();
}
/*
    This function implements the scenario where the client waits for a certain
    time before doing the recv thereby allowing the server code to get
    a WSAEWOULDBLOCK on a send, especially when the data buffer is huge.
*/
void DoSendWaitRecv()
{
    DoSendUntilDone();
    DoShutDown();      
    printf("Waiting before doing recv ...\n");
    Sleep(g_ClientContext.delay);
    DoRecvUntilDone();
}
/*
    This function implements the scenario where the client only sends but
    doesn't recv the echoed data back. This helps demonstrate possible
    deadlocks in the server side for huge sized data buffer.
*/
void DoSendNoRecv()
{
    DoSendUntilDone();
    DoShutDown();    
}
/*
    This function implements the scenario where all the sends are done first
    and all the recvs next.
*/
void DoSendThenRecv()
{
    DoSendUntilDone();
    DoShutDown();
    DoRecvUntilDone();
}
Beispiel #6
0
 void Engine::Run() {
     while(running && DoShutDown()) {
         TimeManager::Get()->Update();
         OneStep();  
     }
 }