本文整理汇总了C++中socket_t::recv方法的典型用法代码示例。如果您正苦于以下问题:C++ socket_t::recv方法的具体用法?C++ socket_t::recv怎么用?C++ socket_t::recv使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类socket_t
的用法示例。
在下文中一共展示了socket_t::recv方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: recv_multipart
/*!
Functions are specific to the assisi message protocol,
i.e., each message is a multipart message in the format:
+---------+
| header1 |
+---------+
| header2 |
+---------+
| header3 |
+---------+
| data |
+---------+
The function asserts the above message format.
*/
static int recv_multipart(socket_t& socket,
std::string& name,
std::string& device,
std::string& command,
std::string& data,
int flags = 0)
{
int len = 0;
message_t msg;
len = socket.recv(&msg, flags);
if (len > 0)
{
name = msg_to_str(msg);
//assert(!last_part(socket));
len += socket.recv(&msg);
device = msg_to_str(msg);
//std::cout << device << std::endl;
//assert(!last_part(socket));
len += socket.recv(&msg);
command = msg_to_str(msg);
//std::cout << command << std::endl;
//assert(!last_part(socket));
len += socket.recv(&msg);
data = msg_to_str(msg);
//std::cout << data << std::endl;
}
return len;
}
示例2: 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 );
}
示例3: drop
void drop() {
zmq::message_t null;
while(more()) {
recv(&null);
}
}
示例4: recv
bool recv(T& result,
int flags = 0)
{
zmq::message_t message;
msgpack::unpacked unpacked;
if(!recv(&message, flags)) {
return false;
}
try {
msgpack::unpack(
&unpacked,
static_cast<const char*>(message.data()),
message.size()
);
unpacked.get().convert(&result);
} catch(const msgpack::type_error& e) {
throw std::runtime_error("corrupted object");
} catch(const std::bad_cast& e) {
throw std::runtime_error("corrupted object - type mismatch");
}
return true;
}
示例5: main
//.........这里部分代码省略.........
#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;
}
} //if suspended
} //if recvLen>0
else if (recvlen==0){//Client must be reconnected!!!!
if (listeningArgs.proto.compare("tcp")==0) {