From 3fa0e4e15bb2c5bcbfee4b73f6d3cce3b00b3000 Mon Sep 17 00:00:00 2001 From: Determinant Date: Fri, 21 Feb 2020 17:24:32 +0000 Subject: seemingly fix the uv_close assertion failure; reduce LOG_INFO messages --- include/salticidae/network.h | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) (limited to 'include/salticidae/network.h') diff --git a/include/salticidae/network.h b/include/salticidae/network.h index c581aa4..1cfe150 100644 --- a/include/salticidae/network.h +++ b/include/salticidae/network.h @@ -79,6 +79,7 @@ class MsgNetwork: public ConnPool { Msg msg; MsgState msg_state; bool msg_sleep; + /* initialized and destroyed by the worker */ TimerEvent ev_enqueue_poll; protected: @@ -88,6 +89,10 @@ class MsgNetwork: public ConnPool { mutable std::atomic nsentb; mutable std::atomic nrecvb; #endif + void stop() override { + ev_enqueue_poll.clear(); + ConnPool::Conn::stop(); + } public: Conn(): msg_state(HEADER), msg_sleep(false) @@ -135,24 +140,22 @@ class MsgNetwork: public ConnPool { void on_setup(const ConnPool::conn_t &_conn) override { auto conn = static_pointer_cast(_conn); - conn->ev_enqueue_poll = TimerEvent(conn->worker->get_ec(), - [this, conn](TimerEvent &) { - if (!incoming_msgs.enqueue(std::make_pair(conn->msg, conn), false)) - { - conn->msg_sleep = true; - conn->ev_enqueue_poll.add(0); - return; - } - conn->msg_sleep = false; - on_read(conn); + auto worker = conn->worker; + worker->get_tcall()->async_call([this, conn, worker](ThreadCall::Handle &) { + conn->ev_enqueue_poll = TimerEvent(worker->get_ec(), + [this, conn](TimerEvent &) { + if (!incoming_msgs.enqueue(std::make_pair(conn->msg, conn), false)) + { + conn->msg_sleep = true; + conn->ev_enqueue_poll.add(0); + return; + } + conn->msg_sleep = false; + on_read(conn); + }); }); } - void on_teardown(const ConnPool::conn_t &_conn) override { - auto conn = static_pointer_cast(_conn); - conn->ev_enqueue_poll.clear(); - } - public: class Config: public ConnPool::Config { @@ -355,6 +358,7 @@ class PeerNetwork: public MsgNetwork { class Conn: public MsgNet::Conn { friend PeerNetwork; Peer *peer; + /* initialized and destroyed by the worker */ TimerEvent ev_timeout; void reset_timeout(double timeout); -- cgit v1.2.3