Esempio n. 1
0
void zmq::session_t::process_term (int linger_)
{
    zmq_assert (state == active);
    state = pending;

    //  If linger is set to zero, we can terminate the session straight away
    //  not waiting for the pending messages to be sent.
    if (linger_ == 0) {
        proceed_with_term ();
        return;
    }

    //  If there's finite linger value, set up a timer.
    if (linger_ > 0) {
       zmq_assert (!has_linger_timer);
       add_timer (linger_, linger_timer_id);
       has_linger_timer = true;
    }

    //  If there's no engine and there's only delimiter in the pipe it wouldn't
    //  be ever read. Thus we check for it explicitly.
    if (in_pipe)
        in_pipe->check_read ();

    //  If there's no in pipe there are no pending messages to send.
    //  We can proceed with the shutdown straight away. Also, if there is
    //  inbound pipe, but the delimiter was already processed, we can
    //  terminate immediately. Alternatively, if the derived session type have
    //  called 'terminate' we'll finish straight away.
    if (!options.requires_out || delimiter_processed || force_terminate ||
        (!options.immediate_connect && !in_pipe))
        proceed_with_term ();
}
Esempio n. 2
0
void zmq::session_base_t::pipe_terminated (pipe_t *pipe_)
{
    // Drop the reference to the deallocated pipe if required.
    zmq_assert (pipe_ == pipe
             || pipe_ == zap_pipe
             || terminating_pipes.count (pipe_) == 1);

    if (pipe_ == pipe)
        // If this is our current pipe, remove it
        pipe = NULL;
    else
    if (pipe_ == zap_pipe)
        zap_pipe = NULL;
    else
        // Remove the pipe from the detached pipes set
        terminating_pipes.erase (pipe_);

    if (!is_terminating () && options.raw_sock) {
        if (engine) {
            engine->terminate ();
            engine = NULL;
        }
        terminate ();
    }

    //  If we are waiting for pending messages to be sent, at this point
    //  we are sure that there will be no more messages and we can proceed
    //  with termination safely.
    if (pending && !pipe && !zap_pipe && terminating_pipes.empty ())
        proceed_with_term ();
}
Esempio n. 3
0
void zmq::session_base_t::process_term (int linger_)
{
    zmq_assert (!pending);

    //  If the termination of the pipe happens before the term command is
    //  delivered there's nothing much to do. We can proceed with the
    //  stadard termination immediately.
    if (!pipe) {
        proceed_with_term ();
        return;
    }

    pending = true;

    //  If there's finite linger value, delay the termination.
    //  If linger is infinite (negative) we don't even have to set
    //  the timer.
    if (linger_ > 0) {
        zmq_assert (!has_linger_timer);
        add_timer (linger_, linger_timer_id);
        has_linger_timer = true;
    }

    //  Start pipe termination process. Delay the termination till all messages
    //  are processed in case the linger time is non-zero.
    pipe->terminate (linger_ != 0);

    //  TODO: Should this go into pipe_t::terminate ?
    //  In case there's no engine and there's only delimiter in the
    //  pipe it wouldn't be ever read. Thus we check for it explicitly.
    pipe->check_read ();
}
Esempio n. 4
0
void zmq::session_t::timer_event (int id_)
{
    //  Linger period expired. We can proceed with termination even though
    //  there are still pending messages to be sent.
    zmq_assert (id_ == linger_timer_id);
    has_linger_timer = false;
    proceed_with_term ();
}
Esempio n. 5
0
void zmq::session_t::delimited (reader_t *pipe_)
{
    zmq_assert (in_pipe == pipe_);
    zmq_assert (!delimiter_processed);
    delimiter_processed = true;

    //  If we are in process of being closed, but still waiting for all
    //  pending messeges being sent, we can terminate here.
    if (state == pending)
        proceed_with_term ();
}
Esempio n. 6
0
void zmq::session_base_t::terminated (pipe_t *pipe_)
{
    //  Drop the reference to the deallocated pipe.
    zmq_assert (pipe == pipe_);
    pipe = NULL;

    //  If we are waiting for pending messages to be sent, at this point
    //  we are sure that there will be no more messages and we can proceed
    //  with termination safely.
    if (pending)
        proceed_with_term ();
}
Esempio n. 7
0
void zmq::session_base_t::terminated (pipe_t *pipe_)
{
    // Drop the reference to the deallocated pipe if required.
    zmq_assert (pipe == pipe_ || terminating_pipes.count (pipe_) == 1);

    if (pipe == pipe_)
        // If this is our current pipe, remove it
        pipe = NULL;
    else
        // Remove the pipe from the detached pipes set
        terminating_pipes.erase (pipe_);

    // If we are waiting for pending messages to be sent, at this point
    // we are sure that there will be no more messages and we can proceed
    // with termination safely.
    if (pending && !pipe && terminating_pipes.size () == 0)
        proceed_with_term ();
}