diff options
author | Determinant <ted.sybil@gmail.com> | 2018-11-14 23:14:32 -0500 |
---|---|---|
committer | Determinant <ted.sybil@gmail.com> | 2018-11-14 23:14:32 -0500 |
commit | 5f88ebb43acc7b7fa3ac272a444677dd72ccb63d (patch) | |
tree | c0075433e52d923609a7587bd25a66e1bcf78867 /include/salticidae/conn.h | |
parent | ecc163f98e434b557768560d00ee2f9755d6d950 (diff) |
fix bugs in `terminate`
Diffstat (limited to 'include/salticidae/conn.h')
-rw-r--r-- | include/salticidae/conn.h | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/include/salticidae/conn.h b/include/salticidae/conn.h index 73b3022..480809f 100644 --- a/include/salticidae/conn.h +++ b/include/salticidae/conn.h @@ -123,12 +123,11 @@ class ConnPool { protected: /** Close the IO and clear all on-going or planned events. */ virtual void stop() { - if (fd == -1) return; + if (!self_ref) return; ev_connect.clear(); ev_socket.clear(); send_buffer.get_queue().unreg_handler(); ::close(fd); - fd = -1; self_ref = nullptr; /* remove the self-cycle */ } @@ -189,7 +188,7 @@ class ConnPool { .get_queue() .reg_handler(this->ec, [conn, client_fd] (MPSCWriteBuffer::queue_t &) { - if (conn->ready_send && conn->fd != -1) + if (conn->ready_send && conn->self_ref) { conn->ev_socket.del(); conn->ev_socket.add(Event::READ | Event::WRITE); @@ -340,9 +339,13 @@ class ConnPool { void terminate(const conn_t &conn, bool blocking = true) { int fd = conn->fd; - conn->worker->get_tcall()->call([conn](ThreadCall::Handle &) { + auto worker = conn->worker; + if (worker) + worker->get_tcall()->call([conn](ThreadCall::Handle &) { + conn->stop(); + }, blocking); + else conn->stop(); - }, blocking); remove_conn(fd); } }; |