From 8badc83b0516a94f513e3b375c4e61d63cce4ee2 Mon Sep 17 00:00:00 2001 From: john30 Date: Wed, 4 Apr 2018 17:51:13 +0200 Subject: [PATCH] watch sockets for error as well in connect --- src/lib/utils/tcpsocket.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/lib/utils/tcpsocket.cpp b/src/lib/utils/tcpsocket.cpp index f9bf01cc..ac78e737 100755 --- a/src/lib/utils/tcpsocket.cpp +++ b/src/lib/utils/tcpsocket.cpp @@ -98,11 +98,19 @@ TCPSocket* TCPClient::connect(const string& server, const uint16_t& port, int ti fds[0].fd = sfd; fds[0].events = POLLIN|POLLOUT; ret = ppoll(fds, nfds, &tdiff, NULL); + if (ret >= 1 && fds[0].revents & POLLERR) { + ret = -1; + } #else - fd_set readfds, writefds; + fd_set readfds, writefds, exceptfds; FD_ZERO(&readfds); + FD_ZERO(&writefds); + FD_ZERO(&exceptfds); FD_SET(sfd, &readfds); - ret = pselect(sfd + 1, &readfds, &writefds, NULL, &tdiff, NULL); + ret = pselect(sfd + 1, &readfds, &writefds, &errfds , &tdiff, NULL); + if (ret >= 1 && FD_ISSET(sfd, &exceptfds)) { + ret = -1; + } #endif if (ret == -1 || ret == 0) { close(sfd);