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
diff --git a/lib/cpp/src/server/TNonblockingServer.cpp b/lib/cpp/src/server/TNonblockingServer.cpp
index ed1001f..b817260 100644
--- a/lib/cpp/src/server/TNonblockingServer.cpp
+++ b/lib/cpp/src/server/TNonblockingServer.cpp
@@ -244,7 +244,7 @@
* @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 @@
*
* @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 @@
*/
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 e4e0e64..5cda2c5 100644
--- a/lib/cpp/src/server/TNonblockingServer.h
+++ b/lib/cpp/src/server/TNonblockingServer.h
@@ -30,7 +30,9 @@
#include <string>
#include <errno.h>
#include <cstdlib>
+#ifdef HAVE_UNISTD_H
#include <unistd.h>
+#endif
#include <event.h>
namespace apache { namespace thrift { namespace server {
@@ -663,7 +665,7 @@
*
* @return write fd for pipe.
*/
- int getNotificationSendFD() const {
+ evutil_socket_t getNotificationSendFD() const {
return notificationPipeFDs_[1];
}
@@ -672,7 +674,7 @@
*
* @return read fd of pipe.
*/
- int getNotificationRecvFD() const {
+ evutil_socket_t getNotificationRecvFD() const {
return notificationPipeFDs_[0];
}