[PATCH 3/6] server: Remove the socket from the polling loop if both it and the peer have SHUT_WR.
zfigura at codeweavers.com
Sat Jul 24 18:54:29 CDT 2021
Based on a patch by Torge Matthies.
Signed-off-by: Zebediah Figura <zfigura at codeweavers.com>
server/sock.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/server/sock.c b/server/sock.c
index 85ea019ad92..2d2aa733565 100644
@@ -1161,6 +1161,20 @@ static int sock_get_poll_events( struct fd *fd )
+ 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;
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 );
if (sock->wr_shutdown_pending && list_empty( &sock->write_q.queue ))
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 an uninitialized socket; we can't call set_fd_events() on
More information about the wine-devel