From b9d5d04feaa211b6812a84de0f78bf8acdae25b8 Mon Sep 17 00:00:00 2001 From: Aman Gupta Date: Thu, 27 Sep 2018 16:23:45 -0700 Subject: [PATCH] ensure that errno is set correctly after hdhomerun_sock_connect --- hdhomerun_sock_posix.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/hdhomerun_sock_posix.c b/hdhomerun_sock_posix.c index d71acf0..18faab1 100644 --- a/hdhomerun_sock_posix.c +++ b/hdhomerun_sock_posix.c @@ -332,12 +332,18 @@ bool hdhomerun_sock_connect(struct hdhomerun_sock_t *sock, uint32_t remote_addr, poll_event.events = POLLOUT; poll_event.revents = 0; - if (poll(&poll_event, 1, (int)timeout) <= 0) { + int ret = poll(&poll_event, 1, (int)timeout); + if (ret < 0) { + return false; + } else if (ret == 0) { + errno = ETIMEDOUT; return false; } - if ((poll_event.revents & POLLOUT) == 0) { - return false; + if (connect(sock->sock, (struct sockaddr *)&sock_addr, sizeof(sock_addr)) != 0) { + if (errno != EISCONN) { + return false; + } } return true;