From: Adrian Aichner [mailto:aichnerï¼ ecf.teradyne.com]
Any ideas what I could do to make (call-process ...) interruptible on
Windows NT native?
Is there a way to make read(...) interruptible on Windows NT?
Nope, read() is non-blocking on Win9x, but that shouldn't stop us from
devising interesting alternatives to get things working. :) Sockets are the
only thing on Win32 that have non-blocking reads like Unix does. Win 9x
doesn't really support asynchronous I/O for files or pipes, and NT supports
overlapped I/O and I/O completion ports like a champ on files, pipes, etc...
So given those annoying constraints, we can't use overlapped I/O and we
can't use non-blocking I/O since it doesn't exist... :(
We can however approximate non-blocking reads on pipes on NT and Win9x by
making use of PeekNamedPipe().
something like the following should help lead the way:
int non_blocking_pipe_read
//-----------------------------------------------------------
// return EWOULDBLOCK if the pipe doesn't contain any readable data
//
(
HANDLE hPipe,
// [in] handle to the pipe
UINT cbBuffer,
// [in] number of bytes in the buffer
UINT *pcbRead,
// [in,out] number of bytes that were actually read into the buffer
BYTE *pbBuffer
// [in,out] buffer to copy data into
)
{
UINT cbAvailable = 0;
if (!PeekNamedPipe(hPipe, NULL, 0, NULL, &cbAvailable, NULL))
{
<error handling>
}
if (cbAvailable > 0)
{
if (cbAvailable > cbBuffer)
{
<error handling>
}
if (!ReadFile(hPipe, pbBuffer, cbAvailable, pcbRead, NULL)
{
<error handling>
}
return 0;
}
else
{
return EWOULDBLOCK;
}
}
NOTE: This only works on pipes, you can't use it on normal files.
I don't know whether or not this is an issue with the XEmacs internals are
not, I wouldn't be surprised if it was.
Bill