Esempio n. 1
0
    void connection_oriented_network::send_message(message_ex* request)
    {
        rpc_session_ptr client = nullptr;
        auto& to = request->to_address;

        // TODO: thread-local client ptr cache
        {
            utils::auto_read_lock l(_clients_lock);
            auto it = _clients.find(to);
            if (it != _clients.end())
            {
                client = it->second;
            }
        }

        int scount = 0;
        bool new_client = false;
        if (nullptr == client.get())
        {
            utils::auto_write_lock l(_clients_lock);
            auto it = _clients.find(to);
            if (it != _clients.end())
            {
                client = it->second;
            }
            else
            {
                client = create_client_session(to);
                _clients.insert(client_sessions::value_type(to, client));
                new_client = true;
            }
            scount = (int)_clients.size();
        }

        // init connection if necessary
        if (new_client) 
        {
            ddebug("client session created, remote_server = %s, current_count = %d",
                   client->remote_address().to_string(), scount);
            client->connect();
        }

        // rpc call
        client->send_message(request);
    }
Esempio n. 2
0
    void connection_oriented_network::send_message(message_ex* request)
    {
        rpc_session_ptr client = nullptr;
        bool new_client = false;
        auto& to = request->to_address;

        // TODO: thread-local client ptr cache
        {
            utils::auto_read_lock l(_clients_lock);
            auto it = _clients.find(to);
            if (it != _clients.end())
            {
                client = it->second;
            }
        }

        if (nullptr == client.get())
        {
            utils::auto_write_lock l(_clients_lock);
            auto it = _clients.find(to);
            if (it != _clients.end())
            {
                client = it->second;
            }
            else
            {
                client = create_client_session(to);
                _clients.insert(client_sessions::value_type(to, client));
                new_client = true;
            }
        }

        // init connection if necessary
        if (new_client) 
        {
            client->connect();
        }

        // rpc call
        client->send_message(request);
    }
Esempio n. 3
0
    void connection_oriented_network::call(message_ptr& request, rpc_response_task_ptr& call)
    {
        rpc_client_session_ptr client = nullptr;
        end_point& to = request->header().to_address;
        bool new_client = false;

        // TODO: thread-local client ptr cache
        {
            utils::auto_read_lock l(_clients_lock);
            auto it = _clients.find(to);
            if (it != _clients.end())
            {
                client = it->second;
            }
        }

        if (nullptr == client.get())
        {
            utils::auto_write_lock l(_clients_lock);
            auto it = _clients.find(to);
            if (it != _clients.end())
            {
                client = it->second;
            }
            else
            {
                client = create_client_session(to);
                _clients.insert(client_sessions::value_type(to, client));
                new_client = true;
            }
        }

        // init connection if necessary
        if (new_client) 
            client->connect();

        // rpc call
        client->call(request, call);
    }