You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by wr...@apache.org on 2003/01/24 19:25:31 UTC

cvs commit: apr/file_io/win32 readwrite.c

wrowe       2003/01/24 10:25:31

  Modified:    file_io/win32 readwrite.c
  Log:
    Simplify and be more thorough.  We only want to know how many bytes are
    in the pipe with a timeout of zero, we don't need to retrieve them.
    Even so, we must not try to read more bytes than are now available
    if the timeout is zero.
  
  Revision  Changes    Path
  1.77      +10 -13    apr/file_io/win32/readwrite.c
  
  Index: readwrite.c
  ===================================================================
  RCS file: /home/cvs/apr/file_io/win32/readwrite.c,v
  retrieving revision 1.76
  retrieving revision 1.77
  diff -u -r1.76 -r1.77
  --- readwrite.c	7 Jan 2003 00:52:54 -0000	1.76
  +++ readwrite.c	24 Jan 2003 18:25:31 -0000	1.77
  @@ -77,23 +77,20 @@
            * If data is available, go ahead and read it.
            */
           if (file->pipe) {
  -            char tmpbuf[5];
  -            DWORD dwBytesRead;
  -            DWORD dwBytesAvail;
  -            DWORD dwBytesLeftThisMsg;
  -            if (!PeekNamedPipe(file->filehand,         // handle to pipe to copy from
  -                               &tmpbuf,                   // pointer to data buffer
  -                               sizeof(tmpbuf),            // size, in bytes, of data buffer
  -                               &dwBytesRead,           // pointer to number of bytes read
  -                               &dwBytesAvail,          // pointer to total number of bytes available
  -                               &dwBytesLeftThisMsg)) { // pointer to unread bytes in this message
  +            DWORD bytes;
  +            if (!PeekNamedPipe(file->filehand, NULL, 0, NULL, &bytes, NULL)) {
                   rv = apr_get_os_error();
  -                if (rv == APR_FROM_OS_ERROR(ERROR_BROKEN_PIPE))
  -                    return APR_EOF;
  +                if (rv == APR_FROM_OS_ERROR(ERROR_BROKEN_PIPE)) {
  +                    rv = APR_EOF;
  +                }
  +                return rv;
               }
               else {
  -                if (dwBytesRead == 0) {
  +                if (bytes == 0) {
                       return APR_EAGAIN;
  +                }
  +                if (len > bytes) {
  +                    len = bytes;
                   }
               }
           }