Commit 9e34fdf9 authored by neverlord's avatar neverlord

bugfixing

parent b61316b9
...@@ -66,9 +66,10 @@ ...@@ -66,9 +66,10 @@
# error Plattform and/or compiler not supported # error Plattform and/or compiler not supported
#endif #endif
#ifdef CPPA_DEBUG
#include <cstdio> #include <cstdio>
#include <cstdlib> #include <cstdlib>
#ifdef CPPA_DEBUG
#include <execinfo.h> #include <execinfo.h>
#define CPPA_REQUIRE__(stmt, file, line) \ #define CPPA_REQUIRE__(stmt, file, line) \
...@@ -83,18 +84,16 @@ ...@@ -83,18 +84,16 @@
if ((stmt) == false) { \ if ((stmt) == false) { \
CPPA_REQUIRE__(#stmt, __FILE__, __LINE__); \ CPPA_REQUIRE__(#stmt, __FILE__, __LINE__); \
}((void) 0) }((void) 0)
#define CPPA_CRITICAL__(error, file, line) \
printf("%s:%u: critical error: '%s'\n", file, line, error); \
{ \
void *array[10]; \
size_t size = backtrace(array, 10); \
backtrace_symbols_fd(array, size, 2); \
} \
exit(7)
#define CPPA_CRITICAL(error) CPPA_CRITICAL__(error, __FILE__, __LINE__)
#else // CPPA_DEBUG #else // CPPA_DEBUG
#define CPPA_REQUIRE(unused) ((void) 0) #define CPPA_REQUIRE(unused) ((void) 0)
#define CPPA_CRITICAL(unused) exit(7)
#endif // CPPA_DEBUG #endif // CPPA_DEBUG
#define CPPA_CRITICAL__(error, file, line) \
{ \
printf("%s:%u: critical error: '%s'\n", file, line, error); \
exit(7); \
} ((void) 0)
#define CPPA_CRITICAL(error) CPPA_CRITICAL__(error, __FILE__, __LINE__)
#endif // CPPA_CONFIG_HPP #endif // CPPA_CONFIG_HPP
...@@ -45,13 +45,7 @@ class addressed_message ...@@ -45,13 +45,7 @@ class addressed_message
public: public:
addressed_message(actor_ptr const& from, addressed_message(actor_ptr from, channel_ptr to, any_tuple ut);
channel_ptr const& to,
any_tuple const& ut);
addressed_message(actor_ptr const& from,
channel_ptr const& to,
any_tuple&& ut);
addressed_message() = default; addressed_message() = default;
addressed_message(addressed_message&&) = default; addressed_message(addressed_message&&) = default;
......
...@@ -31,7 +31,9 @@ ...@@ -31,7 +31,9 @@
#ifndef THREAD_HPP #ifndef THREAD_HPP
#define THREAD_HPP #define THREAD_HPP
#ifdef __APPLE__ //#ifdef __APPLE__
#if 1
#include <boost/thread.hpp> #include <boost/thread.hpp>
#include "cppa/util/duration.hpp" #include "cppa/util/duration.hpp"
......
...@@ -49,8 +49,9 @@ void actor_proxy::forward_message(process_information_ptr const& piptr, ...@@ -49,8 +49,9 @@ void actor_proxy::forward_message(process_information_ptr const& piptr,
actor* sender, actor* sender,
any_tuple&& msg) any_tuple&& msg)
{ {
detail::addressed_message amsg{sender, this, std::move(msg)};
detail::singleton_manager::get_network_manager() detail::singleton_manager::get_network_manager()
->send_to_mailman(make_any_tuple(piptr, actor_ptr{sender}, std::move(msg))); ->send_to_mailman(make_any_tuple(piptr, std::move(amsg)));
} }
void actor_proxy::enqueue(actor* sender, any_tuple msg) void actor_proxy::enqueue(actor* sender, any_tuple msg)
......
...@@ -33,17 +33,8 @@ ...@@ -33,17 +33,8 @@
namespace cppa { namespace detail { namespace cppa { namespace detail {
addressed_message::addressed_message(const actor_ptr& from, addressed_message::addressed_message(actor_ptr from, channel_ptr to, any_tuple ut)
const channel_ptr& to, : m_sender(std::move(from)), m_receiver(std::move(to)), m_content(std::move(ut))
const any_tuple& ut)
: m_sender(from), m_receiver(to), m_content(ut)
{
}
addressed_message::addressed_message(const actor_ptr& from,
const channel_ptr& to,
any_tuple&& ut)
: m_sender(from), m_receiver(to), m_content(std::move(ut))
{ {
} }
......
...@@ -99,11 +99,12 @@ void mailman_loop() ...@@ -99,11 +99,12 @@ void mailman_loop()
} }
else else
{ {
DEBUG("message to an unknown peer"); DEBUG("message to an unknown peer: " << to_string(msg));
} }
}, },
on_arg_match >> [&](native_socket_type sockfd, process_information_ptr pinfo) on_arg_match >> [&](native_socket_type sockfd, process_information_ptr pinfo)
{ {
DEBUG("mailman: add_peer");
auto i = peers.find(*pinfo); auto i = peers.find(*pinfo);
if (i == peers.end()) if (i == peers.end())
{ {
......
This diff is collapsed.
...@@ -100,7 +100,8 @@ struct thread_pool_scheduler::worker ...@@ -100,7 +100,8 @@ struct thread_pool_scheduler::worker
{ {
return result; return result;
} }
# ifdef __APPLE__ # if 1
//# ifdef __APPLE__
auto timeout = boost::get_system_time(); auto timeout = boost::get_system_time();
timeout += boost::posix_time::milliseconds(1); timeout += boost::posix_time::milliseconds(1);
boost::this_thread::sleep(timeout); boost::this_thread::sleep(timeout);
...@@ -121,7 +122,8 @@ struct thread_pool_scheduler::worker ...@@ -121,7 +122,8 @@ struct thread_pool_scheduler::worker
{ {
return result; return result;
} }
# ifdef __APPLE__ # if 1
//# ifdef __APPLE__
auto timeout = boost::get_system_time(); auto timeout = boost::get_system_time();
timeout += boost::posix_time::milliseconds(10); timeout += boost::posix_time::milliseconds(10);
boost::this_thread::sleep(timeout); boost::this_thread::sleep(timeout);
...@@ -154,6 +156,9 @@ struct thread_pool_scheduler::worker ...@@ -154,6 +156,9 @@ struct thread_pool_scheduler::worker
handler h; handler h;
for (;;) for (;;)
{ {
h.job = aggressive_polling();
while (!h.job) h.job = less_aggressive_polling();
/*
h.job = aggressive_polling(); h.job = aggressive_polling();
if (!h.job) if (!h.job)
{ {
...@@ -163,6 +168,7 @@ struct thread_pool_scheduler::worker ...@@ -163,6 +168,7 @@ struct thread_pool_scheduler::worker
h.job = relaxed_polling(); h.job = relaxed_polling();
} }
} }
*/
if (h.job == m_dummy) if (h.job == m_dummy)
{ {
// dummy of doom received ... // dummy of doom received ...
......
...@@ -125,7 +125,8 @@ std::string to_uniform_name_impl(Iterator begin, Iterator end, ...@@ -125,7 +125,8 @@ std::string to_uniform_name_impl(Iterator begin, Iterator end,
{ demangled<cppa::actor_ptr>(), "@actor" }, { demangled<cppa::actor_ptr>(), "@actor" },
{ demangled<cppa::group_ptr>(), "@group" }, { demangled<cppa::group_ptr>(), "@group" },
{ demangled<cppa::channel_ptr>(), "@channel" }, { demangled<cppa::channel_ptr>(), "@channel" },
{ demangled<cppa::detail::addressed_message>(), "@msg" } { demangled<cppa::detail::addressed_message>(), "@msg" },
{ demangled< cppa::intrusive_ptr<cppa::process_information> >(), "@process_info" }
}; };
// check if we could find the whole string in our lookup map // check if we could find the whole string in our lookup map
......
...@@ -133,6 +133,10 @@ void publish(actor_ptr& whom, std::uint16_t port) ...@@ -133,6 +133,10 @@ void publish(actor_ptr& whom, std::uint16_t port)
{ {
throw network_error("unable to get socket flags"); throw network_error("unable to get socket flags");
} }
if (fcntl(sockfd, F_SETFL, flags | O_NONBLOCK) < 0)
{
throw network_error("unable to set socket to nonblock");
}
if (bind(sockfd, (struct sockaddr*) &serv_addr, sizeof(serv_addr)) < 0) if (bind(sockfd, (struct sockaddr*) &serv_addr, sizeof(serv_addr)) < 0)
{ {
throw bind_failure(errno); throw bind_failure(errno);
...@@ -172,7 +176,7 @@ actor_ptr remote_actor(const char* host, std::uint16_t port) ...@@ -172,7 +176,7 @@ actor_ptr remote_actor(const char* host, std::uint16_t port)
serv_addr.sin_family = AF_INET; serv_addr.sin_family = AF_INET;
memmove(&serv_addr.sin_addr.s_addr, server->h_addr, server->h_length); memmove(&serv_addr.sin_addr.s_addr, server->h_addr, server->h_length);
serv_addr.sin_port = htons(port); serv_addr.sin_port = htons(port);
if (connect(sockfd, (const sockaddr*) &serv_addr, sizeof(serv_addr)) < 0) if (connect(sockfd, (const sockaddr*) &serv_addr, sizeof(serv_addr)) != 0)
{ {
throw network_error("could not connect to host"); throw network_error("could not connect to host");
} }
...@@ -189,12 +193,11 @@ actor_ptr remote_actor(const char* host, std::uint16_t port) ...@@ -189,12 +193,11 @@ actor_ptr remote_actor(const char* host, std::uint16_t port)
auto peer_pinf = new process_information(peer_pid, peer_node_id); auto peer_pinf = new process_information(peer_pid, peer_node_id);
process_information_ptr pinfptr(peer_pinf); process_information_ptr pinfptr(peer_pinf);
auto key = std::make_tuple(remote_actor_id, pinfptr->process_id(), pinfptr->node_id()); auto key = std::make_tuple(remote_actor_id, pinfptr->process_id(), pinfptr->node_id());
auto result = detail::get_actor_proxy_cache().get(key);
detail::singleton_manager::get_network_manager() detail::singleton_manager::get_network_manager()
->send_to_mailman(make_any_tuple(sockfd, pinfptr)); ->send_to_mailman(make_any_tuple(sockfd, pinfptr));
detail::post_office_add_peer(sockfd, pinfptr); detail::post_office_add_peer(sockfd, pinfptr);
return detail::get_actor_proxy_cache().get(key);
//auto ptr = get_scheduler()->register_hidden_context(); //auto ptr = get_scheduler()->register_hidden_context();
return result;
} }
} // namespace cppa } // namespace cppa
...@@ -158,7 +158,7 @@ class void_type_tinfo : public util::abstract_uniform_type_info<void_type> ...@@ -158,7 +158,7 @@ class void_type_tinfo : public util::abstract_uniform_type_info<void_type>
protected: protected:
void serialize(const void*, serializer* sink) const void serialize(void const*, serializer* sink) const
{ {
serialize_nullptr(sink); serialize_nullptr(sink);
} }
...@@ -251,7 +251,7 @@ class actor_ptr_tinfo : public util::abstract_uniform_type_info<actor_ptr> ...@@ -251,7 +251,7 @@ class actor_ptr_tinfo : public util::abstract_uniform_type_info<actor_ptr>
protected: protected:
void serialize(const void* ptr, serializer* sink) const void serialize(void const* ptr, serializer* sink) const
{ {
s_serialize(*reinterpret_cast<const actor_ptr*>(ptr), s_serialize(*reinterpret_cast<const actor_ptr*>(ptr),
sink, sink,
...@@ -317,7 +317,7 @@ class group_ptr_tinfo : public util::abstract_uniform_type_info<group_ptr> ...@@ -317,7 +317,7 @@ class group_ptr_tinfo : public util::abstract_uniform_type_info<group_ptr>
protected: protected:
void serialize(const void* ptr, serializer* sink) const void serialize(void const* ptr, serializer* sink) const
{ {
s_serialize(*reinterpret_cast<const group_ptr*>(ptr), s_serialize(*reinterpret_cast<const group_ptr*>(ptr),
sink, sink,
...@@ -411,7 +411,7 @@ class channel_ptr_tinfo : public util::abstract_uniform_type_info<channel_ptr> ...@@ -411,7 +411,7 @@ class channel_ptr_tinfo : public util::abstract_uniform_type_info<channel_ptr>
protected: protected:
void serialize(const void* instance, serializer* sink) const void serialize(void const* instance, serializer* sink) const
{ {
s_serialize(*reinterpret_cast<const channel_ptr*>(instance), s_serialize(*reinterpret_cast<const channel_ptr*>(instance),
sink, sink,
...@@ -479,7 +479,7 @@ class any_tuple_tinfo : public util::abstract_uniform_type_info<any_tuple> ...@@ -479,7 +479,7 @@ class any_tuple_tinfo : public util::abstract_uniform_type_info<any_tuple>
protected: protected:
void serialize(const void* instance, serializer* sink) const void serialize(void const* instance, serializer* sink) const
{ {
s_serialize(*reinterpret_cast<const any_tuple*>(instance),sink,name()); s_serialize(*reinterpret_cast<const any_tuple*>(instance),sink,name());
} }
...@@ -501,7 +501,7 @@ class addr_msg_tinfo : public util::abstract_uniform_type_info<addressed_message ...@@ -501,7 +501,7 @@ class addr_msg_tinfo : public util::abstract_uniform_type_info<addressed_message
public: public:
virtual void serialize(const void* instance, serializer* sink) const virtual void serialize(void const* instance, serializer* sink) const
{ {
const addressed_message& msg = *reinterpret_cast<const addressed_message*>(instance); const addressed_message& msg = *reinterpret_cast<const addressed_message*>(instance);
const any_tuple& data = msg.content(); const any_tuple& data = msg.content();
...@@ -547,12 +547,68 @@ class addr_msg_tinfo : public util::abstract_uniform_type_info<addressed_message ...@@ -547,12 +547,68 @@ class addr_msg_tinfo : public util::abstract_uniform_type_info<addressed_message
}; };
class process_info_ptr_tinfo : public util::abstract_uniform_type_info<process_information_ptr>
{
typedef process_information_ptr ptr_type;
public:
virtual void serialize(void const* instance, serializer* sink) const
{
auto& ptr = *reinterpret_cast<ptr_type const*>(instance);
if (ptr == nullptr)
{
serialize_nullptr(sink);
}
else
{
primitive_variant ptup[2];
ptup[0] = ptr->process_id();
ptup[1] = to_string(ptr->node_id());
sink->begin_object(name());
sink->write_tuple(2, ptup);
sink->end_object();
}
}
virtual void deserialize(void* instance, deserializer* source) const
{
auto& ptrref = *reinterpret_cast<ptr_type*>(instance);
std::string cname = source->seek_object();
if (cname != name())
{
if (cname == nullptr_type_name)
{
deserialize_nullptr(source);
ptrref.reset();
}
else
{
throw std::logic_error("wrong type name found");
}
}
else
{
primitive_variant ptup[2];
primitive_type ptypes[] = { pt_uint32, pt_u8string };
source->begin_object(cname);
source->read_tuple(2, ptypes, ptup);
source->end_object();
process_information::node_id_type nid;
node_id_from_string(get<std::string>(ptup[1]), nid);
ptrref.reset(new process_information{get<std::uint32_t>(ptup[0]), nid});
}
}
};
class atom_value_tinfo : public util::abstract_uniform_type_info<atom_value> class atom_value_tinfo : public util::abstract_uniform_type_info<atom_value>
{ {
public: public:
virtual void serialize(const void* instance, serializer* sink) const virtual void serialize(void const* instance, serializer* sink) const
{ {
auto val = reinterpret_cast<const atom_value*>(instance); auto val = reinterpret_cast<const atom_value*>(instance);
sink->begin_object(name()); sink->begin_object(name());
...@@ -576,7 +632,7 @@ class atom_value_tinfo : public util::abstract_uniform_type_info<atom_value> ...@@ -576,7 +632,7 @@ class atom_value_tinfo : public util::abstract_uniform_type_info<atom_value>
class duration_tinfo : public util::abstract_uniform_type_info<util::duration> class duration_tinfo : public util::abstract_uniform_type_info<util::duration>
{ {
virtual void serialize(const void* instance, serializer* sink) const virtual void serialize(void const* instance, serializer* sink) const
{ {
auto val = reinterpret_cast<const util::duration*>(instance); auto val = reinterpret_cast<const util::duration*>(instance);
sink->begin_object(name()); sink->begin_object(name());
...@@ -694,6 +750,7 @@ class uniform_type_info_map_helper ...@@ -694,6 +750,7 @@ class uniform_type_info_map_helper
insert(d, new atom_value_tinfo, { raw_name<atom_value>() }); insert(d, new atom_value_tinfo, { raw_name<atom_value>() });
insert(d, new addr_msg_tinfo, {raw_name<detail::addressed_message>() }); insert(d, new addr_msg_tinfo, {raw_name<detail::addressed_message>() });
insert(d, new void_type_tinfo, { raw_name<void_type>() }); insert(d, new void_type_tinfo, { raw_name<void_type>() });
insert(d, new process_info_ptr_tinfo, {raw_name<process_information_ptr>()});
insert<float>(d); insert<float>(d);
insert<double>(d); insert<double>(d);
/* /*
......
...@@ -175,8 +175,8 @@ int main(int argc, char** argv) ...@@ -175,8 +175,8 @@ int main(int argc, char** argv)
}, },
on("run_ping", arg_match) >> [&](std::string const& num_pings) on("run_ping", arg_match) >> [&](std::string const& num_pings)
{ {
//auto ping_actor = spawn<detached>(ping, std::stoi(num_pings)); auto ping_actor = spawn<detached>(ping, std::stoi(num_pings));
auto ping_actor = spawn_event_based_ping(std::stoi(num_pings)); //auto ping_actor = spawn_event_based_ping(std::stoi(num_pings));
std::uint16_t port = 4242; std::uint16_t port = 4242;
bool success = false; bool success = false;
do do
......
...@@ -26,7 +26,8 @@ void client_part(std::vector<string_pair> const& args) ...@@ -26,7 +26,8 @@ void client_part(std::vector<string_pair> const& args)
} }
auto port = static_cast<std::uint16_t>(std::stoi(i->second)); auto port = static_cast<std::uint16_t>(std::stoi(i->second));
auto ping_actor = remote_actor("localhost", port); auto ping_actor = remote_actor("localhost", port);
spawn_event_based_pong(ping_actor); //spawn_event_based_pong(ping_actor);
spawn<detached>(pong, ping_actor);
await_all_others_done(); await_all_others_done();
} }
......
...@@ -87,6 +87,7 @@ size_t test__uniform_type() ...@@ -87,6 +87,7 @@ size_t test__uniform_type()
"@actor", // cppa::actor_ptr "@actor", // cppa::actor_ptr
"@group", // cppa::group_ptr "@group", // cppa::group_ptr
"@channel", // cppa::channel_ptr "@channel", // cppa::channel_ptr
"@process_info", // cppa::intrusive_ptr<cppa::process_information>
"cppa::util::duration" "cppa::util::duration"
}; };
// holds the type names we see at runtime // holds the type names we see at runtime
......
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