Commit 7d8ffe52 authored by Benoit Eudier's avatar Benoit Eudier

Do not use pointer to create the reactor

Reactor is not shared. It is owned by listener, create in its
constructor and is not shared with anybody, so created in listener's
destructor. Here a unique_ptr would do the trick but not using a ptr
works fine and remove complexity a bit.
parent aa3f46db
......@@ -80,7 +80,7 @@ private:
std::shared_ptr<Transport> transport_;
std::shared_ptr<Handler> handler_;
std::shared_ptr<Aio::Reactor> reactor_;
Aio::Reactor reactor_;
Aio::Reactor::Key transportKey;
void handleNewConnection();
......
......@@ -81,7 +81,7 @@ Listener::Listener()
, poller()
, options_()
, workers_(Const::DefaultWorkers)
, reactor_(Aio::Reactor::create())
, reactor_()
, transportKey()
{ }
......@@ -93,7 +93,7 @@ Listener::Listener(const Address& address)
, poller()
, options_()
, workers_(Const::DefaultWorkers)
, reactor_(Aio::Reactor::create())
, reactor_()
, transportKey()
{
}
......@@ -201,8 +201,8 @@ Listener::bind(const Address& address) {
transport_.reset(new Transport(handler_));
reactor_->init(Aio::AsyncContext(workers_));
transportKey = reactor_->addHandler(transport_);
reactor_.init(Aio::AsyncContext(workers_));
transportKey = reactor_.addHandler(transport_);
return true;
}
......@@ -214,7 +214,7 @@ Listener::isBound() const {
void
Listener::run() {
reactor_->run();
reactor_.run();
for (;;) {
std::vector<Polling::Event> events;
......@@ -249,12 +249,12 @@ Listener::runThreaded() {
void
Listener::shutdown() {
if (shutdownFd.isBound()) shutdownFd.notify();
reactor_->shutdown();
reactor_.shutdown();
}
Async::Promise<Listener::Load>
Listener::requestLoad(const Listener::Load& old) {
auto handlers = reactor_->handlers(transportKey);
auto handlers = reactor_.handlers(transportKey);
std::vector<Async::Promise<rusage>> loads;
for (const auto& handler: handlers) {
......@@ -332,7 +332,7 @@ Listener::handleNewConnection() {
void
Listener::dispatchPeer(const std::shared_ptr<Peer>& peer) {
auto handlers = reactor_->handlers(transportKey);
auto handlers = reactor_.handlers(transportKey);
auto idx = peer->fd() % handlers.size();
auto transport = std::static_pointer_cast<Transport>(handlers[idx]);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment