summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoger Meier <roger@apache.org>2011-08-02 23:37:36 +0000
committerRoger Meier <roger@apache.org>2011-08-02 23:37:36 +0000
commitc1905587872fe7a78adcc9d8c6d0c091ac7b80cc (patch)
tree247898781e87385acb9f6fbe034ca9a89d330397
parentb342ddf00b9abc318c1075a8942928f1ef324f7f (diff)
downloadthrift-c1905587872fe7a78adcc9d8c6d0c091ac7b80cc.tar.gz
THRIFT-1184 event_base memory freeing by class TNonblockingServer
adds option to use existing event base Patch: Pavlin Radoslavov git-svn-id: https://svn.apache.org/repos/asf/thrift/trunk@1153307 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--lib/cpp/src/server/TNonblockingServer.cpp7
-rw-r--r--lib/cpp/src/server/TNonblockingServer.h8
2 files changed, 11 insertions, 4 deletions
diff --git a/lib/cpp/src/server/TNonblockingServer.cpp b/lib/cpp/src/server/TNonblockingServer.cpp
index 4774b361c..89e9afd78 100644
--- a/lib/cpp/src/server/TNonblockingServer.cpp
+++ b/lib/cpp/src/server/TNonblockingServer.cpp
@@ -567,7 +567,7 @@ TNonblockingServer::~TNonblockingServer() {
delete connection;
}
- if (eventBase_) {
+ if (eventBase_ && ownEventBase_) {
event_base_free(eventBase_);
}
@@ -802,10 +802,11 @@ void TNonblockingServer::createNotificationPipe() {
/**
* Register the core libevent events onto the proper base.
*/
-void TNonblockingServer::registerEvents(event_base* base) {
+void TNonblockingServer::registerEvents(event_base* base, bool ownEventBase) {
assert(serverSocket_ != -1);
assert(!eventBase_);
eventBase_ = base;
+ ownEventBase_ = ownEventBase;
// Print some libevent stats
GlobalOutput.printf("libevent %s method %s",
@@ -911,7 +912,7 @@ void TNonblockingServer::serve() {
}
// Initialize libevent core
- registerEvents(static_cast<event_base*>(event_init()));
+ registerEvents(static_cast<event_base*>(event_init()), true);
// Run the preServe event
if (eventHandler_ != NULL) {
diff --git a/lib/cpp/src/server/TNonblockingServer.h b/lib/cpp/src/server/TNonblockingServer.h
index 7b1cf4dd8..31741e40a 100644
--- a/lib/cpp/src/server/TNonblockingServer.h
+++ b/lib/cpp/src/server/TNonblockingServer.h
@@ -132,6 +132,7 @@ class TNonblockingServer : public TServer {
/// The event base for libevent
event_base* eventBase_;
+ bool ownEventBase_;
/// Event struct, used with eventBase_ for connection events
struct event serverEvent_;
@@ -234,6 +235,7 @@ class TNonblockingServer : public TServer {
port_(port),
threadPoolProcessing_(false),
eventBase_(NULL),
+ ownEventBase_(false),
numTConnections_(0),
numActiveProcessors_(0),
connectionStackLimit_(CONNECTION_STACK_LIMIT),
@@ -259,6 +261,7 @@ class TNonblockingServer : public TServer {
port_(port),
threadManager_(threadManager),
eventBase_(NULL),
+ ownEventBase_(false),
numTConnections_(0),
numActiveProcessors_(0),
connectionStackLimit_(CONNECTION_STACK_LIMIT),
@@ -293,6 +296,7 @@ class TNonblockingServer : public TServer {
port_(port),
threadManager_(threadManager),
eventBase_(NULL),
+ ownEventBase_(false),
numTConnections_(0),
numActiveProcessors_(0),
connectionStackLimit_(CONNECTION_STACK_LIMIT),
@@ -704,8 +708,10 @@ class TNonblockingServer : public TServer {
* Register the core libevent events onto the proper base.
*
* @param base pointer to the event base to be initialized.
+ * @param ownEventBase if true, this server is responsible for
+ * freeing the event base memory.
*/
- void registerEvents(event_base* base);
+ void registerEvents(event_base* base, bool ownEventBase = true);
/**
* Main workhorse function, starts up the server listening on a port and