本文整理汇总了C++中TcpSocket::setTimeout方法的典型用法代码示例。如果您正苦于以下问题:C++ TcpSocket::setTimeout方法的具体用法?C++ TcpSocket::setTimeout怎么用?C++ TcpSocket::setTimeout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TcpSocket
的用法示例。
在下文中一共展示了TcpSocket::setTimeout方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Accept
//======================================================================================
TcpSocket* TcpSocket::Accept() {
struct sockaddr_in sa;
socklen_t len = sizeof(sa);
Log.i(SOCK_TAG, "TcpSocket::Accept m_iSocket=%u", m_iSocket);
int ret = accept(m_iSocket, (struct sockaddr*) &sa, &len);
if (-1 == ret){
Log.e(SOCK_TAG, "TcpSocket::Accept -1!");
return NULL;
}
if (0 == ret) {
Log.e(SOCK_TAG, "TcpSocket::Accept 0!");
return NULL;
}
TcpSocket *pNew = new TcpSocket(m_pSelector);
pNew->m_iSocket = ret;
//pNew->m_ip = ntohl(sa.sin_addr.s_addr);
//pNew->m_iPort = ntohs(sa.sin_port);
pNew->m_ip = sa.sin_addr.s_addr;
pNew->m_iPort = sa.sin_port;
pNew->m_bConnected = true;
pNew->m_iLastRecvTime = SelectorEPoll::getInstance().m_iHaoMiao;
pNew->setTimeout(m_iTimeout);
pNew->SetNBlock();
Log.i(SOCK_TAG, "TcpSocket accept %s:%u", ip2str(pNew->m_ip), pNew->m_iPort);
return pNew;
}
示例2: newSocket
void Worker::newSocket(qintptr socket)
{
//qDebug() << m_name << " is handling a new request; thread id" << thread()->currentThreadId();
TcpSocket* s = new TcpSocket(this);
s->m_id = static_cast<unsigned int>(rand());
connect(s, SIGNAL(readyRead()), this, SLOT(readClient()));
connect(s, SIGNAL(disconnected()), this, SLOT(discardClient()));
s->setSocketDescriptor(socket);
s->setTimeout(1000*60*2);
#ifndef NO_LOG
sLog() << m_name << " receive a new request from ip:" << s->peerAddress().toString();
#endif
}
示例3: createTcpListener
TcpSocket* SocketHandler::createTcpListener(uint32_t uiIP, uint16_t& iPort,
SocketHandler *handler, uint32_t timeout, const char* dbgname)
{
TcpSocket* listenRes = new TcpSocket(&SelectorEPoll::getInstance(), dbgname);
if(listenRes->Listen(uiIP, iPort, true) == false)
{
log(Error, "ListenManager tcp port %u listen failed", iPort);
return NULL;
}
listenRes->m_pHandler = handler;
listenRes->setListenSockt(true);
listenRes->setTimeout(timeout);
//log(Debug, "Calling g_epoll.SetEvent");
SelectorEPoll::getInstance().SetEvent(listenRes, 0, SEL_READ);
return listenRes;
}