server: Remove the socket from the polling loop if both it and the peer have SHUT_WR.

Based on a patch by Torge Matthies.

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=51319
Signed-off-by: Zebediah Figura <zfigura@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Zebediah Figura 2021-07-26 11:53:44 -05:00 committed by Alexandre Julliard
parent ec07f285e2
commit 361435f609
1 changed files with 17 additions and 0 deletions

View File

@ -1161,6 +1161,20 @@ static int sock_get_poll_events( struct fd *fd )
case SOCK_CONNECTED: case SOCK_CONNECTED:
case SOCK_CONNECTIONLESS: case SOCK_CONNECTIONLESS:
if (sock->hangup && sock->wr_shutdown && !sock->wr_shutdown_pending)
{
/* Linux returns POLLHUP if a socket is both SHUT_RD and SHUT_WR, or
* if both the socket and its peer are SHUT_WR.
*
* We don't use SHUT_RD, so we can only encounter this in the latter
* case. In that case there can't be any pending read requests (they
* would have already been completed with a length of zero), the
* above condition ensures that we don't have any pending write
* requests, and nothing that can change about the socket state that
* would complete a pending poll request. */
return -1;
}
if (sock->accept_recv_req) if (sock->accept_recv_req)
{ {
ev |= POLLIN; ev |= POLLIN;
@ -1267,7 +1281,10 @@ static void sock_reselect_async( struct fd *fd, struct async_queue *queue )
struct sock *sock = get_fd_user( fd ); struct sock *sock = get_fd_user( fd );
if (sock->wr_shutdown_pending && list_empty( &sock->write_q.queue )) if (sock->wr_shutdown_pending && list_empty( &sock->write_q.queue ))
{
shutdown( get_unix_fd( sock->fd ), SHUT_WR ); shutdown( get_unix_fd( sock->fd ), SHUT_WR );
sock->wr_shutdown_pending = 0;
}
/* Don't reselect the ifchange queue; we always ask for POLLIN. /* Don't reselect the ifchange queue; we always ask for POLLIN.
* Don't reselect an uninitialized socket; we can't call set_fd_events() on * Don't reselect an uninitialized socket; we can't call set_fd_events() on