Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions source/common/event/dispatcher_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,18 @@ namespace Envoy {
namespace Event {

DispatcherImpl::DispatcherImpl()
: DispatcherImpl(Buffer::WatermarkFactoryPtr{new Buffer::WatermarkBufferFactory}) {}
: DispatcherImpl(Buffer::WatermarkFactoryPtr{new Buffer::WatermarkBufferFactory}) {
// The dispatcher won't work as expected if libevent hasn't been configured to use threads.
RELEASE_ASSERT(Libevent::Global::initialized());
}

DispatcherImpl::DispatcherImpl(Buffer::WatermarkFactoryPtr&& factory)
: buffer_factory_(std::move(factory)), base_(event_base_new()),
deferred_delete_timer_(createTimer([this]() -> void { clearDeferredDeleteList(); })),
post_timer_(createTimer([this]() -> void { runPostCallbacks(); })),
current_to_delete_(&to_delete_1_) {}
current_to_delete_(&to_delete_1_) {
RELEASE_ASSERT(Libevent::Global::initialized());
}

DispatcherImpl::~DispatcherImpl() {}

Expand Down
3 changes: 3 additions & 0 deletions source/common/event/libevent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ namespace Envoy {
namespace Event {
namespace Libevent {

bool Global::initialized_ = false;

void Global::initialize() {
evthread_use_pthreads();

// Ignore SIGPIPE and allow errors to propagate through error codes.
signal(SIGPIPE, SIG_IGN);
initialized_ = true;
}

} // namespace Libevent
Expand Down
6 changes: 6 additions & 0 deletions source/common/event/libevent.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,16 @@ namespace Libevent {
*/
class Global {
public:
static bool initialized() { return initialized_; }

/**
* Initialize the library globally.
*/
static void initialize();

private:
// True if initialized() has been called.
static bool initialized_;
};

typedef CSmartPtr<event_base, event_base_free> BasePtr;
Expand Down
2 changes: 2 additions & 0 deletions test/integration/integration.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "common/buffer/buffer_impl.h"
#include "common/common/assert.h"
#include "common/event/dispatcher_impl.h"
#include "common/event/libevent.h"
#include "common/network/connection_impl.h"
#include "common/network/utility.h"
#include "common/upstream/upstream_impl.h"
Expand Down Expand Up @@ -199,6 +200,7 @@ Network::ClientConnectionPtr BaseIntegrationTest::makeClientConnection(uint32_t

void BaseIntegrationTest::initialize() {
RELEASE_ASSERT(!initialized_);
RELEASE_ASSERT(Event::Libevent::Global::initialized());
initialized_ = true;

createUpstreams();
Expand Down