From 87a6490b39c44e8f9c521f6ccea14f800a712d3f Mon Sep 17 00:00:00 2001 From: Martin Sustrik Date: Wed, 25 May 2011 10:25:51 +0200 Subject: All pipe termination code moved to pipe_t Till now the code was spread over mutliple locations. Additionally, the code was made more formally correct, with explicit pipe state machine etc. Signed-off-by: Martin Sustrik --- src/pipe.hpp | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) (limited to 'src/pipe.hpp') diff --git a/src/pipe.hpp b/src/pipe.hpp index f821bdd..3087ab8 100644 --- a/src/pipe.hpp +++ b/src/pipe.hpp @@ -99,6 +99,9 @@ namespace zmq void process_pipe_term (); void process_pipe_term_ack (); + // Handler for delimiter read from the pipe. + void delimit (); + // Type of the underlying lock-free pipe. typedef ypipe_t upipe_t; @@ -142,15 +145,23 @@ namespace zmq // Sink to send events to. i_pipe_events *sink; - // True is 'terminate' method was called or termination request - // was received from the peer. - bool terminating; - - // True is we've already got pipe_term command from the peer. - bool term_recvd; - - // True if delimiter was already received from the peer. - bool delimited; + // State of the pipe endpoint. Active is common state before any + // termination begins. Delimited means that delimiter was read from + // pipe before term command was received. Pending means that term + // command was already received from the peer but there are still + // pending messages to read. Terminating means that all pending + // messages were already read and all we are waiting for is ack from + // the peer. Terminated means that 'terminate' was explicitly called + // by the user. Double_terminated means that user called 'terminate' + // and then we've got term command from the peer as well. + enum { + active, + delimited, + pending, + terminating, + terminated, + double_terminated + } state; // If true, we receive all the pending inbound messages before // terminating. If false, we terminate immediately when the peer -- cgit v1.2.3