Cygwin: pipes: always signal select_sem if any bytes are read or written
Fold all code branches potentially having read or written data into a single if branch, so signalling select_sem catches all cases. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
parent
08b8534d0a
commit
ba4c58299f
|
@ -303,19 +303,10 @@ fhandler_pipe::raw_read (void *ptr, size_t& len)
|
||||||
waitret = WAIT_OBJECT_0;
|
waitret = WAIT_OBJECT_0;
|
||||||
|
|
||||||
if (waitret == WAIT_CANCELED)
|
if (waitret == WAIT_CANCELED)
|
||||||
{
|
|
||||||
status = STATUS_THREAD_CANCELED;
|
status = STATUS_THREAD_CANCELED;
|
||||||
break;
|
|
||||||
}
|
|
||||||
else if (waitret == WAIT_SIGNALED)
|
else if (waitret == WAIT_SIGNALED)
|
||||||
{
|
|
||||||
status = STATUS_THREAD_SIGNALED;
|
status = STATUS_THREAD_SIGNALED;
|
||||||
nbytes += io.Information;
|
else
|
||||||
if (select_sem && io.Information > 0)
|
|
||||||
ReleaseSemaphore (select_sem,
|
|
||||||
get_obj_handle_count (select_sem), NULL);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
status = io.Status;
|
status = io.Status;
|
||||||
}
|
}
|
||||||
if (isclosed ()) /* A signal handler might have closed the fd. */
|
if (isclosed ()) /* A signal handler might have closed the fd. */
|
||||||
|
@ -326,11 +317,17 @@ fhandler_pipe::raw_read (void *ptr, size_t& len)
|
||||||
__seterrno ();
|
__seterrno ();
|
||||||
nbytes = (size_t) -1;
|
nbytes = (size_t) -1;
|
||||||
}
|
}
|
||||||
else if (NT_SUCCESS (status))
|
else if (NT_SUCCESS (status)
|
||||||
|
|| status == STATUS_BUFFER_OVERFLOW
|
||||||
|
|| status == STATUS_THREAD_CANCELED
|
||||||
|
|| status == STATUS_THREAD_SIGNALED)
|
||||||
{
|
{
|
||||||
nbytes_now = io.Information;
|
nbytes_now = io.Information;
|
||||||
ptr = ((char *) ptr) + nbytes_now;
|
ptr = ((char *) ptr) + nbytes_now;
|
||||||
nbytes += nbytes_now;
|
nbytes += nbytes_now;
|
||||||
|
if (select_sem && nbytes_now > 0)
|
||||||
|
ReleaseSemaphore (select_sem,
|
||||||
|
get_obj_handle_count (select_sem), NULL);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -341,13 +338,6 @@ fhandler_pipe::raw_read (void *ptr, size_t& len)
|
||||||
case STATUS_PIPE_BROKEN:
|
case STATUS_PIPE_BROKEN:
|
||||||
/* This is really EOF. */
|
/* This is really EOF. */
|
||||||
break;
|
break;
|
||||||
case STATUS_MORE_ENTRIES:
|
|
||||||
case STATUS_BUFFER_OVERFLOW:
|
|
||||||
/* `io.Information' is supposedly valid. */
|
|
||||||
nbytes_now = io.Information;
|
|
||||||
ptr = ((char *) ptr) + nbytes_now;
|
|
||||||
nbytes += nbytes_now;
|
|
||||||
break;
|
|
||||||
case STATUS_PIPE_LISTENING:
|
case STATUS_PIPE_LISTENING:
|
||||||
case STATUS_PIPE_EMPTY:
|
case STATUS_PIPE_EMPTY:
|
||||||
if (nbytes != 0)
|
if (nbytes != 0)
|
||||||
|
@ -366,10 +356,8 @@ fhandler_pipe::raw_read (void *ptr, size_t& len)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nbytes_now == 0)
|
if (nbytes_now == 0 || status == STATUS_BUFFER_OVERFLOW)
|
||||||
break;
|
break;
|
||||||
else if (select_sem)
|
|
||||||
ReleaseSemaphore (select_sem, get_obj_handle_count (select_sem), NULL);
|
|
||||||
}
|
}
|
||||||
ReleaseMutex (read_mtx);
|
ReleaseMutex (read_mtx);
|
||||||
if (evt)
|
if (evt)
|
||||||
|
@ -467,19 +455,10 @@ fhandler_pipe_fifo::raw_write (const void *ptr, size_t len)
|
||||||
waitret = WAIT_OBJECT_0;
|
waitret = WAIT_OBJECT_0;
|
||||||
|
|
||||||
if (waitret == WAIT_CANCELED)
|
if (waitret == WAIT_CANCELED)
|
||||||
{
|
|
||||||
status = STATUS_THREAD_CANCELED;
|
status = STATUS_THREAD_CANCELED;
|
||||||
break;
|
|
||||||
}
|
|
||||||
else if (waitret == WAIT_SIGNALED)
|
else if (waitret == WAIT_SIGNALED)
|
||||||
{
|
|
||||||
status = STATUS_THREAD_SIGNALED;
|
status = STATUS_THREAD_SIGNALED;
|
||||||
nbytes += io.Information;
|
else
|
||||||
if (select_sem && io.Information > 0)
|
|
||||||
ReleaseSemaphore (select_sem,
|
|
||||||
get_obj_handle_count (select_sem), NULL);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
status = io.Status;
|
status = io.Status;
|
||||||
}
|
}
|
||||||
if (isclosed ()) /* A signal handler might have closed the fd. */
|
if (isclosed ()) /* A signal handler might have closed the fd. */
|
||||||
|
@ -489,13 +468,18 @@ fhandler_pipe_fifo::raw_write (const void *ptr, size_t len)
|
||||||
else
|
else
|
||||||
__seterrno ();
|
__seterrno ();
|
||||||
}
|
}
|
||||||
else if (NT_SUCCESS (status))
|
else if (NT_SUCCESS (status)
|
||||||
|
|| status == STATUS_THREAD_CANCELED
|
||||||
|
|| status == STATUS_THREAD_SIGNALED)
|
||||||
{
|
{
|
||||||
nbytes_now = io.Information;
|
nbytes_now = io.Information;
|
||||||
ptr = ((char *) ptr) + nbytes_now;
|
ptr = ((char *) ptr) + nbytes_now;
|
||||||
nbytes += nbytes_now;
|
nbytes += nbytes_now;
|
||||||
|
if (select_sem && nbytes_now > 0)
|
||||||
|
ReleaseSemaphore (select_sem,
|
||||||
|
get_obj_handle_count (select_sem), NULL);
|
||||||
/* 0 bytes returned? EAGAIN. See above. */
|
/* 0 bytes returned? EAGAIN. See above. */
|
||||||
if (nbytes == 0)
|
if (NT_SUCCESS (status) && nbytes == 0)
|
||||||
set_errno (EAGAIN);
|
set_errno (EAGAIN);
|
||||||
}
|
}
|
||||||
else if (STATUS_PIPE_IS_CLOSED (status))
|
else if (STATUS_PIPE_IS_CLOSED (status))
|
||||||
|
@ -508,8 +492,6 @@ fhandler_pipe_fifo::raw_write (const void *ptr, size_t len)
|
||||||
|
|
||||||
if (nbytes_now == 0)
|
if (nbytes_now == 0)
|
||||||
break;
|
break;
|
||||||
else if (select_sem)
|
|
||||||
ReleaseSemaphore (select_sem, get_obj_handle_count (select_sem), NULL);
|
|
||||||
}
|
}
|
||||||
if (evt)
|
if (evt)
|
||||||
CloseHandle (evt);
|
CloseHandle (evt);
|
||||||
|
|
Loading…
Reference in New Issue