Skip to content

Commit

Permalink
Part 1 of many read_with_timeout logic fixes. Stop polluting one
Browse files Browse the repository at this point in the history
  occurance of rv with the boolean result of ReadFile() to increase
  the legibility of the success/failure of ReadFile.  This requires
  us to defer *nbytes assignment to the function's end.

  This fix catches additional cases of APR_EOF, as we had not
  tested this case from the error handling path.  So any deferred
  read of zero bytes previously returned 0 bytes APR_SUCCESS 
  rather than APR_EOF.  (This occurs when we wait to discover the 
  owner of the write end closes it without additional data)



git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@388281 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
wrowe committed Mar 23, 2006
1 parent 8320845 commit c49a6a3
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions file_io/win32/readwrite.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ static apr_status_t read_with_timeout(apr_file_t *file, void *buf, apr_size_t le
file->pOverlapped->OffsetHigh = (DWORD)(file->filePtr >> 32);
}

rv = ReadFile(file->filehand, buf, len,
&bytesread, file->pOverlapped);
*nbytes = bytesread;

if (!rv) {
if (ReadFile(file->filehand, buf, len,
&bytesread, file->pOverlapped)) {
rv = APR_SUCCESS;
}
else {
rv = apr_get_os_error();
if (rv == APR_FROM_OS_ERROR(ERROR_IO_PENDING)) {
/* Wait for the pending i/o */
Expand Down Expand Up @@ -117,16 +117,16 @@ static apr_status_t read_with_timeout(apr_file_t *file, void *buf, apr_size_t le
/* Assume ERROR_BROKEN_PIPE signals an EOF reading from a pipe */
rv = APR_EOF;
}
} else {
/* OK and 0 bytes read ==> end of file */
if (*nbytes == 0)
rv = APR_EOF;
else
rv = APR_SUCCESS;
}

/* OK and 0 bytes read ==> end of file */
if (rv == APR_SUCCESS && bytesread == 0)
rv = APR_EOF;
}
if (rv == APR_SUCCESS && file->pOverlapped && !file->pipe) {
file->filePtr += *nbytes;
file->filePtr += bytesread;
}
*nbytes = bytesread;
return rv;
}

Expand Down

0 comments on commit c49a6a3

Please sign in to comment.