From 55165a1ae3e9ded0a644200b66dfc26d14339f65 Mon Sep 17 00:00:00 2001 From: Marc Hoersken Date: Wed, 15 Jul 2020 20:53:21 +0200 Subject: [PATCH] Cygwin: make sure failed sockets always signal writability Since FD_CONNECT is only given once, we manually need to set FD_WRITE for connection failed sockets to have consistent behaviour in programs calling poll/select multiple times. Example test to non-listening port: curl -v 127.0.0.1:47 --- winsup/cygwin/fhandler_socket_inet.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/winsup/cygwin/fhandler_socket_inet.cc b/winsup/cygwin/fhandler_socket_inet.cc index 74c415d60..e5b0d2d14 100644 --- a/winsup/cygwin/fhandler_socket_inet.cc +++ b/winsup/cygwin/fhandler_socket_inet.cc @@ -376,6 +376,12 @@ fhandler_socket_wsock::evaluate_events (const long event_mask, long &events, if (erase) wsock_events->events &= ~(events & ~(FD_WRITE | FD_CLOSE)); } + /* Since FD_CONNECT is only given once, we manually need to set + FD_WRITE for connection failed sockets to have consistent + behaviour in programs calling poll/select multiple times. + Example test to non-listening port: curl -v 127.0.0.1:47 */ + if ((connect_state () == connect_failed) && (event_mask & FD_WRITE)) + wsock_events->events |= FD_WRITE; UNLOCK_EVENTS; return ret;