ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

static int pipeClient ( char path) [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;
 
}

Generated on Fri May 25 2012 06:07:00 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.