Repository: thrift Updated Branches: refs/heads/master 9226590dc -> b5ebcd199
THRIFT-3080: use select() instead poll() for early windows compatibility. Project: http://git-wip-us.apache.org/repos/asf/thrift/repo Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/b5ebcd19 Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/b5ebcd19 Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/b5ebcd19 Branch: refs/heads/master Commit: b5ebcd199c1b603cea652847bfc9177c60fb8e28 Parents: 38772c9 Author: Lei Feiwei <[email protected]> Authored: Sat Apr 4 22:12:07 2015 +0800 Committer: Roger Meier <[email protected]> Committed: Tue Apr 7 22:38:25 2015 +0200 ---------------------------------------------------------------------- .../src/thrift/server/TNonblockingServer.cpp | 22 +++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/thrift/blob/b5ebcd19/lib/cpp/src/thrift/server/TNonblockingServer.cpp ---------------------------------------------------------------------- diff --git a/lib/cpp/src/thrift/server/TNonblockingServer.cpp b/lib/cpp/src/thrift/server/TNonblockingServer.cpp index 31bc34b..8590bff 100644 --- a/lib/cpp/src/thrift/server/TNonblockingServer.cpp +++ b/lib/cpp/src/thrift/server/TNonblockingServer.cpp @@ -28,7 +28,10 @@ #include <thrift/transport/PlatformSocket.h> #include <iostream> -#include <poll.h> + +#ifdef HAVE_SYS_SELECT_H +#include <sys/select.h> +#endif #ifdef HAVE_SYS_SOCKET_H #include <sys/socket.h> @@ -1394,33 +1397,36 @@ bool TNonblockingIOThread::notify(TNonblockingServer::TConnection* conn) { return false; } + fd_set wfds, efds; int ret = -1; - struct pollfd pfd = {fd, POLLOUT, 0}; int kSize = sizeof(conn); const char * pos = (const char *)const_cast_sockopt(&conn); while (kSize > 0) { - pfd.revents = 0; - ret = poll(&pfd, 1, -1); + FD_ZERO(&wfds); + FD_ZERO(&efds); + FD_SET(fd, &wfds); + FD_SET(fd, &efds); + ret = select(fd + 1, NULL, &wfds, &efds, NULL); if (ret < 0) { return false; } else if (ret == 0) { continue; } - if (pfd.revents & POLLHUP || pfd.revents & POLLERR) { - ::close(fd); + if (FD_ISSET(fd, &efds)) { + ::THRIFT_CLOSESOCKET(fd); return false; } - if (pfd.revents & POLLOUT) { + if (FD_ISSET(fd, &wfds)) { ret = send(fd, pos, kSize, 0); if (ret < 0) { if (errno == EAGAIN) { continue; } - ::close(fd); + ::THRIFT_CLOSESOCKET(fd); return false; }
