boosted_tcp_server: fix connection lifetime
This commit is contained in:
parent
afec439953
commit
6d5e2106b3
|
@ -269,8 +269,6 @@ PRAGMA_WARNING_DISABLE_VS(4355)
|
||||||
//_dbg3("[sock " << socket().native_handle() << "] add_ref, m_peer_number=" << mI->m_peer_number);
|
//_dbg3("[sock " << socket().native_handle() << "] add_ref, m_peer_number=" << mI->m_peer_number);
|
||||||
CRITICAL_REGION_LOCAL(self->m_self_refs_lock);
|
CRITICAL_REGION_LOCAL(self->m_self_refs_lock);
|
||||||
//_dbg3("[sock " << socket().native_handle() << "] add_ref 2, m_peer_number=" << mI->m_peer_number);
|
//_dbg3("[sock " << socket().native_handle() << "] add_ref 2, m_peer_number=" << mI->m_peer_number);
|
||||||
if(m_was_shutdown)
|
|
||||||
return false;
|
|
||||||
++m_reference_count;
|
++m_reference_count;
|
||||||
m_self_ref = std::move(self);
|
m_self_ref = std::move(self);
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -892,12 +892,22 @@ template<class t_connection_context> template<class callback_t>
|
||||||
bool async_protocol_handler_config<t_connection_context>::foreach_connection(const callback_t &cb)
|
bool async_protocol_handler_config<t_connection_context>::foreach_connection(const callback_t &cb)
|
||||||
{
|
{
|
||||||
CRITICAL_REGION_LOCAL(m_connects_lock);
|
CRITICAL_REGION_LOCAL(m_connects_lock);
|
||||||
for(auto& c: m_connects)
|
std::vector<typename connections_map::mapped_type> conn;
|
||||||
{
|
conn.reserve(m_connects.size());
|
||||||
async_protocol_handler<t_connection_context>* aph = c.second;
|
|
||||||
|
auto scope_exit_handler = misc_utils::create_scope_leave_handler([&conn]{
|
||||||
|
for (auto &aph: conn)
|
||||||
|
aph->finish_outer_call();
|
||||||
|
});
|
||||||
|
|
||||||
|
for (auto &e: m_connects)
|
||||||
|
if (e.second->start_outer_call())
|
||||||
|
conn.push_back(e.second);
|
||||||
|
|
||||||
|
for (auto &aph: conn)
|
||||||
if (!cb(aph->get_context_ref()))
|
if (!cb(aph->get_context_ref()))
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------------
|
||||||
|
@ -908,6 +918,10 @@ bool async_protocol_handler_config<t_connection_context>::for_connection(const b
|
||||||
async_protocol_handler<t_connection_context>* aph = find_connection(connection_id);
|
async_protocol_handler<t_connection_context>* aph = find_connection(connection_id);
|
||||||
if (!aph)
|
if (!aph)
|
||||||
return false;
|
return false;
|
||||||
|
if (!aph->start_outer_call())
|
||||||
|
return false;
|
||||||
|
auto scope_exit_handler = misc_utils::create_scope_leave_handler(
|
||||||
|
boost::bind(&async_protocol_handler<t_connection_context>::finish_outer_call, aph));
|
||||||
if(!cb(aph->get_context_ref()))
|
if(!cb(aph->get_context_ref()))
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in New Issue