Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
detect connections from/to self and access local actors directly inst…
…ead, relates #67
  • Loading branch information
neverlord authored and neverlord committed Sep 5, 2012
1 parent 92a71cf commit c86f6e3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
17 changes: 15 additions & 2 deletions src/middleman.cpp
Expand Up @@ -58,16 +58,19 @@


using namespace std; using namespace std;


//#define VERBOSE_MIDDLEMAN

#ifdef VERBOSE_MIDDLEMAN
#define DEBUG(arg) { \ #define DEBUG(arg) { \
ostringstream oss; \ ostringstream oss; \
oss << "[process id: " \ oss << "[process id: " \
<< cppa::process_information::get()->process_id() \ << cppa::process_information::get()->process_id() \
<< "] " << arg << endl; \ << "] " << arg << endl; \
cout << oss.str(); \ cout << oss.str(); \
} (void) 0 } (void) 0

#else
#undef DEBUG
#define DEBUG(unused) ((void) 0) #define DEBUG(unused) ((void) 0)
#endif


namespace cppa { namespace detail { namespace cppa { namespace detail {


Expand Down Expand Up @@ -398,6 +401,16 @@ bool peer_connection::continue_reading() {
memcpy(node_id.data(), m_rd_buf.data() + sizeof(uint32_t), memcpy(node_id.data(), m_rd_buf.data() + sizeof(uint32_t),
process_information::node_id_size); process_information::node_id_size);
m_peer.reset(new process_information(process_id, node_id)); m_peer.reset(new process_information(process_id, node_id));
if (*(parent()->pself()) == *m_peer) {
# ifdef VERBOSE_MIDDLEMAN
DEBUG("incoming connection from self");
# elif defined(CPPA_DEBUG)
std::cerr << "*** middleman warning: "
"incoming connection from self"
<< std::endl;
# endif
throw std::ios_base::failure("refused connection from self");
}
parent()->add_peer(*m_peer, this); parent()->add_peer(*m_peer, this);
// initialization done // initialization done
m_rd_state = wait_for_msg_size; m_rd_state = wait_for_msg_size;
Expand Down
12 changes: 8 additions & 4 deletions src/unicast_network.cpp
Expand Up @@ -57,10 +57,6 @@
#include "cppa/detail/actor_proxy_cache.hpp" #include "cppa/detail/actor_proxy_cache.hpp"
#include "cppa/detail/singleton_manager.hpp" #include "cppa/detail/singleton_manager.hpp"



using std::cout;
using std::endl;

namespace cppa { namespace cppa {


void publish(actor_ptr whom, std::unique_ptr<util::acceptor> acceptor) { void publish(actor_ptr whom, std::unique_ptr<util::acceptor> acceptor) {
Expand All @@ -82,6 +78,14 @@ actor_ptr remote_actor(util::io_stream_ptr_pair peer) {
peer.first->read(&peer_pid, sizeof(std::uint32_t)); peer.first->read(&peer_pid, sizeof(std::uint32_t));
peer.first->read(peer_node_id.data(), peer_node_id.size()); peer.first->read(peer_node_id.data(), peer_node_id.size());
process_information_ptr pinfptr(new process_information(peer_pid, peer_node_id)); process_information_ptr pinfptr(new process_information(peer_pid, peer_node_id));
if (*pinf == *pinfptr) {
// dude, this is not a remote actor, it's a local actor!
# ifdef CPPA_DEBUG
std::cerr << "*** warning: remote_actor() called to access a local actor\n"
<< std::flush;
# endif
return detail::singleton_manager::get_actor_registry()->get(remote_actor_id);
}
//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());
detail::middleman_add_peer(peer, pinfptr); detail::middleman_add_peer(peer, pinfptr);
return detail::get_actor_proxy_cache().get_or_put(remote_actor_id, return detail::get_actor_proxy_cache().get_or_put(remote_actor_id,
Expand Down

0 comments on commit c86f6e3

Please sign in to comment.