GetOverlappedResult: Return ERROR_IO_INCOMPLETE if IO still pending.
ReadFile / WriteFile: Use GetOverlappedResult() to check for immediate completion.
This commit is contained in:
parent
874d671e22
commit
e0587d4a64
74
files/file.c
74
files/file.c
|
@ -1410,7 +1410,8 @@ BOOL WINAPI GetOverlappedResult(
|
||||||
if(lpTransferred)
|
if(lpTransferred)
|
||||||
*lpTransferred = lpOverlapped->InternalHigh;
|
*lpTransferred = lpOverlapped->InternalHigh;
|
||||||
|
|
||||||
SetLastError(lpOverlapped->Internal);
|
SetLastError ( lpOverlapped->Internal == STATUS_PENDING ?
|
||||||
|
ERROR_IO_INCOMPLETE : lpOverlapped->Internal );
|
||||||
|
|
||||||
return (r==WAIT_OBJECT_0);
|
return (r==WAIT_OBJECT_0);
|
||||||
}
|
}
|
||||||
|
@ -1599,41 +1600,21 @@ BOOL WINAPI ReadFile( HANDLE hFile, LPVOID buffer, DWORD bytesToRead,
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* see if we can read some data already (this shouldn't block) */
|
|
||||||
result = pread( unix_handle, buffer, bytesToRead, OVERLAPPED_OFFSET(overlapped) );
|
|
||||||
if ((result < 0) && (errno == ESPIPE))
|
|
||||||
result = read( unix_handle, buffer, bytesToRead );
|
|
||||||
close(unix_handle);
|
close(unix_handle);
|
||||||
|
overlapped->InternalHigh = 0;
|
||||||
if(result<0)
|
|
||||||
{
|
|
||||||
if( (errno!=EAGAIN) && (errno!=EINTR) &&
|
|
||||||
((errno != EFAULT) || IsBadWritePtr( buffer, bytesToRead )) )
|
|
||||||
{
|
|
||||||
FILE_SetDosError();
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
result = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* if we read enough to keep the app happy, then return now */
|
|
||||||
if(result>=bytesToRead)
|
|
||||||
{
|
|
||||||
*bytesRead = result;
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* at last resort, do an overlapped read */
|
|
||||||
overlapped->InternalHigh = result;
|
|
||||||
|
|
||||||
if(!FILE_ReadFileEx(hFile, buffer, bytesToRead, overlapped, NULL, overlapped->hEvent))
|
if(!FILE_ReadFileEx(hFile, buffer, bytesToRead, overlapped, NULL, overlapped->hEvent))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
/* fail on return, with ERROR_IO_PENDING */
|
if ( !GetOverlappedResult (hFile, overlapped, bytesRead, FALSE) )
|
||||||
|
{
|
||||||
|
if ( GetLastError() == ERROR_IO_INCOMPLETE )
|
||||||
SetLastError ( ERROR_IO_PENDING );
|
SetLastError ( ERROR_IO_PENDING );
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
if (flags & FD_FLAG_TIMEOUT)
|
if (flags & FD_FLAG_TIMEOUT)
|
||||||
{
|
{
|
||||||
close(unix_handle);
|
close(unix_handle);
|
||||||
|
@ -1817,45 +1798,22 @@ BOOL WINAPI WriteFile( HANDLE hFile, LPCVOID buffer, DWORD bytesToWrite,
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* see if we can write some data already (this shouldn't block) */
|
|
||||||
|
|
||||||
result = pwrite( unix_handle, buffer, bytesToWrite, OVERLAPPED_OFFSET (overlapped) );
|
|
||||||
if ((result < 0) && (errno == ESPIPE))
|
|
||||||
result = write( unix_handle, buffer, bytesToWrite );
|
|
||||||
|
|
||||||
close(unix_handle);
|
close(unix_handle);
|
||||||
|
overlapped->InternalHigh = 0;
|
||||||
if(result<0)
|
|
||||||
{
|
|
||||||
if( (errno!=EAGAIN) && (errno!=EINTR) &&
|
|
||||||
((errno != EFAULT) || IsBadReadPtr( buffer, bytesToWrite )) )
|
|
||||||
{
|
|
||||||
FILE_SetDosError();
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
result = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* if we wrote enough to keep the app happy, then return now */
|
|
||||||
if(result>=bytesToWrite)
|
|
||||||
{
|
|
||||||
*bytesWritten = result;
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* at last resort, do an overlapped read */
|
|
||||||
overlapped->Internal = STATUS_PENDING;
|
|
||||||
overlapped->InternalHigh = result;
|
|
||||||
|
|
||||||
if(!FILE_WriteFileEx(hFile, buffer, bytesToWrite, overlapped, NULL, overlapped->hEvent))
|
if(!FILE_WriteFileEx(hFile, buffer, bytesToWrite, overlapped, NULL, overlapped->hEvent))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
/* fail on return, with ERROR_IO_PENDING */
|
if ( !GetOverlappedResult (hFile, overlapped, bytesWritten, FALSE) )
|
||||||
|
{
|
||||||
|
if ( GetLastError() == ERROR_IO_INCOMPLETE )
|
||||||
SetLastError ( ERROR_IO_PENDING );
|
SetLastError ( ERROR_IO_PENDING );
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
switch(type)
|
switch(type)
|
||||||
{
|
{
|
||||||
case FD_TYPE_CONSOLE:
|
case FD_TYPE_CONSOLE:
|
||||||
|
|
Loading…
Reference in New Issue