Error Socket::Disconnect() const { if (!socket_) { return Error(LNR_EBADF); } const linear::Addrinfo& self = GetSelfInfo(); const linear::Addrinfo& peer = GetPeerInfo(); LINEAR_LOG(LOG_DEBUG, "try to disconnect(id = %d): %s:%d x-- %s --- %s:%d", GetId(), (self.proto == Addrinfo::IPv4) ? self.addr.c_str() : (std::string("[" + self.addr + "]")).c_str(), self.port, GetTypeString(GetType()).c_str(), (peer.proto == Addrinfo::IPv4) ? peer.addr.c_str() : (std::string("[" + peer.addr + "]")).c_str(), peer.port); return socket_->Disconnect(); }
/************************************************************************ 配对标签查找函数 FindMatchInfo 参数: cText 信息串 cInfoProperty 标签串 nLen 标签长度,最大为4 返回: 匹配: 1(true) 无匹配: 0(false) 备注: 1、本函数用于查找标签结尾配对. ************************************************************************/ int CXMLParser::FindMatchInfo(char *cText, char *cInfoProperty, int nLen) { int n = 0; int nCnt = 0; switch(nLen) { case 1: if(!cText[0] || !cText[1]) { return 0; } while(cText[n + 1]) { if((cText[n] == cInfoProperty[0] || cText[n] == cInfoProperty[0] - 32) && cText[n + 1] == '>' && cText[n - 1] == '<') { //登记查到的新的同类型信息,若同类型信息总数为偶数,即为不匹配 nCnt++; n += 2; int nMatch = GetSelfInfo(cText + n); if(nMatch > 0) { nCnt--; } continue; } if(cText[n] == '/' && (cText[n + 1] == cInfoProperty[0] || cText[n + 1] == cInfoProperty[0] - 32)) { //查到匹配信息 if(!nCnt) { return 1; } nCnt--; } n++; } break; case 2: if(!cText[0] || !cText[1] || !cText[2]) { return 0; } while(cText[n + 2]) { if((cText[n] == cInfoProperty[0] || cText[n] == cInfoProperty[0] - 32) && (cText[n + 1] == cInfoProperty[1] || cText[n + 1] == cInfoProperty[1] - 32) && cText[n - 1] == '<') { //登记查到的新的同类型信息,若同类型信息总数为偶数,即为不匹配 nCnt++; n += 3; int nMatch = GetSelfInfo(cText + n); if(nMatch > 0) { nCnt--; } continue; } if(cText[n] == '/' && (cText[n + 1] == cInfoProperty[0] - 32 || cText[n + 1] == cInfoProperty[0]) && (cText[n + 2] == cInfoProperty[1] - 32 || cText[n + 2] == cInfoProperty[1]) && cText[n - 1] == '<') { //查到匹配信息 if(!nCnt) { return 1; } nCnt--; } n++; } break; case 3: if(!cText[0] || !cText[1] || !cText[2] || !cText[3]) { return 0; } while(cText[n + 3]) { if((cText[n] == cInfoProperty[0] + 32 || cText[n] == cInfoProperty[0]) && (cText[n + 1] == cInfoProperty[1] - 32 || cText[n + 1] == cInfoProperty[1]) && (cText[n + 2] == cInfoProperty[2] - 32 || cText[n + 2] == cInfoProperty[2]) && cText[n - 1] == '<') { //登记查到的新的同类型信息,若同类型信息总数为偶数,即为不匹配 nCnt++; n += 4; int nMatch = GetSelfInfo(cText + n); if(nMatch > 0) { nCnt--; } continue; } if(cText[n] == '/' && (cText[n + 1] == cInfoProperty[0] - 32 || cText[n + 1] == cInfoProperty[0]) && (cText[n + 2] == cInfoProperty[1] - 32 || cText[n + 2] == cInfoProperty[1]) && (cText[n + 3] == cInfoProperty[2] - 32 || cText[n + 3] == cInfoProperty[2]) && cText[n - 1] == '<') { //查到匹配信息 if(!nCnt) { return 1; } nCnt--; } n++; } break; case 4: if(!cText[0] || !cText[1] || !cText[2] || !cText[3] || !cText[4]) { return 0; } while(cText[n + 4]) { if((cText[n] == cInfoProperty[0] + 32 || cText[n] == cInfoProperty[0]) && (cText[n + 1] == cInfoProperty[1] - 32 || cText[n + 1] == cInfoProperty[1]) && (cText[n + 2] == cInfoProperty[2] - 32 || cText[n + 2] == cInfoProperty[2]) && (cText[n + 3] == cInfoProperty[3] - 32 || cText[n + 3] == cInfoProperty[3]) && cText[n - 1] == '<') { //登记查到的新的同类型信息,若同类型信息总数为偶数,即为不匹配 nCnt++; n += 5; int nMatch = GetSelfInfo(cText + n); if(nMatch > 0) { nCnt--; } continue; } if(cText[n] == '/' && (cText[n + 1] == cInfoProperty[0] - 32 || cText[n + 1] == cInfoProperty[0]) && (cText[n + 2] == cInfoProperty[1] - 32 || cText[n + 2] == cInfoProperty[1]) && (cText[n + 3] == cInfoProperty[2] - 32 || cText[n + 3] == cInfoProperty[2]) && (cText[n + 4] == cInfoProperty[3] - 32 || cText[n + 4] == cInfoProperty[3]) && cText[n - 1] == '<') { //查到匹配信息 if(!nCnt) { return 1; } nCnt--; } n++; } break; } return 0;//无匹配 }