Commit 5e9d12cf authored by Dominik Charousset's avatar Dominik Charousset

decrease running actor count correctly

parent 9bea72e9
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include "cppa/singletons.hpp" #include "cppa/singletons.hpp"
#include "cppa/detail/actor_registry.hpp"
#include "cppa/network/io_actor.hpp" #include "cppa/network/io_actor.hpp"
#include "cppa/network/middleman.hpp" #include "cppa/network/middleman.hpp"
...@@ -45,7 +46,9 @@ class io_actor_continuation { ...@@ -45,7 +46,9 @@ class io_actor_continuation {
io_actor_continuation(io_actor_ptr ptr, mailbox_element* elem) io_actor_continuation(io_actor_ptr ptr, mailbox_element* elem)
: m_self(std::move(ptr)), m_elem(elem) { } : m_self(std::move(ptr)), m_elem(elem) { }
void operator()() const { m_self->invoke_message(m_elem); } void operator()() const {
m_self->invoke_message(m_elem);
}
private: private:
...@@ -97,6 +100,9 @@ void io_actor::invoke_message(mailbox_element* elem) { ...@@ -97,6 +100,9 @@ void io_actor::invoke_message(mailbox_element* elem) {
CPPA_LOG_ERROR("IO actor killed due to an unhandled exception"); CPPA_LOG_ERROR("IO actor killed due to an unhandled exception");
quit(exit_reason::unhandled_exception); quit(exit_reason::unhandled_exception);
} }
if (exit_reason() != exit_reason::not_exited) {
get_actor_registry()->dec_running();
}
} }
void io_actor::invoke_message(any_tuple msg) { void io_actor::invoke_message(any_tuple msg) {
......
...@@ -28,6 +28,8 @@ ...@@ -28,6 +28,8 @@
\******************************************************************************/ \******************************************************************************/
#include <iostream>
#include "cppa/singletons.hpp" #include "cppa/singletons.hpp"
#include "cppa/network/middleman.hpp" #include "cppa/network/middleman.hpp"
...@@ -51,8 +53,8 @@ io_actor_backend::io_actor_backend(input_stream_ptr in, ...@@ -51,8 +53,8 @@ io_actor_backend::io_actor_backend(input_stream_ptr in,
} }
io_actor_backend::~io_actor_backend() { io_actor_backend::~io_actor_backend() {
std::cout << "~io_actor_backend" << std::endl;
handle_disconnect(); handle_disconnect();
get_actor_registry()->dec_running();
} }
void io_actor_backend::init() { void io_actor_backend::init() {
...@@ -64,11 +66,19 @@ void io_actor_backend::init() { ...@@ -64,11 +66,19 @@ void io_actor_backend::init() {
void io_actor_backend::handle_disconnect() { void io_actor_backend::handle_disconnect() {
if (m_self) { if (m_self) {
auto ms = m_self;
m_self.reset();
bool dec_count = ms->exit_reason() == exit_reason::not_exited;
CPPA_LOG_DEBUG("became disconnected"); CPPA_LOG_DEBUG("became disconnected");
if (m_self->exit_reason() == exit_reason::not_exited) { if (ms->exit_reason() == exit_reason::not_exited) {
m_self->invoke_message(make_any_tuple(atom("IO_closed"))); ms->invoke_message(make_any_tuple(atom("IO_closed")));
}
get_middleman()->stop_reader(this);
if (dec_count) {
if (ms->exit_reason() != exit_reason::not_exited) {
get_actor_registry()->dec_running();
}
} }
m_self.reset();
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment