summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMartin Sustrik <sustrik@250bpm.com>2010-09-19 20:43:14 +0200
committerMartin Sustrik <sustrik@250bpm.com>2010-09-19 20:43:14 +0200
commit471013a59fc7f41b694c0bc0b11a459d4c19700d (patch)
tree9160c31b89537c618cc07c2dc765101e40d5d0ae /src
parent1f10208ad065c01e172669affdd48b6f2698ff4c (diff)
two races fixed in session creation
Diffstat (limited to 'src')
-rw-r--r--src/zmq_init.cpp16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/zmq_init.cpp b/src/zmq_init.cpp
index 5bf6070..3c8f288 100644
--- a/src/zmq_init.cpp
+++ b/src/zmq_init.cpp
@@ -153,14 +153,18 @@ void zmq::zmq_init_t::finalise_initialisation ()
zmq_assert (socket);
// We have no associated session. If the peer has no identity we'll
- // create a transient session for the connection.
+ // create a transient session for the connection. Note that
+ // seqnum is incremented to account for attach command before the
+ // session is launched. That way we are sure it won't terminate before
+ // being attached.
if (peer_identity [0] == 0) {
session = new (std::nothrow) transient_session_t (io_thread,
socket, options);
zmq_assert (session);
+ session->inc_seqnum ();
launch_sibling (session);
engine->unplug ();
- send_attach (session, engine, peer_identity, true);
+ send_attach (session, engine, peer_identity, false);
engine = NULL;
terminate ();
return;
@@ -179,13 +183,17 @@ void zmq::zmq_init_t::finalise_initialisation ()
return;
}
- // There's no such named session. We have to create one.
+ // There's no such named session. We have to create one. Note that
+ // seqnum is incremented to account for attach command before the
+ // session is launched. That way we are sure it won't terminate before
+ // being attached.
session = new (std::nothrow) named_session_t (io_thread, socket,
options, peer_identity);
zmq_assert (session);
+ session->inc_seqnum ();
launch_sibling (session);
engine->unplug ();
- send_attach (session, engine, peer_identity, true);
+ send_attach (session, engine, peer_identity, false);
engine = NULL;
terminate ();
return;