Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fileserver程序崩溃问题 #45

Open
fangyixing opened this issue Sep 29, 2020 · 0 comments
Open

fileserver程序崩溃问题 #45

fangyixing opened this issue Sep 29, 2020 · 0 comments

Comments

@fangyixing
Copy link

fangyixing commented Sep 29, 2020

问题描述:A发送文件给B,同时C发送文件给D,其中任何一组发送完成都会导致fileserver服务崩溃。
问题原因:FileServer::onDisconnected 函数逻辑错误,任何会话完成传输都会清理掉其他会话。
我的解决方法:

void FileServer::onDisconnected(const std::shared_ptr<TcpConnection>& conn)
{
    std::lock_guard<std::mutex> guard(m_sessionMutex);
    for (auto iter = m_sessions.begin(); iter != m_sessions.end(); ++iter)
    {
        if ((*iter)->getConnectionPtr() == NULL)
        {
            LOGE("connection is NULL");
            continue;
        }
        if ((*iter)->getConnectionPtr() == conn)
        {
            //用户下线
            m_sessions.erase(iter);
            //bUserOffline = true;
            LOGI("client disconnected: %s", conn->peerAddress().toIpPort().c_str());
            break;
        }
    }    
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant