Commit 5daa0dec authored by Martin Sustrik's avatar Martin Sustrik

ZMQII-5: Only one consumer in a process gets the message

parent f824b8a0
...@@ -72,9 +72,9 @@ void zmq::session_t::detach () ...@@ -72,9 +72,9 @@ void zmq::session_t::detach ()
// Engine is terminating itself. // Engine is terminating itself.
engine = NULL; engine = NULL;
// TODO: In the case od anonymous connection, terminate the session. // In the case od anonymous connection, terminate the session.
// if (anonymous) if (name.empty ())
// term (); term ();
} }
void zmq::session_t::attach_inpipe (reader_t *pipe_) void zmq::session_t::attach_inpipe (reader_t *pipe_)
...@@ -114,11 +114,13 @@ void zmq::session_t::detach_outpipe (writer_t *pipe_) ...@@ -114,11 +114,13 @@ void zmq::session_t::detach_outpipe (writer_t *pipe_)
void zmq::session_t::process_plug () void zmq::session_t::process_plug ()
{ {
// Register the session with the socket. // Register the session with the socket.
bool ok = owner->register_session (name.c_str (), this); if (!name.empty ()) {
bool ok = owner->register_session (name.c_str (), this);
// There's already a session with the specified identity. // There's already a session with the specified identity.
// We should syslog it and drop the session. TODO // We should syslog it and drop the session. TODO
zmq_assert (ok); zmq_assert (ok);
}
// If session is created by 'connect' function, it has the pipes set // If session is created by 'connect' function, it has the pipes set
// already. Otherwise, it's being created by the listener and the pipes // already. Otherwise, it's being created by the listener and the pipes
...@@ -141,8 +143,10 @@ void zmq::session_t::process_plug () ...@@ -141,8 +143,10 @@ void zmq::session_t::process_plug ()
void zmq::session_t::process_unplug () void zmq::session_t::process_unplug ()
{ {
// Unregister the session from the socket. // Unregister the session from the socket.
bool ok = owner->unregister_session (name.c_str ()); if (!name.empty ()) {
zmq_assert (ok); bool ok = owner->unregister_session (name.c_str ());
zmq_assert (ok);
}
// Ask associated pipes to terminate. // Ask associated pipes to terminate.
if (in_pipe) { if (in_pipe) {
...@@ -163,6 +167,7 @@ void zmq::session_t::process_unplug () ...@@ -163,6 +167,7 @@ void zmq::session_t::process_unplug ()
void zmq::session_t::process_attach (i_engine *engine_) void zmq::session_t::process_attach (i_engine *engine_)
{ {
zmq_assert (!engine);
zmq_assert (engine_); zmq_assert (engine_);
engine = engine_; engine = engine_;
engine->plug (this); engine->plug (this);
......
...@@ -55,7 +55,9 @@ bool zmq::zmq_connecter_init_t::read (::zmq_msg_t *msg_) ...@@ -55,7 +55,9 @@ bool zmq::zmq_connecter_init_t::read (::zmq_msg_t *msg_)
// Find the session associated with this connecter. If it doesn't exist // Find the session associated with this connecter. If it doesn't exist
// drop the newly created connection. If it does, attach it to the // drop the newly created connection. If it does, attach it to the
// connection. // connection.
session_t *session = owner->find_session (session_name.c_str ()); session_t *session = NULL;
if (!session_name.empty ())
session = owner->find_session (session_name.c_str ());
if (!session) { if (!session) {
// TODO // TODO
zmq_assert (false); zmq_assert (false);
......
...@@ -50,6 +50,8 @@ zmq::zmq_engine_t::~zmq_engine_t () ...@@ -50,6 +50,8 @@ zmq::zmq_engine_t::~zmq_engine_t ()
void zmq::zmq_engine_t::plug (i_inout *inout_) void zmq::zmq_engine_t::plug (i_inout *inout_)
{ {
zmq_assert (!inout);
encoder.set_inout (inout_); encoder.set_inout (inout_);
decoder.set_inout (inout_); decoder.set_inout (inout_);
......
...@@ -70,7 +70,9 @@ void zmq::zmq_listener_init_t::flush () ...@@ -70,7 +70,9 @@ void zmq::zmq_listener_init_t::flush ()
// Have a look whether the session already exists. If it does, attach it // Have a look whether the session already exists. If it does, attach it
// to the engine. If it doesn't create it first. // to the engine. If it doesn't create it first.
session_t *session = owner->find_session (peer_identity.c_str ()); session_t *session = NULL;
if (!peer_identity.empty ())
session = owner->find_session (peer_identity.c_str ());
if (!session) { if (!session) {
io_thread_t *io_thread = choose_io_thread (options.affinity); io_thread_t *io_thread = choose_io_thread (options.affinity);
session = new session_t (io_thread, owner, peer_identity.c_str (), session = new session_t (io_thread, owner, peer_identity.c_str (),
......
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