From 5db3620f4957bf9c8df166f3e9ab75d8c1835663 Mon Sep 17 00:00:00 2001 From: Benjamin Sergeant Date: Sat, 26 Jan 2019 20:50:25 -0800 Subject: [PATCH 1/5] rebase poll branch --- ixwebsocket/IXSocket.cpp | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/ixwebsocket/IXSocket.cpp b/ixwebsocket/IXSocket.cpp index d456d3d2..7edde77e 100644 --- a/ixwebsocket/IXSocket.cpp +++ b/ixwebsocket/IXSocket.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -37,22 +38,21 @@ namespace ix void Socket::poll(const OnPollCallback& onPollCallback, int timeoutSecs) { - fd_set rfds; - FD_ZERO(&rfds); - FD_SET(_sockfd, &rfds); + if (_sockfd == -1) + { + onPollCallback(PollResultType_Error); + return; + } #ifdef __linux__ FD_SET(_eventfd.getFd(), &rfds); #endif + struct pollfd fds[1]; + fds[0].fd = _sockfd; + fds[0].events = POLLIN | POLLHUP | POLLERR; - struct timeval timeout; - timeout.tv_sec = timeoutSecs; - timeout.tv_usec = 0; - - int sockfd = _sockfd; - int nfds = (std::max)(sockfd, _eventfd.getFd()); - int ret = select(nfds + 1, &rfds, nullptr, nullptr, - (timeoutSecs == kDefaultPollNoTimeout) ? nullptr : &timeout); + int timeout_msecs = timeoutSecs * 1000; + int ret = ::poll(fds, 1, timeout_msecs); PollResultType pollResult = PollResultType_ReadyForRead; if (ret < 0) @@ -65,6 +65,7 @@ namespace ix } onPollCallback(pollResult); + } void Socket::wakeUpFromPoll() @@ -92,6 +93,9 @@ namespace ix if (_sockfd == -1) return; +#if 1 + ::shutdown(_sockfd, SHUT_RDWR); +#endif closeSocket(_sockfd); _sockfd = -1; } From 76c97027c8aab81de0ac1b7e59da65475ad91781 Mon Sep 17 00:00:00 2001 From: Benjamin Sergeant Date: Sat, 26 Jan 2019 20:54:23 -0800 Subject: [PATCH 2/5] remove shutdown call --- ixwebsocket/IXSocket.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/ixwebsocket/IXSocket.cpp b/ixwebsocket/IXSocket.cpp index 7edde77e..7d5a6f0d 100644 --- a/ixwebsocket/IXSocket.cpp +++ b/ixwebsocket/IXSocket.cpp @@ -93,9 +93,6 @@ namespace ix if (_sockfd == -1) return; -#if 1 - ::shutdown(_sockfd, SHUT_RDWR); -#endif closeSocket(_sockfd); _sockfd = -1; } From b9c49c38ed080d4025a8dcb3bccf9ba8523511f2 Mon Sep 17 00:00:00 2001 From: Benjamin Sergeant Date: Sat, 26 Jan 2019 20:57:48 -0800 Subject: [PATCH 3/5] linux fix --- .travis.yml | 2 +- ixwebsocket/IXSocket.cpp | 14 ++++++++++---- test/run.py | 2 +- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index ec96d822..4dfb451e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,5 +5,5 @@ compiler: - clang # - gcc -os: osx + # os: osx script: make test diff --git a/ixwebsocket/IXSocket.cpp b/ixwebsocket/IXSocket.cpp index 7d5a6f0d..42854e05 100644 --- a/ixwebsocket/IXSocket.cpp +++ b/ixwebsocket/IXSocket.cpp @@ -45,14 +45,20 @@ namespace ix } #ifdef __linux__ - FD_SET(_eventfd.getFd(), &rfds); + int nfds = 2; +#else + int nfds = 1; #endif - struct pollfd fds[1]; + + struct pollfd fds[nfds]; fds[0].fd = _sockfd; fds[0].events = POLLIN | POLLHUP | POLLERR; - int timeout_msecs = timeoutSecs * 1000; - int ret = ::poll(fds, 1, timeout_msecs); +#ifdef __linux__ + fds[1].fd = _eventfd.getFd(); + fds[1].events = POLLIN | POLLHUP | POLLERR; +#endif + int ret = ::poll(fds, nfds, timeoutSecs * 1000); PollResultType pollResult = PollResultType_ReadyForRead; if (ret < 0) diff --git a/test/run.py b/test/run.py index 3cee95bd..49586b1f 100644 --- a/test/run.py +++ b/test/run.py @@ -30,7 +30,7 @@ sanitizersFlags = { } sanitizer = 'tsan' if osName == 'Linux': - sanitizer = 'asan' + sanitizer = 'none' sanitizerFlags = sanitizersFlags[sanitizer] From 58921592c88faa3ddbd41c5fdf146a613cbebcdb Mon Sep 17 00:00:00 2001 From: Benjamin Sergeant Date: Sat, 26 Jan 2019 21:01:36 -0800 Subject: [PATCH 4/5] constexpr to declare number of fds --- ixwebsocket/IXSocket.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ixwebsocket/IXSocket.cpp b/ixwebsocket/IXSocket.cpp index 42854e05..1b676905 100644 --- a/ixwebsocket/IXSocket.cpp +++ b/ixwebsocket/IXSocket.cpp @@ -45,9 +45,9 @@ namespace ix } #ifdef __linux__ - int nfds = 2; + constexpr int nfds = 2; #else - int nfds = 1; + constexpr int nfds = 1; #endif struct pollfd fds[nfds]; From 907605c59ca06f3963d296b833b26f812428d105 Mon Sep 17 00:00:00 2001 From: Benjamin Sergeant Date: Sun, 27 Jan 2019 10:46:02 -0800 Subject: [PATCH 5/5] windows build fix --- ixwebsocket/IXSocket.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ixwebsocket/IXSocket.cpp b/ixwebsocket/IXSocket.cpp index 1b676905..40fb0b31 100644 --- a/ixwebsocket/IXSocket.cpp +++ b/ixwebsocket/IXSocket.cpp @@ -52,11 +52,11 @@ namespace ix struct pollfd fds[nfds]; fds[0].fd = _sockfd; - fds[0].events = POLLIN | POLLHUP | POLLERR; + fds[0].events = POLLIN; #ifdef __linux__ fds[1].fd = _eventfd.getFd(); - fds[1].events = POLLIN | POLLHUP | POLLERR; + fds[1].events = POLLIN; #endif int ret = ::poll(fds, nfds, timeoutSecs * 1000);