Beispiel #1
0
void Gateway::OnAccepted(SessionPtr pSession, const boost::system::error_code& error)
{
    if (!error)
    {
        boost::asio::ip::tcp::no_delay option(true);
        pSession->GetSocket().set_option(option);
        int64 sessionId = GenSessionId();
        int totalSessionNum = 0;
        pSession->SetSessionId(sessionId);
        {
            boost::mutex::scoped_lock lock(_mutexSessionMap);
            _sessions.insert(make_pair(sessionId, pSession));
            totalSessionNum = _sessions.size();
        }
        boost::system::error_code ec;
        ip::tcp::socket::endpoint_type endpoint = pSession->GetSocket().remote_endpoint(ec);
        pSession->Start();
        if (_onSessionOpenNew)
        {
            string ip = endpoint.address().to_string();
            _onSessionOpenNew(sessionId, ip.c_str(), totalSessionNum);
        }
    }

    if (!_bStopAccept)
        StartAccept();
}