Home | Info | Community | Development | myReactOS | Contact Us
[static]
Definition at line 77 of file piperead.cpp.
Referenced by main().
{ HANDLE hPipe=INVALID_HANDLE_VALUE; TCHAR chBuf[BUFSIZE]; BOOL fSuccess = FALSE; DWORD cbRead; DWORD Err; int res = 0; setvbuf(stdout, NULL, _IONBF, 0); while (1) { hPipe = CreateFile( path, // pipe name GENERIC_READ, 0, // no sharing NULL, // default security attributes OPEN_EXISTING, // opens existing pipe 0, // default attributes NULL); // no template file // Break if the pipe handle is valid. if (hPipe != INVALID_HANDLE_VALUE) break; // Exit if an error other than ERROR_PIPE_BUSY occurs. Err = GetLastError(); if (Err != ERROR_PIPE_BUSY) { if (ERROR_FILE_NOT_FOUND == Err) { res = PIPEREAD_NOPIPE; return res; } else { fprintf(stderr,"Could not open pipe %s. Error=%lu\n", path, Err ); res = -1; } break; } // All pipe instances are busy, so wait for 20 seconds. if ( ! WaitNamedPipe(path, 20000)) { fprintf(stderr,"Could not open pipe: 20 second wait timed out."); res = -2; break; } } if (!res) do { fSuccess = ReadFile( hPipe, // pipe handle chBuf, // buffer to receive reply BUFSIZE, // size of buffer &cbRead, // number of bytes read NULL); // not overlapped if ( ! fSuccess ) { Err = GetLastError(); if ( Err == ERROR_MORE_DATA ) { fSuccess = TRUE; } else { fprintf(stderr, "ReadFile: Error %lu \n", Err ); res = -9; break; } } fwrite(chBuf,1,cbRead,stdout); } while ( fSuccess); if ( ! fSuccess) { fprintf(stderr, "ReadFile from pipe failed. Error=%lu\n", GetLastError() ); } if (hPipe != INVALID_HANDLE_VALUE) CloseHandle(hPipe); return res; }