Listing 3: Sample client using the named pipe class
nmpipe_cConnector::nmpipe_cConnector(const char *pPipeName,
int MaxRetries) { if (bInError) { return; } for (int i=0; i<MaxRetries; i++) { BOOL bSuccess = WaitNamedPipe(pPipeName, NMPWAIT_USE_DEFAULT_WAIT); if (bSuccess) { hPipe = CreateFile(pPipeName, GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL); if (hPipe != INVALID_HANDLE_VALUE) { return; } REPORT("Failure: CreateFile() -- WinError = %u\n", GetLastError()); } else { REPORT("Warning: WaitNamedPipe() failed (retrying)" " -- WinError = %u\n", GetLastError()); } } REPORT("Failure: WaitNamedPipe() -- retry limit exceeded\n"); bInError = TRUE; } nmpipe_cConnector::~nmpipe_cConnector() { if (hPipe != INVALID_HANDLE_VALUE) { FlushFileBuffers(hPipe); w CloseHandle(hPipe); } } //End of File