当前位置: 首页>>代码示例>>C++>>正文


C++ socket_t::send方法代码示例

本文整理汇总了C++中socket_t::send方法的典型用法代码示例。如果您正苦于以下问题:C++ socket_t::send方法的具体用法?C++ socket_t::send怎么用?C++ socket_t::send使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在socket_t的用法示例。


在下文中一共展示了socket_t::send方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: SendEnvelopes

int SendEnvelopes(socket_t &socket, vector<string> const &identities, vector<Envelope> &envelopes, bool is_protocol, int flags)
{
    int initial_flags = ZMQ_SNDMORE | (ZMQ_DONTWAIT & flags);

    for (vector<string>::size_type i = 0; i < identities.size(); i++) {
        string identity = identities.at(i);
        if (!socket.send(identity.data(), identity.size(), initial_flags)) {
            return 0;
        }
    }

    message_t msg;
    msg.rebuild(0);
    if (!socket.send(msg, initial_flags)) return -1;

    for (vector<Envelope>::size_type i = 0; i < envelopes.size(); i++) {
        if (is_protocol) {
            if (!envelopes.at(i).ToProtocolZmqMessage(msg)) return -1;
        }
        else {
            if (!envelopes.at(i).ToZmqMessage(msg)) return -1;
        }

        if (!socket.send(msg, flags)) return 0;
    }

    return 1;
}
开发者ID:Fantasticer,项目名称:zippylog,代码行数:28,代码来源:zeromq.cpp

示例2: SendEnvelope

int SendEnvelope(socket_t &socket, vector<string> const &identities, Envelope &e, bool is_protocol, int flags)
{
    message_t msg;
    int initial_flags = ZMQ_SNDMORE | (ZMQ_DONTWAIT & flags);

    message_t e_msg;
    if (is_protocol) {
        if (!e.ToProtocolZmqMessage(e_msg)) return -1;
    }
    else {
        if (!e.ToZmqMessage(e_msg)) return -1;
    }

    for (size_t i = 0; i < identities.size(); i++) {
        string identity = identities.at(i);
        msg.rebuild(identity.size());
        memcpy(msg.data(), identity.data(), msg.size());
        if (!socket.send(msg, initial_flags)) return 0;
    }

    msg.rebuild(0);
    if (!socket.send(msg, initial_flags)) return 0;

    return socket.send(e_msg, flags) ? 1 : 0;
}
开发者ID:Fantasticer,项目名称:zippylog,代码行数:25,代码来源:zeromq.cpp

示例3: send

        bool send(const std::string& route,
                  const packed<Domain, Command>& command)
        {
            const bool multipart = boost::tuples::length<
                typename packed<Domain, Command>::tuple_type
            >::value;

            return send(protect(route), ZMQ_SNDMORE) &&
                   send(static_cast<int>(Command), multipart ? ZMQ_SNDMORE : 0) &&
                   send_multipart(command);
        }
开发者ID:griffordson,项目名称:cocaine-core,代码行数:11,代码来源:io.hpp

示例4: SendSubscriptionEnvelopeResponse

bool RequestProcessor::SendSubscriptionEnvelopeResponse(socket_t &sock, EnvelopeSubscriptionResponseState &state)
{
    if (!state.finalized && !(state.current_size > state.max_size || state.messages.size() > state.max_envelopes))
        return true;

    if (state.messages.size() == 0)
        return true;

    Envelope response;
    protocol::response::SubscriptionStartV1 start;
    start.set_id(state.id);
    start.add_to_envelope(response);

    if (!zeromq::SendEnvelope(sock, state.identities, response, true, ZMQ_SNDMORE)) {
        return false;
    }

    vector<message_t *>::iterator i = state.messages.begin();
    for (; i != state.messages.end(); i++) {
        sock.send(**i, i != state.messages.end() ? ZMQ_SNDMORE : 0);
        delete *i;
        *i = NULL;
    }

    state.messages.clear();
    state.current_size = 0;

    return true;
}
开发者ID:Fantasticer,项目名称:zippylog,代码行数:29,代码来源:request_processor.cpp

示例5: send_multipart

 /*! Outgoing messages conform to the sam format as incoming mssages,
     i.e., they have 4 header parts and a data part.
 */
 static int send_multipart(socket_t& socket,
                    const std::string& name,
                    const std::string& device,
                    const std::string& desc,
                    const std::string& data,
                    int flags = 0)
 {
     message_t msg;
     str_to_msg(name, msg);
     socket.send(msg, ZMQ_SNDMORE);
     str_to_msg(device, msg);
     socket.send(msg, ZMQ_SNDMORE);
     str_to_msg(desc, msg);
     socket.send(msg, ZMQ_SNDMORE);
     str_to_msg(data, msg);
     socket.send(msg);
            
     return 4;
 }
开发者ID:assisi,项目名称:playground,代码行数:22,代码来源:zmq_helpers.hpp

示例6: if

void *streamingFcn (void *argP) {
	StreamingArgs *args=(StreamingArgs*)argP;
	ictDatagram_t datagram;
	uint16_t number;
	
	makeLog(LOG_DEBUG,"Streamer: Thread started");

	for (;;) {
		read(mypipe[0],&number,sizeof(number));
	
//		makeLog(LOG_DEBUG,"Readnumber: %u",number);
//		bool empty=outQueue.empty();
//		if (!empty) {
//			number=outQueue.front();
//			outQueue.pop_front();
//		}

//		if (!empty) {
			getDatagram (datagram,number);

			uint64_t took=getUNow();
			int sentcount=sender.send(datagram,datagram.size(),0);//,(const sockaddr*)&sender.peer,sizeof(sender.peer));
			if (sentcount<0) {
				makeLog(LOG_WARNING,"Sending status error: %d",sentcount);
			} else if (sentcount>0) {
				took=getUNow()-took;
				//1000*1000/bitrate -time for sending 1bit/milisec
				//sentcount*1000*1000/bitrate - time for sending sentcount bits/milisec
				//sentcount*8000*1000/bitrate - time for sending sentcount bytes/milisec
				int64_t wait=long(sentcount)*8000*1000/args->bitrate;
				wait-=took;
//				makeLog(LOG_DEBUG,"Should wait: %ld,%ld,%lu",wait,took,args->bitrate);
				if (wait>0) usleep(wait);
			}
//		} else {
//			outQueue.wait();
//			pthread_mutex_lock	( &outQueueMutex );
//			pthread_cond_wait	( &streamingCnd, &outQueueMutex );
//			pthread_mutex_unlock	( &outQueueMutex );
//		}
	}
}
开发者ID:radenko,项目名称:ict-sender,代码行数:42,代码来源:ict-sender.cpp

示例7: main


//.........这里部分代码省略.........
	}

	if(control.init(AF_INET, SOCK_DGRAM, 0) == -1) {
		makeLog(LOG_ERR,"Control: Unable to create socket: %s",strerror(errno));
		terminate();
	}

	if (controlArgs.host.empty()) {
		control.local.set_in("",controlArgs.port);

		if (control.bind()>=0) 
			makeLog(LOG_INFO,"Control: Listening on *:%d",controlArgs.port);
		else {
			makeLog(LOG_INFO,"Control: Unable to bind socket for udp port %d: %s",controlArgs.port,strerror(errno));
			exit(0);
		}	
	} else {
		makeLog(LOG_INFO,"Control: NAT mode");
		if (controlArgs.proto.compare("tcp")==0) {
		
		} else {
			control.peer.set_in(controlArgs.host,controlArgs.port);
		}
	}

	#ifdef CONTROL_THREAD
	FD_SET(control.getHandle(), &controlSocks);
	control.updatefdmax(&fdmax);
	#else
	FD_SET(control.getHandle(), &master);
	control.updatefdmax(&fdmax);
	#endif

	if(sender.init(AF_INET, SOCK_DGRAM, 0) == -1) {
		makeLog(LOG_ERR,"Streamer: Unable to create socket: %s",strerror(errno));
		terminate();
	}

	if (streamingArgs.proto.compare("tcp")==0) {
		
	} else {
		sender.peer.set_in(streamingArgs.host,streamingArgs.port);
		makeLog(LOG_INFO,"Streamer: Peer port was set up %s:%d",streamingArgs.host.c_str(),streamingArgs.port);
	}

	#ifdef CONTROL_THREAD
	FD_SET(sender .getHandle(), &controlSocks);
	sender.updatefdmax(&fdmax);
	#else
	FD_SET(sender.getHandle(), &master);
	sender.updatefdmax(&fdmax);
	#endif

	if (!listeningArgs.copyHost.empty()) {
		if(copier.init(AF_INET, SOCK_DGRAM, 0) == -1) {
			makeLog(LOG_ERR,"Copier: Unable to create socket: %s",strerror(errno));
		}

		copier.peer.set_in(listeningArgs.copyHost,listeningArgs.copyPort);
		makeLog(LOG_INFO,"Copier: Resend data to: %s",copier.peer.toString().c_str());

		FD_SET(copier.getHandle(), &master);
		copier.updatefdmax(&fdmax);
	}

	openlog("ict-receiver", LOG_PID|LOG_CONS, LOG_USER);
开发者ID:radenko,项目名称:ict-sender,代码行数:67,代码来源:ict-sender.cpp


注:本文中的socket_t::send方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。