ReleaseSemaphore (select_sem, n_release, NULL);
}
+/* Read from a non-blocking pipe and wait for completion. */
+static NTSTATUS
+nt_read (HANDLE h, HANDLE evt, PIO_STATUS_BLOCK pio, void *in_ptr, size_t& len)
+{
+ NTSTATUS status;
+
+ ResetEvent (evt);
+ status = NtReadFile (h, evt, NULL, NULL, pio, in_ptr, len, NULL, NULL);
+ if (status == STATUS_PENDING)
+ {
+ /* Very short-lived */
+ status = NtWaitForSingleObject (evt, FALSE, NULL);
+ if (NT_SUCCESS (status))
+ status = pio->Status;
+ }
+ return status;
+}
+
void __reg3
fhandler_fifo::raw_read (void *in_ptr, size_t& len)
{
+ HANDLE evt;
+
if (!len)
return;
+ if (!(evt = CreateEvent (NULL, false, false, NULL)))
+ {
+ __seterrno ();
+ len = (size_t) -1;
+ return;
+ }
+
while (1)
{
int nconnected = 0;
NTSTATUS status;
IO_STATUS_BLOCK io;
- status = NtReadFile (fc_handler[j].h, NULL, NULL, NULL,
- &io, in_ptr, len, NULL, NULL);
+ status = nt_read (fc_handler[j].h, evt, &io, in_ptr, len);
switch (status)
{
case STATUS_SUCCESS:
case STATUS_BUFFER_OVERFLOW:
- /* io.Information is supposedly valid in latter case. */
if (io.Information > 0)
{
len = io.Information;
- goto out;
+ goto unlock_out;
}
break;
case STATUS_PIPE_EMPTY:
fc_handler[j].set_state (fc_disconnected);
break;
default:
- debug_printf ("NtReadFile status %y", status);
+ debug_printf ("nt_read status %y", status);
fc_handler[j].set_state (fc_error);
break;
}
NTSTATUS status;
IO_STATUS_BLOCK io;
- status = NtReadFile (fc_handler[i].h, NULL, NULL, NULL,
- &io, in_ptr, len, NULL, NULL);
+ status = nt_read (fc_handler[i].h, evt, &io, in_ptr, len);
switch (status)
{
case STATUS_SUCCESS:
if (j < nhandlers)
fc_handler[j].last_read = false;
fc_handler[i].last_read = true;
- goto out;
+ goto unlock_out;
}
break;
case STATUS_PIPE_EMPTY:
fc_handler[i].set_state (fc_disconnected);
break;
default:
- debug_printf ("NtReadFile status %y", status);
+ debug_printf ("nt_read status %y", status);
fc_handler[i].set_state (fc_error);
break;
}
IO_STATUS_BLOCK io;
nconnected++;
- status = NtReadFile (fc_handler[i].h, NULL, NULL, NULL,
- &io, in_ptr, len, NULL, NULL);
+ status = nt_read (fc_handler[i].h, evt, &io, in_ptr, len);
switch (status)
{
case STATUS_SUCCESS:
if (j < nhandlers)
fc_handler[j].last_read = false;
fc_handler[i].last_read = true;
- goto out;
+ goto unlock_out;
}
break;
case STATUS_PIPE_EMPTY:
nconnected--;
break;
default:
- debug_printf ("NtReadFile status %y", status);
+ debug_printf ("nt_read status %y", status);
fc_handler[i].set_state (fc_error);
nconnected--;
break;
}
}
- fifo_client_unlock ();
if (!nconnected && hit_eof ())
{
- reading_unlock ();
len = 0;
- return;
+ goto unlock_out;
}
+ fifo_client_unlock ();
maybe_retry:
reading_unlock ();
if (is_nonblocking ())
{
set_errno (EAGAIN);
- goto errout;
+ len = (size_t) -1;
+ goto out;
}
else
{
else
{
set_errno (EINTR);
- goto errout;
+ len = (size_t) -1;
+ goto out;
}
}
}
if (isclosed ())
{
set_errno (EBADF);
- goto errout;
+ len = (size_t) -1;
+ goto out;
}
}
-errout:
- len = (size_t) -1;
- return;
-out:
+unlock_out:
fifo_client_unlock ();
reading_unlock ();
+out:
if (select_sem)
release_select_sem ("raw_read");
+ CloseHandle (evt);
}
int __reg2