本文整理汇总了C++中socket_t::getHandle方法的典型用法代码示例。如果您正苦于以下问题:C++ socket_t::getHandle方法的具体用法?C++ socket_t::getHandle怎么用?C++ socket_t::getHandle使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类socket_t
的用法示例。
在下文中一共展示了socket_t::getHandle方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
int main(int argc, char *argv[]) {
//clear the master and temp sets
FD_ZERO(&master);
FD_ZERO(&controlSocks);
char c;
int hSocket;
uint16_t number=0;
uint64_t lastAnnounceTime=0;
Reconnector reconnector;
set_terminate(terminateFcn);
void (*prev_fn)(int);
prev_fn = signal (SIGINT,terminateFcn);
if (prev_fn==SIG_ERR)
makeLog(LOG_ERR,"Main: Unable to set termination funtion");
while ((c = getopt (argc, argv, "fvc:")) != -1)
switch (c) {
case 'f':
fflag = true;
break;
case 'v':
vflag = true;
break;
case 'c':
configFile = optarg;
break;
case '?':
if (optopt == 'c')
fprintf (stderr, "Main: Option -%c requires an argument.\n", optopt);
else if (isprint (optopt))
fprintf (stderr, "Main: Unknown option `-%c'.\n", optopt);
else
fprintf (stderr, "Main: Unknown option character `\\x%x'.\n", optopt);
return 1;
default:
abort ();
}
Config config;
readConfig(config);
makeLog(LOG_DEBUG,"Read configuration");
if (!pidFile.empty()) {
makeLog(LOG_DEBUG,"Main: Checking pid file: %s",pidFile.c_str());
ifstream pidfile(pidFile.c_str());
if (pidfile.is_open()) {
char line[20];
int otherpid;
pidfile.getline(line,sizeof(line));
sscanf(line,"%u",&otherpid);
if (kill(otherpid,0)==0) {
makeLog(LOG_ERR,"Main: Other instance is running: %d",otherpid);
pidFile="";
terminate();
}
pidfile.close();
}
}
// makeLog(LOG_DEBUG,"PID check finished");
if (!fflag) daemon (0,1);
if (!pidFile.empty()) {
ofstream pidfile;
pidfile.open(pidFile.c_str());
pidfile << getpid();
pidfile << "\n";
pidfile.close();
}
if (listeningArgs.proto.compare("tcp")==0) {
//get the listener
if(listener.init(AF_INET, SOCK_STREAM, 0) == -1) {
makeLog(LOG_ERR,"Listener: Unable to create socket");
exit(1);
}
listener.peer.set_in(listeningArgs.host,listeningArgs.port);
if (listener.connect() < 0) {
makeLog(LOG_ERR,"Listener: Cannot connect: %s;",strerror(errno));
reconnector.add(&listener,reconnectListener,NULL);
} else {
// add the listener to the master set
listener.updatefdmax(&fdmax);
makeLog(LOG_INFO,"Listener: Connected to %s:%d;",listeningArgs.host.c_str(),listeningArgs.port);
}
FD_SET(listener.getHandle(), &master);
} else {
const bool mcast=((inet_addr(listeningArgs.host.c_str()) & MCAST_MASK) == MCAST_ADDR);
//get the listener
if(listener.init(AF_INET, SOCK_DGRAM, 0) == -1) {
//.........这里部分代码省略.........
示例3: processControl
string processControl (const string Msg,const socket_t &sock) {
const CStrings data=split(" ",Msg);
const CStringsIterator name=data.begin();
string result="";
makeLog(LOG_DEBUG,"Control: Processing {%s}",Msg.c_str());
if (name->compare("SEND")==0) {
uint16_t resendNumber = (data.size()>1)?atoi(data[1].c_str()):0;
uint16_t cnt = (data.size()>2)?atoi(data[2].c_str()):0;
if (cnt<1) cnt=1;
// makeLog(LOG_DEBUG,"RESEND request: %d:%d",resendNumber,cnt);
bool wasMissing=false;
for (int i=0;i<cnt;i++) {
int missing = getDatagramLength(resendNumber);
if (missing<=0) {
wasMissing=true;
makeLog(LOG_INFO,"Streamer: Datagram lost: %d",resendNumber);
sendControl(stringprintf("SEND_OOB %d",resendNumber));
} else {
ictDatagram_t ictDatagram;
getDatagram(ictDatagram,resendNumber);
outQueue.push_front ( resendNumber );
// sendto(sender.socket,ictDatagram,ictDatagram.size(),0,(const sockaddr*)&sender.peer,sizeof(sender.peer));
}
resendNumber++;
}
if (wasMissing) {
makeLog(LOG_WARNING,"Streamer: Packet(s) is out of buffer");
}
}
else if (name->compare("STARTED")==0) {
makeLog (LOG_INFO,"Control: method STARTED");
}
else if (name->compare("KEPT")==0) {
keptLastTime=getMNow();
}
else if (name->compare("SETBUF")==0) {
//makelog ("Control message: {$msg1}");
int newBufferTime=(data.size()>1)?atoi(data[1].c_str()):-1;
if (newBufferTime!=-1 && cleaningArgs.bufferSize!=newBufferTime) {
cleaningArgs.bufferSize=newBufferTime;
makeLog (LOG_INFO,"Buffer is set to new value: %d",cleaningArgs.bufferSize);
}
return stringprintf("BUFSET %d",cleaningArgs.bufferSize);
}
else if (name->compare("RESETSTREAM")==0) {
FD_CLR(sender.getHandle(),&master);
sender.reinit();
FD_SET(sender.getHandle(),&master);
makeLog (LOG_INFO,"Streamer: Restart on receiver requested");
result+=stringprintf("STREAMRESET %d",0);
}
else if (name->compare("SUSPEND")==0) {
if (!sendingSuspended) {
sendingSuspended=true;
makeLog(LOG_INFO,"Streamer: Supended on receiver request");
}
return stringprintf("SUSPENDED %d",0); //TODO O by malo byt cislo noveho portu na vysielacej strane
}
else if (name->compare("RESUME")==0) {
sendingSuspended=false;
return stringprintf("RESUMED %d",0); //TODO O by malo byt cislo noveho portu na vysielacej strane
}
else if (name->compare("CINIT")==0) {
int newBufferTime=data.size()>1?atoi(data[1].c_str()):-1;
sendingSuspended=false;
makeLog(LOG_INFO,"Clinet initialization request from receiver");
if (newBufferTime!=-1 && cleaningArgs.bufferSize!=newBufferTime) {
cleaningArgs.bufferSize=newBufferTime;
makeLog (LOG_INFO,"Buffer is set to new value: %d",cleaningArgs.bufferSize);
result+=stringprintf("BUFSET %d",cleaningArgs.bufferSize);
}
result+=stringprintf("CINITED %d",0);//getSocketLocalPort(sender.socket)); //TODO O by malo byt cislo noveho portu na vysielacej strane
}
else if (name->compare("CUNINIT")==0) {
clearBuffer();
sendingInitialized=false;
result+=stringprintf("CUNINITED %d",0); //TODO O by malo byt cislo noveho portu na vysielacej strane
}
else if (name->compare("CONNECTCONTROL")==0) {
return "CONTROLCONNECT\n";
} else {
makeLog(LOG_ERR,"Control: unknown command: %s",name->c_str());
}
return result;
//.........这里部分代码省略.........