当前位置: 首页>>代码示例>>C++>>正文


C++ TcpSessionPtr类代码示例

本文整理汇总了C++中TcpSessionPtr的典型用法代码示例。如果您正苦于以下问题:C++ TcpSessionPtr类的具体用法?C++ TcpSessionPtr怎么用?C++ TcpSessionPtr使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了TcpSessionPtr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: dispatchOnSessionEstablished

void MessageDispatcher::dispatchOnSessionEstablished(TcpSessionPtr  session)
{
    if (_vctOnSessionEstablished.empty())
    {
        return;
    }
    for (auto &fun : _vctOnSessionEstablished)
    {
        try
        {
            LCT("Entry dispatchOnSessionEstablished SessionID=" << session->getSessionID());
            fun(session);
            LCT("Leave dispatchOnSessionEstablished SessionID=" << session->getSessionID());
        }
        
        catch (std::runtime_error e)
        {
            LCE("Leave dispatchOnSessionEstablished Runtime Error: SessionID=" << session->getSessionID() << ", Error Message=\"" << e.what() << "\"");
        }
        catch (...)
        {
            LCE("Leave dispatchOnSessionEstablished Unknown Runtime Error: SessionID=" << session->getSessionID());
        }
    }
}
开发者ID:jimmy486,项目名称:zsummerX,代码行数:25,代码来源:dispatch.cpp

示例2: dispatchPreSessionMessage

bool MessageDispatcher::dispatchPreSessionMessage(TcpSessionPtr session, const char * blockBegin, zsummer::proto4z::Integer blockSize)
{
    if (_vctPreSessionDispatch.empty())
    {
        return true;
    }
    
    try
    {
        for (auto & fun : _vctPreSessionDispatch)
        {
            LCT("Entry dispatchOrgSessionMessage  SessionID=" << session->getSessionID() << ", blockSize=" << blockSize);
            if (!fun(session, blockBegin, blockSize))
            {
                return false;
            }
        }
    }
    catch (std::runtime_error e)
    {
        LCE("Leave dispatchOrgSessionMessage With Runtime Error:  SessionID=" << session->getSessionID() << ", Error Message=\"" << e.what() << "\"");
        return false;
    }
    catch (...)
    {
        LCE("Leave dispatchOrgSessionMessage With Unknown Runtime Error: SessionID=" << session->getSessionID());
        return false;
    }
    return true;
}
开发者ID:jimmy486,项目名称:zsummerX,代码行数:30,代码来源:dispatch.cpp

示例3: event_onSessionDisconnect

void NetManager::event_onSessionDisconnect(TcpSessionPtr session)
{
	LOGT("NetManager::event_onSessionDisconnect. SessionID=" << session->getSessionID() << ", remoteIP=" << session->getRemoteIP() << ", remotePort=" << session->getRemotePort());

	if (isConnectID(session->getSessionID()))
	{
	}
	else
	{
		if (session->getUserParam() == SS_LOGINED)
		{
			auto info = UserManager::getRef().getInnerUserInfoBySID(session->getSessionID());
			if (info)
			{
				UserManager::getRef().userLogout(info);
				info->sID = InvalidSeesionID;
			}
		}

	}

	if (UserManager::getRef().getAllOnlineUserCount() == 0 && _onSafeClosed)
	{
		SessionManager::getRef().post(_onSafeClosed);
		_onSafeClosed = nullptr;
	}
}
开发者ID:heber,项目名称:breeze,代码行数:27,代码来源:netManager.cpp

示例4: msg_onHeartbeatEcho

void NetMgr::msg_onHeartbeatEcho(TcpSessionPtr session, ReadStream & rs)
{
    auto status = session->getUserParamNumber(UPARAM_SESSION_STATUS);
    if (status != SSTATUS_UNKNOW && status != SSTATUS_PLAT_LOGINING)
    {
        session->setUserParam(UPARAM_LAST_ACTIVE_TIME, time(NULL));
    }
}
开发者ID:roger912,项目名称:breeze,代码行数:8,代码来源:netMgr.cpp

示例5: createTCPSession

	void XAsioTCPServer::processAccept()
	{
		if ( m_acceptor )
		{
			TcpSessionPtr session = createTCPSession();
			m_acceptor->async_accept( *session->getSocket(), 
				m_strand.wrap( boost::bind( &XAsioTCPServer::onAcceptCallback, shared_from_this(), 
				session, boost::asio::placeholders::error ) ));
		}		
	}
开发者ID:tryangx,项目名称:asiowrapper,代码行数:10,代码来源:XAsioTCPServer.cpp

示例6: OnSessionPulse

 void OnSessionPulse(TcpSessionPtr session, unsigned int pulseInterval)
 {
     if (time(NULL) - session->getUserLParam() > pulseInterval/1000 * 3)
     {
         LOGI("remote session timeout. sID=" << session->getSessionID() << ", timeout=" << time(NULL) - session->getUserLParam());
         SessionManager::getRef().kickSession(session->getSessionID());
         return;
     }
     WriteStream pack(ID_Pulse);
     SessionManager::getRef().sendSessionData(session->getSessionID(), pack.getStream(), pack.getStreamLen());
 
 }
开发者ID:jimmy486,项目名称:zsummerX,代码行数:12,代码来源:FrameStressMain.cpp

示例7: connectHandle

void TcpServer::connectHandle(const error_code &err, const TcpSessionPtr &session)
{
    cout << err.message() << endl;
    if (!err)
    {
        m_tcpSessions.push_back(session);
        session->start();
        start();
    }
    else
    {
        session->close();
    }
}
开发者ID:zhugp125,项目名称:C_C_plus_plus,代码行数:14,代码来源:TcpServer.cpp

示例8: if

void SessionManager::removeSession(TcpSessionPtr session)
{
    _mapTcpSessionPtr.erase(session->getSessionID());
    if (session->getAcceptID() != InvalidAccepterID)
    {
        _mapAccepterOptions[session->getAcceptID()]._currentLinked--;
        _mapAccepterOptions[session->getAcceptID()]._totalAcceptCount++;
    }

    if (_stopClients == 2 || _stopServers == 2)
    {
        int clients = 0;
        int servers = 0;
        for (auto & kv : _mapTcpSessionPtr)
        {
            if (isSessionID(kv.first))
            {
                clients++;
            }
            else if (isConnectID(kv.first))
            {
                servers++;
            }
            else
            {
                LCE("error. invalid session id in _mapTcpSessionPtr");
            }
        }
        if (_stopClients == 2)
        {
            _stopClients = 3;
            if (_funClientsStop)
            {
                auto temp = std::move(_funClientsStop);
                temp();
            }
        }
        if (_stopServers == 2)
        {
            _stopServers = 3;
            if (_funServerStop)
            {
                auto temp = std::move(_funServerStop);
                temp();
            }
        }
    }
    
}
开发者ID:roger912,项目名称:zsummerX,代码行数:49,代码来源:manager.cpp

示例9: event_onSessionPulse

void NetMgr::event_onSessionPulse(TcpSessionPtr session)
{
    if (isSessionID(session->getSessionID()))
    {
        if (time(NULL) - session->getUserParamNumber(UPARAM_LAST_ACTIVE_TIME) > session->getOptions()._sessionPulseInterval / 1000 * 2)
        {
            session->close();
            return;
        }
        Heartbeat hb;
        hb.timeStamp = (ui32)time(NULL);
        hb.timeTick = (unsigned int)getNowTick();
        sendMessage(session, hb);
    }
}
开发者ID:roger912,项目名称:breeze,代码行数:15,代码来源:netMgr.cpp

示例10: _onSessionLinked

static void _onSessionLinked(lua_State * L, TcpSessionPtr session)
{
    lua_pushcfunction(L, pcall_error);
    lua_rawgeti(L, LUA_REGISTRYINDEX, _linkedRef);
    lua_pushnumber(L, session->getSessionID());
    lua_pushstring(L, session->getRemoteIP().c_str());
    lua_pushnumber(L, session->getRemotePort());
    int status = lua_pcall(L, 3, 0, 1);
    lua_remove(L, 1);
    if (status)
    {
        const char *msg = lua_tostring(L, -1);
        if (msg == NULL) msg = "(error object is not a string)";
        LOGE(msg);
        lua_pop(L, 1);
    }
}
开发者ID:ZhuOS,项目名称:breeze,代码行数:17,代码来源:summer.cpp

示例11: event_onClosed

void NetMgr::event_onClosed(TcpSessionPtr session)
{
    LOGD("NetMgr::event_onClosed. SessionID=" << session->getSessionID() << ", remoteIP=" << session->getRemoteIP() << ", remotePort=" << session->getRemotePort());

    if (isConnectID(session->getSessionID()))
    {
    }
    else
    {
        if (session->getUserParamNumber(UPARAM_SESSION_STATUS) == SSTATUS_LOGINED)
        {
            auto founder = _mapUserInfo.find(session->getUserParamNumber(UPARAM_USER_ID));
            if (founder == _mapUserInfo.end() || founder->second->sID != session->getSessionID())
            {
                _mapSession.erase(session->getSessionID());
                return;
            }
            
            event_onLogout(founder->second);
            founder->second->sID = InvalidSessionID;
        }
        _mapSession.erase(session->getSessionID());
    }

    if (_mapSession.size() == 0 && _onSafeClosed)
    {
        SessionManager::getRef().post(_onSafeClosed);
        _onSafeClosed = nullptr;
    }
}
开发者ID:roger912,项目名称:breeze,代码行数:30,代码来源:netMgr.cpp

示例12: msg_onAttachLogicReq

void NetMgr::msg_onAttachLogicReq(TcpSessionPtr session, ReadStream & rs)
{
    if (std::get<TupleParamNumber>(session->getUserParam(UPARAM_SESSION_STATUS)) != SSTATUS_UNKNOW)
    {
        return;
    }
    
    AttachLogicAck ack;
    ack.retCode = EC_SUCCESS;
    AttachLogicReq req;
    rs >> req;
    LOGD("enter msg_loginReq token=" << req.token << ", uID=" << req.uID);
    do 
    {
        auto info = getUserInfo(req.uID);
        if (!info)
        {
            ack.retCode = EC_TARGET_NOT_EXIST;
            break;
        }
        if (info->token.token != req.token)
        {
            ack.retCode = EC_PERMISSION_DENIED;
            break;
        }
        if (info->token.expire < time(NULL))
        {
            ack.retCode = EC_REQUEST_EXPIRE;
            break;
        }

        if (info->sID != InvalidSessionID)
        {
            event_onLogout(info);
            SessionManager::getRef().kickSession(info->sID);
            _mapSession.erase(info->sID);
        }

        info->sID = session->getSessionID();
        session->setUserParam(UPARAM_USER_ID, info->base.uID);
        session->setUserParam(UPARAM_SESSION_STATUS, SSTATUS_LOGINED);
        session->setUserParam(UPARAM_LAST_ACTIVE_TIME, time(NULL));
        session->setUserParam(UPARAM_LOGIN_TIME, time(NULL));
        _mapSession.insert(std::make_pair(session->getSessionID(), info));

        sendMessage(session, ack);
        session->setUserParam(UPARAM_LAST_ACTIVE_TIME, time(NULL));

        event_onLogin(info);
        
        return;
    } while (0);
    
    sendMessage(session, ack);
}
开发者ID:roger912,项目名称:breeze,代码行数:55,代码来源:netMgr.cpp

示例13: _onWebMessage

//param: sID, {key=,value=}, {head kv}, body
static void _onWebMessage(lua_State * L, TcpSessionPtr session, const zsummer::network::PairString & commonLine,
                          const MapString &head, const std::string & body)
{
    lua_pushcfunction(L, pcall_error);
    lua_rawgeti(L, LUA_REGISTRYINDEX, _webMessageRef);
    lua_pushinteger(L, session->getSessionID());
    lua_newtable(L);
    lua_pushstring(L, commonLine.first.c_str());
    lua_setfield(L, -2, "key");
    lua_pushstring(L, commonLine.second.c_str());
    lua_setfield(L, -2, "value");
    lua_newtable(L);
    bool needUrlDecode = false;
    for (auto & hd : head)
    {
        lua_pushstring(L, hd.second.c_str());
        lua_setfield(L, -2, hd.first.c_str());
        if(hd.first.find("Content-Type") != std::string::npos
           && hd.second.find("application/x-www-form-urlencoded") != std::string::npos)
        {
            needUrlDecode = true;
        }
    }
    if (needUrlDecode)
    {
        std::string de = zsummer::proto4z::urlDecode(body);
        lua_pushlstring(L, de.c_str(), de.length());
    }
    else
    {
        lua_pushlstring(L, body.c_str(), body.length());
    }
    int status = lua_pcall(L, 4, 0, 1);
    lua_remove(L, 1);
    if (status)
    {
        const char *msg = lua_tostring(L, -1);
        if (msg == NULL) msg = "(error object is not a string)";
        LOGE("code crash when process web message. sID=" << session->getSessionID()
            << ", commond line=" << commonLine.first << " " << commonLine.second << ", body(max500byte)=" << body.substr(0, 500)
            << ", head=" << head);
        LOGE(msg);
        lua_pop(L, 1);
    }
}
开发者ID:ZhuOS,项目名称:breeze,代码行数:46,代码来源:summer.cpp

示例14: event_onSessionPulse

void NetManager::event_onSessionPulse(TcpSessionPtr session, unsigned int pulseInterval)
{
	if (isSessionID(session->getSessionID()))
	{
		if (session->getUserLParam() == SS_LOGINED || time(NULL) - session->getUserRParam() > pulseInterval * 2)
		{
			session->close();
			return;
		}

		WriteStream ws(ID_Heartbeat);
		Heartbeat hb;
		hb.timeStamp = (ui32)time(NULL);
		hb.timeTick = getNowTick();
		ws << hb;
		session->doSend(ws.getStream(), ws.getStreamLen());
	}
}
开发者ID:heber,项目名称:breeze,代码行数:18,代码来源:netManager.cpp

示例15: msg_ResultSequence_fun

    void msg_ResultSequence_fun(TcpSessionPtr session, ReadStream & rs)
    {
        if (g_hightBenchmark)
        {
            session->doSend(rs.getStream(), rs.getStreamLen());
        }
        else
        {
            EchoPack pack;
            rs >> pack;

            if (g_sendType == 0 || g_intervalMs == 0) //echo send
            {
                WriteStream ws(ID_EchoPack);
                ws << pack;
                session->doSend(ws.getStream(), ws.getStreamLen());
            }
        }
    };
开发者ID:jimmy486,项目名称:zsummerX,代码行数:19,代码来源:FrameStressMain.cpp


注:本文中的TcpSessionPtr类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。