aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorDeterminant <[email protected]>2018-11-14 23:14:32 -0500
committerDeterminant <[email protected]>2018-11-14 23:14:32 -0500
commit5f88ebb43acc7b7fa3ac272a444677dd72ccb63d (patch)
treec0075433e52d923609a7587bd25a66e1bcf78867 /include
parentecc163f98e434b557768560d00ee2f9755d6d950 (diff)
fix bugs in `terminate`
Diffstat (limited to 'include')
-rw-r--r--include/salticidae/conn.h13
-rw-r--r--include/salticidae/event.h2
-rw-r--r--include/salticidae/network.h10
3 files changed, 13 insertions, 12 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);
}
};
diff --git a/include/salticidae/event.h b/include/salticidae/event.h
index 616f598..3fd11b6 100644
--- a/include/salticidae/event.h
+++ b/include/salticidae/event.h
@@ -85,7 +85,7 @@ class Event {
static inline void fd_then(uv_poll_t *h, int status, int events) {
if (status != 0)
{
- SALTICIDAE_LOG_WARN("%s", uv_strerror(status));
+ //SALTICIDAE_LOG_WARN("%s", uv_strerror(status));
return;
}
auto event = static_cast<Event *>(h->data);
diff --git a/include/salticidae/network.h b/include/salticidae/network.h
index a63976b..60d8f20 100644
--- a/include/salticidae/network.h
+++ b/include/salticidae/network.h
@@ -405,7 +405,7 @@ void MsgNetwork<OpcodeType>::Conn::on_read() {
ConnPool::Conn::on_read();
auto &recv_buffer = this->recv_buffer;
auto mn = get_net();
- while (fd != -1)
+ while (self_ref)
{
if (msg_state == Conn::HEADER)
{
@@ -472,11 +472,6 @@ void PeerNetwork<O, _, __>::Conn::on_setup() {
SALTICIDAE_LOG_INFO("peer ping-pong timeout");
conn->terminate();
});
- if (this->get_mode() == Conn::ConnMode::ACTIVE)
- {
- peer_id = this->get_addr();
- if (pn->id_mode == IP_BASED) peer_id.port = 0;
- }
/* the initial ping-pong to set up the connection */
tcall_reset_timeout(worker, conn, pn->conn_timeout);
pn->send_msg(MsgPing(pn->listen_port), *conn);
@@ -584,6 +579,9 @@ void PeerNetwork<O, _, __>::start_active_conn(const NetAddr &addr) {
auto conn = static_pointer_cast<Conn>(MsgNet::_connect(addr));
assert(p->conn == nullptr);
p->conn = conn;
+ conn->peer_id = addr;
+ if (id_mode == IP_BASED)
+ conn->peer_id.port = 0;
}
/* end: functions invoked by the dispatcher */