Exemplo n.º 1
0
//! 当有连接断开,则被回调
int ffbroker_t::handle_broken_impl(socket_ptr_t sock_)
{
    if (NULL == sock_->get_data<session_data_t>())
    {
        sock_->safe_delete();
        return 0;
    }
    uint32_t node_id = sock_->get_data<session_data_t>()->get_node_id();
    if (node_id == BROKER_MASTER_NODE_ID && false == is_master())
    {
        //! slave 连接到master 的连接断开,重连
        //! 设置定时器重连
        m_broker_client_info.clear();
        m_timer.once_timer(RECONNECT_TO_BROKER_TIMEOUT, task_binder_t::gen(&route_call_reconnect, this));
    }
    else
    {
        m_slave_broker_sockets.erase(node_id);
        m_broker_client_info.erase(node_id);
    }

    if (is_master())
    {
        //! 如果是master, //!如果是slave broker断开连接,需要为原来的service重新分配slave broker
        sync_all_register_info(NULL);
    }
    delete sock_->get_data<session_data_t>();
    sock_->set_data(NULL);
    sock_->safe_delete();
    return 0;
}
Exemplo n.º 2
0
//! 处理连接断开
int ffgate_t::handle_broken_impl(socket_ptr_t sock_)
{
    LOGTRACE((FFGATE, "ffgate_t::broken begin"));
    session_data_t* session_data = sock_->get_data<session_data_t>();
    if (NULL == session_data)
    {
        sock_->safe_delete();
        return 0;
    }
    
    if (false == session_data->is_valid())
    {
        //! 还未通过验证
        m_wait_verify_set.erase(sock_);
    }
    else
    {
        client_info_t& client_info = m_client_set[session_data->id()];
        if (client_info.sock == sock_)
        {
            session_offline_t::in_t msg;
            msg.session_id  = session_data->id();
            msg.online_time = session_data->online_time;
            m_ffrpc->call(DEFAULT_LOGIC_SERVICE, msg);
            m_client_set.erase(session_data->id());
        }
    }
    LOGTRACE((FFGATE, "ffgate_t::broken session_id[%s]", session_data->id()));
    delete session_data;
    sock_->set_data(NULL);
    sock_->safe_delete();
    return 0;
}
Exemplo n.º 3
0
//! 处理连接断开
int ffgate_t::handle_broken(socket_ptr_t sock_)
{
    session_data_t* session_data = sock_->get_data<session_data_t>();
    if (NULL == session_data)
    {
        LOGDEBUG((FFGATE, "ffgate_t::broken ignore"));
        sock_->safe_delete();
        return 0;
    }
    
    LOGTRACE((FFGATE, "ffgate_t::broken begin"));
    if (false == session_data->is_valid())
    {
        //! 还未通过验证
        m_wait_verify_set.erase(session_data->socket_id);
    }
    else
    {
        client_info_t& client_info = m_client_set[session_data->id()];
        if (client_info.sock == sock_)
        {
            session_offline_t::in_t msg;
            msg.session_id  = session_data->id();
            m_ffrpc->call(client_info.alloc_logic_service, msg);
            m_client_set.erase(session_data->id());
        }
    }
    LOGTRACE((FFGATE, "ffgate_t::broken session_id[%ld]", session_data->id()));
    delete session_data;
    sock_->set_data(NULL);
    sock_->safe_delete();
    return 0;
}
Exemplo n.º 4
0
int msg_bus_t::handle_broken(socket_ptr_t sock_)
{
    lock_guard_t lock(m_mutex);
    if (m_socket == sock_)
    {
        m_socket = NULL;
    }

    sock_->safe_delete();
    return 0;    
}
Exemplo n.º 5
0
int ffrpc_t::handle_broken_impl(socket_ptr_t sock_)
{
    if (NULL == sock_->get_data<session_data_t>())
    {
        sock_->safe_delete();
        return 0;
    }
    if (BROKER_MASTER_NODE_ID == sock_->get_data<session_data_t>()->get_node_id())
    {
        m_master_broker_sock = NULL;
        //! 连接到broker master的连接断开了
        map<uint32_t, slave_broker_info_t>::iterator it = m_slave_broker_sockets.begin();//! node id -> info
        for (; it != m_slave_broker_sockets.end(); ++it)
        {
            slave_broker_info_t& slave_broker_info = it->second;
            delete slave_broker_info.sock->get_data<session_data_t>();
            slave_broker_info.sock->set_data(NULL);
            slave_broker_info.sock->close();
        }
        m_slave_broker_sockets.clear();//! 所有连接到broker slave的连接断开
        m_ffslot_interface.clear();//! 注册的接口清除
        m_ffslot_callback.clear();//! 回调函数清除
        m_msg2id.clear();//! 消息映射表清除
        m_broker_client_info.clear();//! 各个服务的记录表清除
        m_broker_client_name2nodeid.clear();//! 服务名到node id的映射
        //! 设置定时器重练
        m_timer.once_timer(RECONNECT_TO_BROKER_TIMEOUT, task_binder_t::gen(&route_call_reconnect, this));
    }
    else
    {
        m_slave_broker_sockets.erase(sock_->get_data<session_data_t>()->get_node_id());
    }
    delete sock_->get_data<session_data_t>();
    sock_->set_data(NULL);
    sock_->safe_delete();
    return 0;
}
Exemplo n.º 6
0
int broker_service_t::handle_broken(socket_ptr_t sock_)
{
    logwarn((BROKER, "broker_service_t::handle_broken bagin soket_ptr<%p>", sock_));
    lock_guard_t lock(m_mutex);

    vector<uint32_t> del_sgid;
    vector<uint32_t> del_sid;
    vector<uint32_t> del_callback_uuid;

    service_obj_map_t::iterator it = m_service_obj_mgr.begin();
    for (; it != m_service_obj_mgr.end(); ++it)
    {
        map<uint16_t, service_obj_t>::iterator it2 = it->second.service_objs.begin();
        for (; it2 != it->second.service_objs.end(); ++it2)
        {
            callback_map_t::iterator uuid_it = it2->second.m_callback_map.begin();
            for (; uuid_it != it2->second.m_callback_map.end(); ++uuid_it)
            {
                if (uuid_it->second.socket_ptr == sock_)
                {
                    del_callback_uuid.push_back(uuid_it->first);
                }
            }
            
            if (it2->second.socket_ptr == sock_)
            {
                del_sgid.push_back(it->first);
                del_sid.push_back(it2->first);
            }
            
            //! del all tmp callback uuid
            for (size_t i = 0; i < del_callback_uuid.size(); ++i)
            {
                it2->second.m_callback_map.erase(del_callback_uuid[i]);
            }
            del_callback_uuid.clear();
        }
    }
    
    for (size_t i = 0; i < del_sgid.size(); ++i)
    {
        logwarn((BROKER, "broker_service_t::handle_broken del sgid[%u], sid[%u]", del_sgid[i], del_sid[i]));
        m_service_obj_mgr[del_sgid[i]].service_objs.erase(del_sid[i]);
        if (m_service_obj_mgr[del_sgid[i]].service_objs.empty())
        {
            m_service_obj_mgr.erase(del_sgid[i]);
            logwarn((BROKER, "broker_service_t::handle_broken del sgid[%u]", del_sgid[i]));
        }
    }
    
    if (NULL != sock_->get_data<socket_session_info_t>())
    {
        for (vector<string>::iterator vit = m_all_slave_host.begin(); vit != m_all_slave_host.end(); ++vit)
        {
            if (*vit == sock_->get_data<socket_session_info_t>()->slave_host)
            {
                m_all_slave_host.erase(vit);
                break;
            }
        }

        delete sock_->get_data<socket_session_info_t>();
        sock_->set_data(NULL);
    }

    sock_->safe_delete();
    m_all_sockets.erase(sock_);

    logwarn((BROKER, "broker_service_t::handle_broken en ok"));
    return 0;
}