OVERLAPPED op;
HANDLE h,
handleArray[2];
BOOL bStop = FALSE;
memset(&op, 0, sizeof(op));
--> create a event for monitoring new CONNECTIONS
handleArray[0] = op.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
handleArray[1] = gbl_hStopEvent;
while (bStop == FALSE)
{
-->create the named pipe or a new instance of a named pipe with overlapeed i/oh = CreateNamedPipe(FILE_FLAG_OVERLAPPED);
-->connect named pipe returns immediately the overlapped structure tells
it that we want to do a async i/o operation
ConnectNamedPipe(h, &op);
-->now we wait for a new connection on the named pipe
switch (WaitForMultipleObjects(
2, handleArray, FALSE, INFINITE))
{
case WAIT_OBJECT_0:
--> here is a new connection established
_beginthread(threadProc, 0, h);
ResetEvent(handleArray[0]);
break;
case WAIT_OBJECT_0 + 1:
CloseHandle(h);
bStop = TRUE;
break;
}
}
CloseHandle(handleArray[0]);