本文整理汇总了C++中Transport::close方法的典型用法代码示例。如果您正苦于以下问题:C++ Transport::close方法的具体用法?C++ Transport::close怎么用?C++ Transport::close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Transport
的用法示例。
在下文中一共展示了Transport::close方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: UDTsend
int CGMP::UDTsend(const char* ip, const int& port, CGMPMessage* msg)
{
Transport t;
if (t.open(m_iUDTReusePort, false, true) < 0)
return -1;
if (t.connect(ip, port) < 0)
{
t.close();
return -1;
}
if ((t.send((char*)(&m_iPort), 4) < 0) || (t.send((char*)(msg->m_piHeader), 16) < 0) || (t.send((char*)&(msg->m_iLength), 4) < 0))
{
t.close();
return -1;
}
if (t.send(msg->m_pcData, msg->m_iLength) < 0)
{
t.close();
return -1;
}
t.close();
return 16 + msg->m_iLength;
}
示例2: udtRcvHandler
DWORD WINAPI CGMP::udtRcvHandler(LPVOID s)
#endif
{
CGMP* self = (CGMP*)s;
Transport t;
sockaddr_in addr;
int namelen = sizeof(sockaddr_in);
int32_t header[4];
while (!self->m_bClosed)
{
if (self->m_UDTSocket.accept(t, (sockaddr*)&addr, &namelen) < 0)
continue;
int port;
if (t.recv((char*)&port, 4) < 0)
{
t.close();
continue;
}
// recv "header" information
if (t.recv((char*)header, 16) < 0)
{
t.close();
continue;
}
CMsgRecord* rec = new CMsgRecord;
char tmp[64]="";
udt_inet_ntop(AF_INET, &(addr.sin_addr), tmp, 64);
rec->m_strIP = tmp;
rec->m_iPort = port;
rec->m_pMsg = new CGMPMessage;
//rec->m_pMsg->m_iType = type;
rec->m_pMsg->m_iSession = header[1];
rec->m_pMsg->m_iID = header[2];
rec->m_pMsg->m_iInfo = header[3];
// recv parameter size
if (t.recv((char*)&(rec->m_pMsg->m_iLength), 4) < 0)
{
t.close();
delete rec->m_pMsg;
delete rec;
continue;
}
rec->m_pMsg->m_pcData = new char[rec->m_pMsg->m_iLength];
if (t.recv(rec->m_pMsg->m_pcData, rec->m_pMsg->m_iLength) < 0)
{
t.close();
delete rec->m_pMsg;
delete rec;
continue;
}
t.close();
if (self->m_PeerHistory.hit(rec->m_strIP, rec->m_iPort, rec->m_pMsg->m_iSession, rec->m_pMsg->m_iID))
continue;
self->m_PeerHistory.insert(rec->m_strIP, rec->m_iPort, rec->m_pMsg->m_iSession, rec->m_pMsg->m_iID);
if (0 == header[3])
{
{
CMutexGuard guard (self->m_RcvQueueLock);
self->m_qRcvQueue.push(rec);
}
#ifndef WIN32
pthread_cond_signal(&self->m_RcvQueueCond);
#else
SetEvent(self->m_RcvQueueCond);
#endif
}
else
{
{
CMutexGuard guard (self->m_ResQueueLock);
self->m_mResQueue[header[3]] = rec;
}
#ifndef WIN32
pthread_cond_signal(&self->m_ResQueueCond);
#else
SetEvent(self->m_ResQueueCond);
#endif
}
}
#ifndef WIN32
pthread_cond_signal(&self->m_RcvQueueCond);
pthread_cond_signal(&self->m_ResQueueCond);
#else
SetEvent(self->m_RcvQueueCond);
//.........这里部分代码省略.........