Cygwin: FIFO: simplify raw_read
Call NtReadFile directly instead of calling fhandler_base::raw_read. In addition to being simpler, this gives us access to the return value from NtReadFile.
This commit is contained in:
parent
5bd5e3dc6c
commit
5b2696cb83
|
@ -802,8 +802,6 @@ fhandler_fifo::check_listen_client_thread ()
|
||||||
void __reg3
|
void __reg3
|
||||||
fhandler_fifo::raw_read (void *in_ptr, size_t& len)
|
fhandler_fifo::raw_read (void *in_ptr, size_t& len)
|
||||||
{
|
{
|
||||||
size_t orig_len = len;
|
|
||||||
|
|
||||||
/* Make sure the lct is running. */
|
/* Make sure the lct is running. */
|
||||||
int res = check_listen_client_thread ();
|
int res = check_listen_client_thread ();
|
||||||
debug_printf ("lct status %d", res);
|
debug_printf ("lct status %d", res);
|
||||||
|
@ -826,26 +824,40 @@ fhandler_fifo::raw_read (void *in_ptr, size_t& len)
|
||||||
for (int i = 0; i < nhandlers; i++)
|
for (int i = 0; i < nhandlers; i++)
|
||||||
if (fc_handler[i].state == fc_connected)
|
if (fc_handler[i].state == fc_connected)
|
||||||
{
|
{
|
||||||
len = orig_len;
|
NTSTATUS status;
|
||||||
fc_handler[i].fh->fhandler_base::raw_read (in_ptr, len);
|
IO_STATUS_BLOCK io;
|
||||||
ssize_t nread = (ssize_t) len;
|
size_t nbytes = 0;
|
||||||
if (nread > 0)
|
|
||||||
{
|
status = NtReadFile (get_fc_handle (i), NULL, NULL, NULL,
|
||||||
fifo_client_unlock ();
|
&io, in_ptr, len, NULL, NULL);
|
||||||
return;
|
switch (status)
|
||||||
}
|
|
||||||
/* If the pipe is empty, we get nread == -1 with
|
|
||||||
ERROR_NO_DATA. */
|
|
||||||
else if (nread < 0 && GetLastError () != ERROR_NO_DATA)
|
|
||||||
{
|
|
||||||
fifo_client_unlock ();
|
|
||||||
goto errout;
|
|
||||||
}
|
|
||||||
else if (nread == 0)
|
|
||||||
/* Client has disconnected. */
|
|
||||||
{
|
{
|
||||||
|
case STATUS_SUCCESS:
|
||||||
|
case STATUS_BUFFER_OVERFLOW:
|
||||||
|
/* io.Information is supposedly valid. */
|
||||||
|
nbytes = io.Information;
|
||||||
|
if (nbytes > 0)
|
||||||
|
{
|
||||||
|
len = nbytes;
|
||||||
|
fifo_client_unlock ();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case STATUS_PIPE_EMPTY:
|
||||||
|
break;
|
||||||
|
case STATUS_PIPE_BROKEN:
|
||||||
|
/* Client has disconnected. Mark the client handler
|
||||||
|
to be deleted when it's safe to do that. */
|
||||||
fc_handler[i].state = fc_invalid;
|
fc_handler[i].state = fc_invalid;
|
||||||
nconnected--;
|
nconnected--;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
debug_printf ("NtReadFile status %y", status);
|
||||||
|
__seterrno_from_nt_status (status);
|
||||||
|
fc_handler[i].state = fc_invalid;
|
||||||
|
nconnected--;
|
||||||
|
fifo_client_unlock ();
|
||||||
|
goto errout;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fifo_client_unlock ();
|
fifo_client_unlock ();
|
||||||
|
|
Loading…
Reference in New Issue