Skip to content
This repository has been archived by the owner on Mar 3, 2020. It is now read-only.

Commit

Permalink
couple things that might help
Browse files Browse the repository at this point in the history
  • Loading branch information
isabelsavannah committed Mar 14, 2019
1 parent 06f7b30 commit cbfcb20
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
26 changes: 22 additions & 4 deletions node/session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <node/session.hpp>
#include <node/node.hpp>
#include <sstream>
#include <boost/beast/websocket/error.hpp>


using namespace bzn;
Expand Down Expand Up @@ -64,13 +65,17 @@ session::start_idle_timeout()
return;
}

self->start_idle_timeout();
if (!self->closing)
{
self->start_idle_timeout();
}
}));
}

void
session::open(std::shared_ptr<bzn::beast::websocket_base> ws_factory)
{
this->opened_session = true;
this->strand->wrap([self = shared_from_this(), ws_factory]()
{
self->record("open");
Expand Down Expand Up @@ -120,6 +125,7 @@ session::open(std::shared_ptr<bzn::beast::websocket_base> ws_factory)
void
session::accept(std::shared_ptr<bzn::beast::websocket_stream_base> ws)
{
this->accepted_session = true;
this->strand->wrap([self = shared_from_this(), ws]()
{
self->record("accept");
Expand Down Expand Up @@ -170,7 +176,7 @@ session::do_read()

auto buffer = std::make_shared<boost::beast::multi_buffer>();

if (this->reading || !this->is_open())
if (this->reading || !this->is_open() || this->closing)
{
this->record("do read skipped");
return;
Expand All @@ -182,6 +188,10 @@ session::do_read()
this->strand->wrap([self = shared_from_this(), buffer](boost::system::error_code ec, auto /*bytes_transferred*/)
{
self->record("do read callback");
if (self->opened_session)
{
LOG(debug) << "why are we reading from a session we opened?";
}
self->activity = true;

if(ec)
Expand All @@ -193,7 +203,10 @@ session::do_read()
self->record("do read callback failed because other than close");
LOG(error) << "websocket read failed: " << ec.message();
}
self->private_close();
if (ec != boost::beast::websocket::error::closed)
{
self->private_close();
}
return;
}

Expand Down Expand Up @@ -260,7 +273,10 @@ session::do_write()
}

self->write_queue.push_front(msg);
self->private_close();
if (ec != boost::beast::websocket::error::closed)
{
self->private_close();
}
return;
}

Expand Down Expand Up @@ -345,6 +361,8 @@ session::private_close()
}
}));
}

this->idle_timer->cancel();
}

bool
Expand Down
4 changes: 4 additions & 0 deletions node/session.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ namespace bzn
std::list<std::string> event_log;
void record(std::string event);

bool opened_session = false;
bool accepted_session = false;



};

Expand Down

0 comments on commit cbfcb20

Please sign in to comment.