本文整理汇总了C++中socket_t::write方法的典型用法代码示例。如果您正苦于以下问题:C++ socket_t::write方法的具体用法?C++ socket_t::write怎么用?C++ socket_t::write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类socket_t
的用法示例。
在下文中一共展示了socket_t::write方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sendControl
bool sendControl(const string data) {
makeLog(LOG_DEBUG,"Control: Sending {%s}",data.c_str());
if (control.peer.empty()) {
makeLog(LOG_ERR,"Control: Peer party is not connected!");
return false;
}
string buf(data);
buf.append("\n");
int sentLength=control.write(buf);
if (sentLength <= 0) {
return false;
} else if (buf.size() != sentLength) {
makeLog(LOG_ERR,"Control: Unable to send complete data");
}
return true;
}
示例2: main
//.........这里部分代码省略.........
}
#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;
}
} //if suspended
} //if recvLen>0
else if (recvlen==0){//Client must be reconnected!!!!
if (listeningArgs.proto.compare("tcp")==0) {
FD_CLR(listener.getHandle(),&master);
if (listener.isConnected()) {
listener.reinit();
}