Quantcast
Channel: Chilkat Forum - latest questions
Viewing all articles
Browse latest Browse all 1061

What's wrong with this AcceptNextConnection loop ?

$
0
0

Hi,

Is it the right way to do an infinite loop wich accepts simultaneaous incoming connections in a server of a multi-clients client-server application ?

It crashes with the non-blocking (asynchrounous) and blocking (synchronous) solution after an unknown amount of connections.

I'm going to try to count the number of connections before the unpredictable crash. It seems to crash faster with the asynchronous method...

But it crashes always... after an unknown number a successfull transactions :-(

Is there a memory leak, something to free ???

If I have time enough to test, I will try to limit my program at an acceptConnection followed by a closesocket, just to be sure that the problem comes from the acceptConnection loop.

Best regards

Thanks

This the simplified code :

    if (!CkSocket_UnlockComponent(listenSocket,"mycode....")) 
     goto label_endloop ;

if (!CkSocket_BindAndListen(listenSocket,5001,32)) 
        goto label_endloop ;

label_startloop :

if (byChilkat == 2) // NOT BLOCKING
    {

task = CkSocket_AcceptNextConnectionAsync(listenSocket,0);
        if (CkSocket_getLastMethodSuccess(listenSocket) != TRUE) 
        {   ShowError ("Error CkSocket_AcceptNextConnectionAsync :", (char *)CkSocket_lastErrorText(listenSocket), FALSE) ;
            goto label_startloop ;
        }

if (!CkTask_Run(task)) 
        {    ShowError ("Error CkTask_Run (CkSocket_AcceptNextConnectionAsync) :", (char *)CkSocket_lastErrorText(listenSocket), FALSE) ;
            CkTask_Dispose(task);
            goto label_startloop ;
        }

while (CkTask_getFinished(task) != TRUE) 
            CkTask_SleepMs(task,10);    //  Sleep 10 ms.

status = CkTask_getStatusInt(task) ;
        if (status != 7) 
        {    ShowError ("Task (CkSocket_AcceptNextConnectionAsync) did not complete. Task status: ", (char *)CkTask_status(task), FALSE) ;
            CkTask_Dispose(task);
            goto label_startloop ;
        }

clientSocket = CkSocket_Create();
        if (!CkSocket_LoadTaskResult(clientSocket, task)) 
        {    ShowError ("CkSocket_LoadTaskResult", (char *)CkSocket_lastErrorText(clientSocket), FALSE) ;
            CkTask_Dispose(task);
            goto label_startloop ;
        }

CkTask_Dispose(task);
    }
    else    // BLOCKING
    {
         clientSocket = CkSocket_AcceptNextConnection(listenSocket, 0);
    }

hThreadSocketChilkatC = CreateThread(NULL, 0, ThreadSocketQuestionResponse, (LPVOID)&clientSocket, 0, &dwThreadId);

goto label_startloop ;

label_endloop :

Viewing all articles
Browse latest Browse all 1061

Trending Articles