From 6ddf620a21cafa4e82e7267cc1605c29126d6bbe Mon Sep 17 00:00:00 2001 From: Karl Heyes Date: Mon, 6 Jul 2009 14:28:16 +0000 Subject: [PATCH] bug+fix reported on icecast-dev (Petr Pisar, 06/07/2009). poll implementation of sock_connected had incorrect return in failure case. svn path=/icecast/trunk/net/; revision=16209 --- net/sock.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/net/sock.c b/net/sock.c index 6044931..beb5302 100644 --- a/net/sock.c +++ b/net/sock.c @@ -516,17 +516,27 @@ int sock_read_line(sock_t sock, char *buff, const int len) int sock_connected (sock_t sock, int timeout) { struct pollfd check; + int val = SOCK_ERROR; + socklen_t size = sizeof val; check.fd = sock; check.events = POLLOUT; switch (poll (&check, 1, timeout*1000)) { case 0: return SOCK_TIMEOUT; + default: + /* on windows getsockopt.val is defined as char* */ + if (getsockopt(sock, SOL_SOCKET, SO_ERROR, (void*) &val, &size) == 0) + { + if (val == 0) + return 1; + sock_set_error (val); + } + /* fall through */ case -1: if (sock_recoverable (sock_error())) return 0; return SOCK_ERROR; - default: return 1; } }