Exemple #1
0
void zmq::pipe_t::flush ()
{
    //  The peer does not exist anymore at this point.
    if (state == term_ack_sent)
        return;

    if (outpipe && !outpipe->flush ())
        send_activate_read (peer);
}
Exemple #2
0
void xs::pipe_t::flush ()
{
    //  If terminate() was already called do nothing.
    if (state == terminated || state == double_terminated)
        return;

    //  The peer does not exist anymore at this point.
    if (state == terminating)
        return;

    if (outpipe && !outpipe->flush ())
        send_activate_read (peer);
}
Exemple #3
0
void xs::pipe_t::terminate (bool delay_)
{
    //  Overload the value specified at pipe creation.
    delay = delay_;

    //  If terminate was already called, we can ignore the duplicit invocation.
    if (state == terminated || state == double_terminated)
        return;

    //  If the pipe is in the final phase of async termination, it's going to
    //  closed anyway. No need to do anything special here.
    else if (state == terminating)
        return;

    //  The simple sync termination case. Ask the peer to terminate and wait
    //  for the ack.
    else if (state == active) {
        send_pipe_term (peer);
        state = terminated;
    }

    //  There are still pending messages available, but the user calls
    //  'terminate'. We can act as if all the pending messages were read.
    else if (state == pending && !delay) {
        outpipe = NULL;
        send_pipe_term_ack (peer);
        state = terminating;
    }

    //  If there are pending messages still availabe, do nothing.
    else if (state == pending && delay) {
    }

    //  We've already got delimiter, but not term command yet. We can ignore
    //  the delimiter and ack synchronously terminate as if we were in
    //  active state.    
    else if (state == delimited) {
        send_pipe_term (peer);
        state = terminated;    
    }

    //  There are no other states.
    else
        xs_assert (false);

    //  Stop outbound flow of messages.
    out_active = false;

    if (outpipe) {

		//  Rollback any unfinished outbound messages.
		rollback ();

		//  Push delimiter into the outbound pipe. Note that watermarks are not
		//  checked thus the delimiter can be written even though the pipe
        //  is full.
		msg_t msg;
		msg.init_delimiter ();
		outpipe->write (msg, false);
        if (state != terminating && !outpipe->flush ())
            send_activate_read (peer);
    }
}