Merge pull request #326 from hurtonm/pipe_code_cleanup

pipe: code cleanup
This commit is contained in:
Ian Barber 2012-04-26 04:59:11 -07:00
commit 29000d3b02

View File

@ -255,12 +255,10 @@ void zmq::pipe_t::process_pipe_term ()
state = terminating; state = terminating;
outpipe = NULL; outpipe = NULL;
send_pipe_term_ack (peer); send_pipe_term_ack (peer);
return;
} }
else { else
state = pending; state = pending;
return; return;
}
} }
// Delimiter happened to arrive before the term command. Now we have the // Delimiter happened to arrive before the term command. Now we have the
@ -296,14 +294,12 @@ void zmq::pipe_t::process_pipe_term_ack ()
// Simply deallocate the pipe. In terminated state we have to ack the // Simply deallocate the pipe. In terminated state we have to ack the
// peer before deallocating this side of the pipe. All the other states // peer before deallocating this side of the pipe. All the other states
// are invalid. // are invalid.
if (state == terminating) ; if (state == terminated) {
else if (state == double_terminated);
else if (state == terminated) {
outpipe = NULL; outpipe = NULL;
send_pipe_term_ack (peer); send_pipe_term_ack (peer);
} }
else else
zmq_assert (false); zmq_assert (state == terminating || state == double_terminated);
// We'll deallocate the inbound pipe, the peer will deallocate the outbound // We'll deallocate the inbound pipe, the peer will deallocate the outbound
// pipe (which is an inbound pipe from its point of view). // pipe (which is an inbound pipe from its point of view).
@ -345,18 +341,18 @@ void zmq::pipe_t::terminate (bool delay_)
// There are still pending messages available, but the user calls // There are still pending messages available, but the user calls
// 'terminate'. We can act as if all the pending messages were read. // 'terminate'. We can act as if all the pending messages were read.
else if (state == pending && !delay) { else if (state == pending && !delay) {
outpipe = NULL; outpipe = NULL;
send_pipe_term_ack (peer); send_pipe_term_ack (peer);
state = terminating; state = terminating;
} }
// If there are pending messages still availabe, do nothing. // If there are pending messages still availabe, do nothing.
else if (state == pending && delay) { else if (state == pending) {
} }
// We've already got delimiter, but not term command yet. We can ignore // We've already got delimiter, but not term command yet. We can ignore
// the delimiter and ack synchronously terminate as if we were in // the delimiter and ack synchronously terminate as if we were in
// active state. // active state.
else if (state == delimited) { else if (state == delimited) {
send_pipe_term (peer); send_pipe_term (peer);
state = terminated; state = terminated;
@ -371,11 +367,11 @@ void zmq::pipe_t::terminate (bool delay_)
if (outpipe) { if (outpipe) {
// Rollback any unfinished outbound messages. // Drop any unfinished outbound messages.
rollback (); rollback ();
// Push delimiter into the outbound pipe. Note that watermarks are not // Write the delimiter into the pipe. Note that watermarks are not
// checked thus the delimiter can be written even though the pipe is full. // checked; thus the delimiter can be written even when the pipe is full.
msg_t msg; msg_t msg;
msg.init_delimiter (); msg.init_delimiter ();
outpipe->write (msg, false); outpipe->write (msg, false);