delete connection;
}
- if (eventBase_) {
+ if (eventBase_ && ownEventBase_) {
event_base_free(eventBase_);
}
/**
* 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",
}
// 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) {
/// The event base for libevent
event_base* eventBase_;
+ bool ownEventBase_;
/// Event struct, used with eventBase_ for connection events
struct event serverEvent_;
port_(port),
threadPoolProcessing_(false),
eventBase_(NULL),
+ ownEventBase_(false),
numTConnections_(0),
numActiveProcessors_(0),
connectionStackLimit_(CONNECTION_STACK_LIMIT),
port_(port),
threadManager_(threadManager),
eventBase_(NULL),
+ ownEventBase_(false),
numTConnections_(0),
numActiveProcessors_(0),
connectionStackLimit_(CONNECTION_STACK_LIMIT),
port_(port),
threadManager_(threadManager),
eventBase_(NULL),
+ ownEventBase_(false),
numTConnections_(0),
numActiveProcessors_(0),
connectionStackLimit_(CONNECTION_STACK_LIMIT),
* 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