diff options
author | Determinant <[email protected]> | 2018-11-19 00:54:56 -0500 |
---|---|---|
committer | Determinant <[email protected]> | 2018-11-19 00:54:56 -0500 |
commit | 4fdac38ad5796cae03f827670655efd79d953699 (patch) | |
tree | b20baed058ce71b7498b7b2a21575b18b0b84efb /src/conn.cpp | |
parent | 35ffa2c1e5c7fba06c52e2c20aff2aac910921d5 (diff) |
fix bug in remove_conn
Diffstat (limited to 'src/conn.cpp')
-rw-r--r-- | src/conn.cpp | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/src/conn.cpp b/src/conn.cpp index 413a582..b131684 100644 --- a/src/conn.cpp +++ b/src/conn.cpp @@ -145,26 +145,26 @@ void ConnPool::Conn::stop() { } void ConnPool::Conn::worker_terminate() { + auto conn = self(); + if (!conn) return; stop(); if (!worker->is_dispatcher()) cpool->disp_tcall->async_call( - [cpool=this->cpool, fd=this->fd](ThreadCall::Handle &) { - cpool->remove_conn(fd); + [cpool=this->cpool, conn](ThreadCall::Handle &) { + cpool->del_conn(conn); }); - else cpool->remove_conn(fd); + else cpool->del_conn(conn); } void ConnPool::Conn::disp_terminate() { + auto conn = self(); + if (!conn) return; if (worker && !worker->is_dispatcher()) - { - auto conn = self(); - if (conn) - worker->get_tcall()->call([conn](ThreadCall::Handle &) { - conn->stop(); - }); - } + worker->get_tcall()->call([conn](ThreadCall::Handle &) { + conn->stop(); + }); else stop(); - cpool->remove_conn(fd); + cpool->del_conn(conn); } void ConnPool::accept_client(int fd, int) { @@ -201,6 +201,7 @@ void ConnPool::accept_client(int fd, int) { void ConnPool::Conn::conn_server(int fd, int events) { auto conn = self(); /* pin the connection */ + if (!conn) return; if (send(fd, "", 0, MSG_NOSIGNAL) == 0) { ev_connect.clear(); @@ -290,8 +291,8 @@ ConnPool::conn_t ConnPool::_connect(const NetAddr &addr) { return conn; } -void ConnPool::remove_conn(int fd) { - auto it = pool.find(fd); +void ConnPool::del_conn(const conn_t &conn) { + auto it = pool.find(conn->fd); if (it != pool.end()) { /* temporarily pin the conn before it dies */ @@ -303,6 +304,7 @@ void ConnPool::remove_conn(int fd) { update_conn(conn, false); conn->release_self(); /* remove the self-cycle */ ::close(conn->fd); + SALTICIDAE_LOG_INFO("remove_conn: %s", std::string(*conn).c_str()); conn->fd = -1; } } |