Esempio n. 1
0
    void rpc_session::send_message(message_ex* msg)
    {
        msg->add_ref(); // released in on_send_completed

        msg->io_session = this;

        dassert(_parser, "parser should not be null when send");
        _parser->prepare_on_send(msg);

        uint64_t sig;
        {
            utils::auto_lock<utils::ex_lock_nr> l(_lock);
            msg->dl.insert_before(&_messages);
            ++_message_count;

            if (SS_CONNECTED == _connect_state && !_is_sending_next)
            {
                _is_sending_next = true;
                sig = _message_sent + 1;
                unlink_message_for_send();
            }
            else
            {
                return;
            }
        }

        this->send(sig);
    }
Esempio n. 2
0
    void rpc_session::send_message(message_ex* msg)
    {
        //dinfo("%s: rpc_id = %016llx, code = %s", __FUNCTION__, msg->header->rpc_id, msg->header->rpc_name);

        msg->add_ref(); // released in on_send_completed

        uint64_t sig;
        {
            utils::auto_lock<utils::ex_lock_nr> l(_lock);
            msg->dl.insert_before(&_messages);
            ++_message_count;

            if (SS_CONNECTED == _connect_state && !_is_sending_next)
            {
                _is_sending_next = true;
                sig = _message_sent + 1;
                unlink_message_for_send();
            }
            else
            {
                return;
            }
        }

        this->send(sig);
    }
Esempio n. 3
0
    void rpc_session::on_send_completed(uint64_t signature)
    {
        uint64_t sig = 0;
        {
            utils::auto_lock<utils::ex_lock_nr> l(_lock);
            if (signature != 0)
            {
                dassert(_is_sending_next
                    && signature == _message_sent + 1,
                    "sent msg must be sending");
                _is_sending_next = false;

                // the _sending_msgs may have been cleared when reading of the rpc_session is failed.
                if (_sending_msgs.size() == 0)
                {
                    dassert(_connect_state == SS_DISCONNECTED,
                            "assume sending queue is cleared due to session closed");
                    return;
                }
                
                for (auto& msg : _sending_msgs)
                {
                    // added in rpc_engine::reply (for server) or rpc_session::send_message (for client)
                    msg->release_ref();
                    _message_sent++;
                }
                _sending_msgs.clear();
                _sending_buffers.clear();
            }
            
            if (!_is_sending_next)
            {
                if (unlink_message_for_send())
                {
                    sig = _message_sent + 1;
                    _is_sending_next = true;
                }
            }
        }

        // for next send messages
        if (sig != 0)
            this->send(sig);
    }