bool TCPServer::handleError(PSocketContext pSocketContext) { FastMutex::ScopedLock lock(_mtClients); auto* pClient = findClients(pSocketContext); if(nullptr == pClient) { return true;// 数据包过多可能造成该会话已经被清理掉 } auto errID = WSAGetLastError(); if(WAIT_TIMEOUT == errID) { if(!pClient->isAlive()) { LOG("网络超时!客户端离线"); removeClients(pClient); } else { LOG("网络超时!客户端在线"); } } else if(ERROR_NETNAME_DELETED == errID) { LOG("检测到客户端非正常离线"); removeClients(pClient); } else { SYSLOG("完成端口操作出现错误,线程退出", errID); return false; } return true; }
void TCPServer::handleClose(PSocketContext pSocketContext) { auto pClient = findClients(pSocketContext); LOG("客户端[%s-%d]正常离线", pClient->getPeerIP(), pClient->getPeerPort()); removeClients(pClient); }
void Application::newInstanceConnected() { DEBUG_LOG(("Application Info: new local socket connected")); for (QLocalSocket *client = server.nextPendingConnection(); client; client = server.nextPendingConnection()) { clients.push_back(ClientSocket(client, QByteArray())); connect(client, SIGNAL(readyRead()), this, SLOT(readClients())); connect(client, SIGNAL(disconnected()), this, SLOT(removeClients())); } }
void Application::closeApplication() { // close server server.close(); for (ClientSockets::iterator i = clients.begin(), e = clients.end(); i != e; ++i) { disconnect(i->first, SIGNAL(disconnected()), this, SLOT(removeClients())); i->first->close(); } clients.clear(); MTP::stop(); }