Exemplo n.º 1
0
void CLoginConn::Close()
{
    if (m_handle != NETLIB_INVALID_HANDLE) 
    {
        netlib_close(m_handle);
        if (m_conn_type == LOGIN_CONN_TYPE_CLIENT) 
        {
            g_client_conn_map.erase(m_handle);
        } 
        else 
        {
            g_msg_serv_conn_map.erase(m_handle);

            // remove all user count from this message server
            map<uint32_t, msg_serv_info_t*>::iterator it = g_msg_serv_info.find(m_handle);
            if (it != g_msg_serv_info.end()) 
            {
                msg_serv_info_t* pMsgServInfo = it->second;

                g_total_online_user_cnt -= pMsgServInfo->cur_conn_cnt;
                log("onclose from MsgServer: %s:%u ", pMsgServInfo->hostname.c_str(), pMsgServInfo->port);
                
                delete pMsgServInfo;
                g_msg_serv_info.erase(it);
            }
        }
    }

    ReleaseRef();
}
Exemplo n.º 2
0
void CRouteConn::_HandleFriendStatusNotify(CImPduFriendStatusNotify* pPdu)
{
	uint32_t from_user_id = pPdu->GetFromUserId();
	uint32_t from_user_status = pPdu->GetFromUserStatus();
	uint32_t friend_cnt = pPdu->GetFriendCnt();

	log("HandleFriendNotify, from_id=%u, status=%u, friend_cnt=%u\n", from_user_id, from_user_status,
        friend_cnt);
    if (from_user_status == USER_STATUS_OFFLINE) {
        UserStatMap_t::iterator it = g_rs_user_map.find(from_user_id);
        if (it != g_rs_user_map.end()) {
            uint32_t status = it->second.status;
            if (status != USER_STATUS_OFFLINE) {
                // user is still online, do not send status leave status to other
                return;
            }
        }
	}
	for (ConnMap_t::iterator it = g_route_conn_map.begin();  it != g_route_conn_map.end(); it++) {
		CRouteConn* pConn = (CRouteConn*)it->second;
		if (pConn) {
			pConn->SendPdu(pPdu);
		}
	}
}
Exemplo n.º 3
0
void CRouteConn::_BroadcastMsg(CImPdu* pPdu, CRouteConn* pFromConn)
{
	ConnMap_t::iterator it;
	for (it = g_route_conn_map.begin(); it != g_route_conn_map.end(); it++) {
		CRouteConn* pRouteConn = (CRouteConn*)it->second;
		if (pRouteConn != pFromConn) {
			pRouteConn->SendPdu(pPdu);
		}
	}
}
Exemplo n.º 4
0
void FileClientConnTimerCallback(void* callback_data, uint8_t msg, uint32_t handle, void* pParam) {
    uint64_t cur_time = get_tick_count();
    for (ConnMap_t::iterator it = g_file_client_conn_map.begin(); it != g_file_client_conn_map.end(); ) {
        ConnMap_t::iterator it_old = it;
        it++;
        
        FileClientConn* conn = (FileClientConn*)it_old->second;
        conn->OnTimer(cur_time);
    }
}
Exemplo n.º 5
0
void route_serv_timer_callback(void* callback_data, uint8_t msg, uint32_t handle, void* pParam)
{
	uint64_t cur_time = get_tick_count();
	for (ConnMap_t::iterator it = g_route_conn_map.begin(); it != g_route_conn_map.end(); ) {
		ConnMap_t::iterator it_old = it;
		it++;

		CRouteConn* pConn = (CRouteConn*)it_old->second;
		pConn->OnTimer(cur_time);
	}
}
Exemplo n.º 6
0
void FileMsgServerConn::OnConnect(net_handle_t handle) {
    m_handle = handle;
    
    g_file_msg_server_conn_map.insert(make_pair(handle, this));
    netlib_option(handle, NETLIB_OPT_SET_CALLBACK, (void*)imconn_callback);
    netlib_option(handle, NETLIB_OPT_SET_CALLBACK_DATA, (void*)&g_file_msg_server_conn_map);
}
Exemplo n.º 7
0
void CRouteConn::Close()
{
	if (m_handle != NETLIB_INVALID_HANDLE) {
		netlib_close(m_handle);
		g_route_conn_map.erase(m_handle);
	}

	// remove all user info from this MessageServer
	UserStatMap_t::iterator it_old;
	for (UserStatMap_t::iterator it = g_rs_user_map.begin(); it != g_rs_user_map.end(); ) {
		it_old = it;
		it++;
        
		RouteConnMap_t::iterator conn_it = it_old->second.conns.find(this);
		if (conn_it != it_old->second.conns.end()) {
			it_old->second.conns.erase(conn_it);
            
			if (it_old->second.conns.empty()) {
				g_rs_user_map.erase(it_old);
			}
		}
	}

	ReleaseRef();
}
Exemplo n.º 8
0
void CRouteConn::Close()
{
	if (m_handle != NETLIB_INVALID_HANDLE) {
		netlib_close(m_handle);
		g_route_conn_map.erase(m_handle);
	}

	// remove all user info from this MessageServer
    
    UserInfoMap_t::iterator it_old;
    for (UserInfoMap_t::iterator it = g_user_map.begin(); it != g_user_map.end(); )
    {
        it_old = it;
        it++;
        
        CUserInfo* pUser = it_old->second;
        pUser->RemoveRouteConn(this);
        if (pUser->GetRouteConnCount() == 0)
        {
            delete pUser;
            pUser = NULL;
            g_user_map.erase(it_old);
        }
    }

	ReleaseRef();
}
Exemplo n.º 9
0
net_handle_t ClientConn::connect(const string& strIp, uint16_t nPort, const string& strName, const string& strPass)
{
	m_handle = netlib_connect(strIp.c_str(), nPort, imconn_callback, &g_client_conn_map);
	if(m_handle != NETLIB_INVALID_HANDLE)
		g_client_conn_map.insert(make_pair(m_handle, this));
    return  m_handle;
}
Exemplo n.º 10
0
void route_server_conn_timer_callback(void* callback_data, uint8_t msg, uint32_t handle, void* pParam)
{
	ConnMap_t::iterator it_old;
	CRouteServConn* pConn = NULL;
	uint64_t cur_time = get_tick_count();

	for (ConnMap_t::iterator it = g_route_server_conn_map.begin(); it != g_route_server_conn_map.end(); ) {
        it_old = it;
        it++;
        pConn = (CRouteServConn*)it_old->second;
        pConn->OnTimer(cur_time);
	}

	// reconnect RouteServer
	serv_check_reconnect<CRouteServConn>(g_route_server_list, g_route_server_count);
}
Exemplo n.º 11
0
void ClientConn::Close()
{
	log("clientconn close from handle = %d\n", m_handle);
	if (m_handle != NETLIB_INVALID_HANDLE) {
		netlib_close(m_handle);
		g_client_conn_map.erase(m_handle);
	}
	ReleaseRef();
}
Exemplo n.º 12
0
void CRouteConn::OnConnect(net_handle_t handle)
{
	m_handle = handle;

	g_route_conn_map.insert(make_pair(handle, this));

	netlib_option(handle, NETLIB_OPT_SET_CALLBACK, (void*)imconn_callback);
	netlib_option(handle, NETLIB_OPT_SET_CALLBACK_DATA, (void*)&g_route_conn_map);
}
Exemplo n.º 13
0
static void db_server_conn_timer_callback(void* callback_data, uint8_t msg, uint32_t handle, void* pParam)
{
	ConnMap_t::iterator it_old;
	CDBServConn* pConn = NULL;
	uint64_t cur_time = get_tick_count();

	for (ConnMap_t::iterator it = g_db_server_conn_map.begin(); it != g_db_server_conn_map.end(); ) {
		it_old = it;
		it++;

		pConn = (CDBServConn*)it_old->second;
		if (pConn->IsOpen()) {
			pConn->OnTimer(cur_time);
		}
	}

	// reconnect DB Storage Server
	// will reconnect in 4s, 8s, 16s, 32s, 64s, 4s 8s ...
	serv_check_reconnect<CDBServConn>(g_db_server_list, g_db_server_count);
}
Exemplo n.º 14
0
void CRouteServConn::Connect(const char* server_ip, uint16_t server_port, uint32_t idx)
{
	log("Connecting to RouteServer %s:%d\n", server_ip, server_port);

	m_serv_idx = idx;
	m_handle = netlib_connect(server_ip, server_port, imconn_callback, (void*)&g_route_server_conn_map);

	if (m_handle != NETLIB_INVALID_HANDLE) {
		g_route_server_conn_map.insert(make_pair(m_handle, this));
	}
}
Exemplo n.º 15
0
void login_conn_timer_callback(void* callback_data, uint8_t msg, uint32_t handle, void* pParam)
{
	//test
	uint64_t cur_time = get_tick_count();
	for (ConnMap_t::iterator it = g_client_conn_map.begin(); it != g_client_conn_map.end(); ) {
		ConnMap_t::iterator it_old = it;
		it++;

		CLoginConn* pConn = (CLoginConn*)it_old->second;
		pConn->OnTimer(cur_time);
	}

	for (ConnMap_t::iterator it = g_msg_serv_conn_map.begin(); it != g_msg_serv_conn_map.end(); ) {
		ConnMap_t::iterator it_old = it;
		it++;

		CLoginConn* pConn = (CLoginConn*)it_old->second;
		pConn->OnTimer(cur_time);
	}
}
Exemplo n.º 16
0
void CDBServConn::Close()
{
	// reset server information for the next connect
	serv_reset<CDBServConn>(g_db_server_list, g_db_server_count, m_serv_idx);

	if (m_handle != NETLIB_INVALID_HANDLE) {
		netlib_close(m_handle);
		g_db_server_conn_map.erase(m_handle);
	}

	ReleaseRef();
}
Exemplo n.º 17
0
void FileMsgServerConn::Close() {
    log("Close client, handle %d", m_handle);
    
    connected_ = false;
    
    if (m_handle != NETLIB_INVALID_HANDLE) {
        netlib_close(m_handle);
        g_file_msg_server_conn_map.erase(m_handle);
    }
    
    ReleaseRef();
}
Exemplo n.º 18
0
void CLoginServConn::Close()
{
    serv_reset<CLoginServConn>(g_login_server_list, g_login_server_count, m_serv_idx);

    if (m_handle != NETLIB_INVALID_HANDLE) 
    {
        netlib_close(m_handle);
        g_login_server_conn_map.erase(m_handle);
    }

    ReleaseRef();
}
Exemplo n.º 19
0
void FileClientConn::OnConnect(net_handle_t handle) {
    /// yunfan modify 2014.8.7
    m_handle = handle;
    
    g_file_client_conn_map.insert(make_pair(handle, this));
    netlib_option(handle, NETLIB_OPT_SET_CALLBACK, (void*)imconn_callback);
    netlib_option(handle, NETLIB_OPT_SET_CALLBACK_DATA, (void*)&g_file_client_conn_map);
    
    uint32_t socket_buf_size = NETLIB_MAX_SOCKET_BUF_SIZE;
    netlib_option(handle, NETLIB_OPT_SET_SEND_BUF_SIZE, &socket_buf_size);
    netlib_option(handle, NETLIB_OPT_SET_RECV_BUF_SIZE, &socket_buf_size);
    /// yunfan modify end
}
Exemplo n.º 20
0
//每隔一秒,这个函数就会被调用一次
void login_conn_timer_callback(void* callback_data, uint8_t msg, uint32_t handle, void* pParam)
{
	log("enter[%s]", __FUNCTION__);

	//两个conn_map里所有的连接都要调用一次OnTimer()
	uint64_t cur_time = get_tick_count();
	for (ConnMap_t::iterator it = g_client_conn_map.begin(); it != g_client_conn_map.end(); ) {
		ConnMap_t::iterator it_old = it;
		it++;

		CLoginConn* pConn = (CLoginConn*)it_old->second;
		pConn->OnTimer(cur_time);
	}

	for (ConnMap_t::iterator it = g_msg_serv_conn_map.begin(); it != g_msg_serv_conn_map.end(); ) {
		ConnMap_t::iterator it_old = it;
		it++;

		CLoginConn* pConn = (CLoginConn*)it_old->second;
		pConn->OnTimer(cur_time);
	}
	log("leave[%s]", __FUNCTION__);

}
Exemplo n.º 21
0
void CRouteServConn::Close()
{
	serv_reset<CRouteServConn>(g_route_server_list, g_route_server_count, m_serv_idx);

	m_bOpen = false;
	if (m_handle != NETLIB_INVALID_HANDLE) {
		netlib_close(m_handle);
		g_route_server_conn_map.erase(m_handle);
	}

	ReleaseRef();

	if (g_master_rs_conn == this) {
		update_master_route_serv_conn();
	}
}
Exemplo n.º 22
0
void CFileConn::Close()
{
    log("close client, handle %d", m_handle);
    
    m_bAuth = false;
    
	if (m_handle != NETLIB_INVALID_HANDLE) {
		netlib_close(m_handle);
		g_file_conn_map.erase(m_handle);
	}

	if (m_user_id > 0) {
		g_file_user_map.erase(m_user_id);
        m_user_id = 0;
	}

	ReleaseRef();
}
Exemplo n.º 23
0
void FileClientConn::Close() {
    log("close client, handle %d", m_handle);
    
    if (transfer_task_) {
        if (transfer_task_->GetTransMode() == FILE_TYPE_ONLINE) {
            transfer_task_->set_state(kTransferTaskStateInvalid);
            
//            CImConn* conn = transfer_task_->GetOpponentConn(user_id_);
//            if (conn) {
//                FileClientConn* conn2 = reinterpret_cast<FileClientConn*>(conn);
//                conn2->Close2();
//            }
            // Close2();
        } else {
            if (transfer_task_->state() >= kTransferTaskStateUploadEnd) {
                transfer_task_->set_state(kTransferTaskStateWaitingDownload);
            }
        }
        transfer_task_->SetConnByUserID(user_id_, NULL);

        TransferTaskManager::GetInstance()->DeleteTransferTaskByConnClose(transfer_task_->task_id());
        
        // 关闭另一个连接
//        if (transfer_task_->GetTransMode() == FILE_TYPE_ONLINE) {
//        }
        transfer_task_ = NULL;
    }
    auth_ = false;

    if (m_handle != NETLIB_INVALID_HANDLE) {
        netlib_close(m_handle);
        g_file_client_conn_map.erase(m_handle);
    }

//    if (user_id_ > 0) {
//        g_file_user_map.erase(m_user_id);
//        m_user_id = 0;
//    }
    
    ReleaseRef();
}