本文整理汇总了C++中TCPSocket::getSocketFid方法的典型用法代码示例。如果您正苦于以下问题:C++ TCPSocket::getSocketFid方法的具体用法?C++ TCPSocket::getSocketFid怎么用?C++ TCPSocket::getSocketFid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TCPSocket
的用法示例。
在下文中一共展示了TCPSocket::getSocketFid方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: listenToSocket
TCPSocket* MultipleTCPSocketsListener::listenToSocket(int timeout){
struct timeval tv = {timeout, 0};
tSocketsContainer::iterator iter = sockets.begin();
tSocketsContainer::iterator endIter = sockets.end();
fd_set fdset;
FD_ZERO(&fdset);
int highfd = 0;
// Fill the set with file descriptors
for (;iter != endIter;iter++) {
highfd++;
FD_SET((*iter)->getSocketFid(), &fdset);
}
// Perform the select
int returned;
if (timeout>0){
returned = select(sizeof(fdset)*8, &fdset, NULL, NULL, &tv);
}else{
returned = select(sizeof(fdset)*8, &fdset, NULL, NULL, NULL);
}
if (returned) {
for (int i = 0; i < highfd; i++) {
TCPSocket* tmpSocket = sockets[i];
if (FD_ISSET(tmpSocket->getSocketFid(), &fdset)) {
return tmpSocket;
}
}
}
return NULL;
}
示例2: run
void Listener::run() {
_running = true;
while (_running) {
TCPSocket* sock = _listenSock->listenAndAccept();
if (sock == NULL) {
break;
}
struct timeval timeout;
timeout.tv_sec = 720;
timeout.tv_usec = 0;
setsockopt(sock->getSocketFid(), SOL_SOCKET, SO_RCVTIMEO, (char*)&timeout, sizeof timeout);
_loginManager->addPendingPeer(sock);
cout << "New peer connected: " << sock->destIpAndPort() << endl;
}
cout << "Listener has stopped" << endl;
}