From 266b1737a5ce7ecdafdf5274f66bd46315f7dfde Mon Sep 17 00:00:00 2001 From: Bryan Duxbury Date: Thu, 1 Sep 2011 16:50:28 +0000 Subject: [PATCH] THRIFT-1305. cpp: make TConnection a private inner class of TNonblockingServer The previous patch reverted some elements of THRIFT-1217. Fixed. Patch: Alexandre Parenteau git-svn-id: https://svn.apache.org/repos/asf/thrift/trunk@1164161 13f79535-47bb-0310-9956-ffa450edef68 --- lib/cpp/src/server/TNonblockingServer.cpp | 10 +++++----- lib/cpp/src/server/TNonblockingServer.h | 6 ++++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/cpp/src/server/TNonblockingServer.cpp b/lib/cpp/src/server/TNonblockingServer.cpp index ed1001ff..b817260f 100644 --- a/lib/cpp/src/server/TNonblockingServer.cpp +++ b/lib/cpp/src/server/TNonblockingServer.cpp @@ -244,7 +244,7 @@ class TNonblockingServer::TConnection { * @param which the flags associated with the event. * @param v void* callback arg where we placed TConnection's "this". */ - static void eventHandler(int fd, short /* which */, void* v) { + static void eventHandler(evutil_socket_t fd, short /* which */, void* v) { assert(fd == ((TConnection*)v)->getTSocket()->getSocketFD()); ((TConnection*)v)->workSocket(); } @@ -257,10 +257,10 @@ class TNonblockingServer::TConnection { * * @param fd the descriptor the event occurred on. */ - static void taskHandler(int fd, short /* which */, void* /* v */) { + static void taskHandler(evutil_socket_t fd, short /* which */, void* /* v */) { TConnection* connection; ssize_t nBytes; - while ((nBytes = read(fd, (void*)&connection, sizeof(TConnection*))) + while ((nBytes = recv(fd, cast_sockopt(&connection), sizeof(TConnection*), 0)) == sizeof(TConnection*)) { connection->transition(); } @@ -281,8 +281,8 @@ class TNonblockingServer::TConnection { */ bool notifyServer() { TConnection* connection = this; - if (write(server_->getNotificationSendFD(), (const void*)&connection, - sizeof(TConnection*)) != sizeof(TConnection*)) { + if (send(server_->getNotificationSendFD(), const_cast_sockopt(&connection), + sizeof(TConnection*), 0) != sizeof(TConnection*)) { return false; } diff --git a/lib/cpp/src/server/TNonblockingServer.h b/lib/cpp/src/server/TNonblockingServer.h index e4e0e648..5cda2c53 100644 --- a/lib/cpp/src/server/TNonblockingServer.h +++ b/lib/cpp/src/server/TNonblockingServer.h @@ -30,7 +30,9 @@ #include #include #include +#ifdef HAVE_UNISTD_H #include +#endif #include namespace apache { namespace thrift { namespace server { @@ -663,7 +665,7 @@ class TNonblockingServer : public TServer { * * @return write fd for pipe. */ - int getNotificationSendFD() const { + evutil_socket_t getNotificationSendFD() const { return notificationPipeFDs_[1]; } @@ -672,7 +674,7 @@ class TNonblockingServer : public TServer { * * @return read fd of pipe. */ - int getNotificationRecvFD() const { + evutil_socket_t getNotificationRecvFD() const { return notificationPipeFDs_[0]; } -- 2.17.1