本文整理汇总了C++中socket_t::handles方法的典型用法代码示例。如果您正苦于以下问题:C++ socket_t::handles方法的具体用法?C++ socket_t::handles怎么用?C++ socket_t::handles使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类socket_t
的用法示例。
在下文中一共展示了socket_t::handles方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
void *controlThreadFcn (void *argPtr) {
makeLog(LOG_DEBUG,"Control: Thread started");
ControlArgs *args=(ControlArgs *)argPtr;
int fdmax=-1;
fd_set read_fds;
int hSocket;
timeval timeout={10,0};//sec,usec
FD_SET(control.getHandle(), &controlSocks);
control.updatefdmax(&fdmax);
FD_SET(sender .getHandle(), &controlSocks);
sender.updatefdmax(&fdmax);
for (;;) {
read_fds=controlSocks;
int selectCnt=select(fdmax+1, &read_fds, NULL, NULL, &timeout);
if(selectCnt == -1) {
makeLog(LOG_ERR,"Control: select error: %s",strerror(errno));
terminate();
}
else if(selectCnt > 0) {
for(hSocket = 0; hSocket <= fdmax; hSocket++) {
if(FD_ISSET(hSocket, &read_fds))
{ // we got one...
makeLog(LOG_DEBUG,"Processing control from thread");
if(control.handles(hSocket)) {
char cmsg[1500];
int recvlen = control.recv((void*)cmsg,sizeof(cmsg),0);
if (recvlen>0) {
controlStr.append(cmsg,recvlen);
processControls(controlStr,control);
} else if (recvlen==0) {
FD_CLR( hSocket, &controlSocks );
}
}
if (sender.handles(hSocket)) {
char cmsg[1500];
int recvlen = sender.recv(cmsg,sizeof(cmsg),0);
if (recvlen>0) {
controlStr.append(cmsg,recvlen);
processControls(controlStr,sender);
} else if (recvlen==0) {
FD_CLR( hSocket, &controlSocks );
}
}
}//if FD_ISSET
} //for loop through sockets
} //selectCnt > 0
}//infinite loop
FD_CLR( control.getHandle(), &controlSocks );
FD_CLR( sender .getHandle(), &controlSocks );
}
示例2: main
//.........这里部分代码省略.........
if (int errcode=pthread_create(&keepingThread,NULL,&keepingFcn,NULL)) {
makeLog(LOG_ERR,"Keeper: Unable to create thread: %s",strerror(errno));
}
#ifdef CONTROL_THREAD
if (int errcode=pthread_create(&controlThread,NULL,&controlThreadFcn,&controlArgs)) {
makeLog(LOG_ERR,"Control: Unable to create thread: %s",strerror(errno));
}
#endif
sendControl("START");
timeval timeout={10,0}; //sec,usec
// loop
for(;;) {
// copy it
fd_set read_fds = master;
int readCnt=select(fdmax+1, &read_fds, NULL, NULL, &timeout);
if( readCnt == -1 ) {
makeLog(LOG_ERR,"Main: select error: %s",strerror(errno));
exit(1);
}
reconnector.tryReconnect(10);
if ( readCnt > 0 ) {
//run through the existing connections looking for data to be read
for(hSocket = 0; hSocket <= fdmax; hSocket++) {
if(FD_ISSET(hSocket, &read_fds))
{ // we got one...
if(listener.handles(hSocket)) {
// buffer for client data
ictDatagram_t ictDatagram;
int recvlen = listener.recv(ictDatagram.data(), listeningArgs.mtu, 0);
if (recvlen>0) {
if (copier.inited()) {
copier.write(ictDatagram.data(),recvlen);
}
ictDatagram.setDataLength(recvlen);
if (!sendingSuspended) {
ictDatagram.setTime(getMNow());
ictDatagram.setNumber(number);
pushDatagram (ictDatagram);
if (streamingArgs.bitrate) {
// makeLog(LOG_DEBUG,"Writenumber: %u",number);
write(mypipe[1],&number,sizeof(number));
// outQueue.push_back ( number );
} else {
int sentcount=sender.send(ictDatagram,ictDatagram.size(),0);
}
number++;
} else {//if suspended
uint64_t now=getMNow();
if (now-lastAnnounceTime>30*1000) {
sender.send("UU",2,0);
lastAnnounceTime=now;
}