diff options
author | Martin Sustrik <sustrik@250bpm.com> | 2012-03-20 15:31:01 +0100 |
---|---|---|
committer | Martin Sustrik <sustrik@250bpm.com> | 2012-03-20 15:31:01 +0100 |
commit | 818d122d78e4b3bc55fdc376b43e15841b2e2006 (patch) | |
tree | 61509054977a8b4086290adf8fe0f8f1c17a6ada /src | |
parent | d7f1c5cfebd95ace9a62a5f1b7a8208827df0fb6 (diff) |
Send identities on reconnect
When reconnection happened, identity was not resent to the peer.
Fixed.
Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/session_base.cpp | 15 | ||||
-rw-r--r-- | src/session_base.hpp | 10 |
2 files changed, 20 insertions, 5 deletions
diff --git a/src/session_base.cpp b/src/session_base.cpp index be7d429..b752f9f 100644 --- a/src/session_base.cpp +++ b/src/session_base.cpp @@ -114,7 +114,9 @@ xs::session_base_t::session_base_t (class io_thread_t *io_thread_, socket (socket_), io_thread (io_thread_), send_identity (options_.send_identity), + identity_sent (false), recv_identity (options_.recv_identity), + identity_recvd (false), linger_timer (NULL) { if (protocol_) @@ -150,11 +152,11 @@ void xs::session_base_t::attach_pipe (pipe_t *pipe_) int xs::session_base_t::read (msg_t *msg_) { // First message to send is identity (if required). - if (send_identity) { + if (send_identity && !identity_sent) { xs_assert (!(msg_->flags () & msg_t::more)); msg_->init_size (options.identity_size); memcpy (msg_->data (), options.identity, options.identity_size); - send_identity = false; + identity_sent = true; incomplete_in = false; return 0; } @@ -171,9 +173,9 @@ int xs::session_base_t::read (msg_t *msg_) int xs::session_base_t::write (msg_t *msg_) { // First message to receive is identity (if required). - if (recv_identity) { + if (recv_identity && !identity_recvd) { msg_->set_flags (msg_t::identity); - recv_identity = false; + identity_recvd = true; } if (pipe && pipe->write (msg_)) { @@ -301,6 +303,11 @@ void xs::session_base_t::detach () // Engine is dead. Let's forget about it. engine = NULL; + // In case identities are sent/received, remember we yet hato to send/recv + // one from the new connection. + identity_sent = false; + identity_recvd = false; + // Remove any half-done messages from the pipes. clean_pipes (); diff --git a/src/session_base.hpp b/src/session_base.hpp index 8b0d019..47da8c2 100644 --- a/src/session_base.hpp +++ b/src/session_base.hpp @@ -118,10 +118,18 @@ namespace xs // the engines into the same thread. xs::io_thread_t *io_thread; - // If true, identity is to be sent/recvd from the network. + // If true, identity is to be sent to the network. bool send_identity; + + // If true, identity was already sent to the current connection. + bool identity_sent; + + // If true, identity is to be received from the network. bool recv_identity; + // If true, identity was already received from the current connection. + bool identity_recvd; + // Protocol and address to use when connecting. std::string protocol; std::string address; |