本文整理汇总了C++中zmq::socket_t::send方法的典型用法代码示例。如果您正苦于以下问题:C++ socket_t::send方法的具体用法?C++ socket_t::send怎么用?C++ socket_t::send使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类zmq::socket_t
的用法示例。
在下文中一共展示了socket_t::send方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Send
bool OTSocket::Send(const std::string & str_Reply)
{
OT_ASSERT_MSG(NULL != m_pSocket, "m_pSocket == NULL in OTSocket::Send()");
OT_ASSERT_MSG(NULL != m_pContext, "m_pContext == NULL in OTSocket::Send()");
OT_ASSERT_MSG(str_Reply.size() > 0, "str_Reply.size() > 0");
// -----------------------------------
const long lLatencySendMilliSec = OTLog::GetLatencySendMs();
const long lLatencySendMicroSec = lLatencySendMilliSec*1000; // Microsecond is 1000 times smaller than millisecond.
// Convert the std::string (reply) into a ZMQ message
zmq::message_t reply (str_Reply.length());
memcpy((void *) reply.data(), str_Reply.c_str(), str_Reply.length());
// -----------------------------------
bool bSuccessSending = false;
if (OTLog::IsBlocking())
{
bSuccessSending = m_pSocket->send(reply); // Blocking.
}
else // not blocking
{
int nSendTries = OTLog::GetLatencySendNoTries();
long lDoubling = lLatencySendMicroSec;
bool bKeepTrying = true;
while (bKeepTrying && (nSendTries > 0))
{
zmq::pollitem_t items [] = {
{ (*m_pSocket), 0, ZMQ_POLLOUT, 0 }
};
const int nPoll = zmq::poll(&items[0], 1, lDoubling); // ZMQ_POLLOUT, 1 item, timeout (microseconds in ZMQ 2.1; changes to milliseconds in 3.0)
lDoubling *= 2;
if (items[0].revents & ZMQ_POLLOUT)
{
bSuccessSending = m_pSocket->send(reply, ZMQ_NOBLOCK); // <=========== SEND ===============
OTLog::SleepMilliseconds( 1 );
if (!bSuccessSending)
{
if (false == HandleSendingError())
bKeepTrying = false;
}
else
break; // (Success -- we're done in this loop.)
}
else if ((-1) == nPoll) // error.
{
if (false == HandlePollingError())
bKeepTrying = false;
}
--nSendTries;
}
}
return bSuccessSending;
}
示例2: memcpy
void
raw_sender(zmq::socket_t& s)
{
for (size_t i = 0; i < ITERS; ++i)
{
zmq::message_t msg1(ARRAY_LEN(PART1)-1);
memcpy(msg1.data(), PART1, msg1.size());
s.send(msg1, ZMQ_SNDMORE);
zmq::message_t msg2(ARRAY_LEN(PART2)-1);
memcpy(msg2.data(), PART2, msg2.size());
s.send(msg2, ZMQ_SNDMORE);
zmq::message_t msg3(ARRAY_LEN(PART3)-1);
memcpy(msg3.data(), PART3, msg3.size());
s.send(msg3);
zmq::message_t msg_res;
s.recv(&msg_res, 0);
if (i % 1000 == 0)
{
std::cout << ".";
std::cout.flush();
}
}
}
示例3: message
static bool
s_send (zmq::socket_t & socket, const char* buffer, unsigned length, bool zerocopy=false) {
if(zerocopy) {
zmq::message_t message((void *)buffer, length, NULL, NULL);
return socket.send (message);
}else {
zmq::message_t message(length);
memcpy (message.data(),buffer, length);
return socket.send (message);
}
}
示例4: rawSocketSend
void MessageSender::rawSocketSend( zmq::socket_t& a_socket, const std::string& a_name, const unsigned char* a_msg, size_t a_msgSize )
{
bool ok = false;
try
{
ok = a_socket.send( a_name.data(), a_name.size(), ZMQ_SNDMORE );
ok = a_socket.send( a_msg, a_msgSize );
}
catch( const zmq::error_t& ex )
{
//std::cout << __PRETTY_FUNCTION__ << " " << ex.what() << std::endl;
}
}
示例5: sendOverSocket
void sendOverSocket(zmq::socket_t &socket, const message::Node &msg) {
std::string msg_str;
msg.SerializeToString(&msg_str);
zmq::message_t request(msg_str.size());
memcpy((void*)request.data(), msg_str.c_str(), msg_str.size());
// Sometimes sending will fail with EINTR. In this case, we try to
// send the message again.
while (true) {
int failed_attempts = 0;
try {
bool sentOK = socket.send(request);
// If sentOK is false, there was an EAGAIN. We handle this the
// same as EINTR.
if (!sentOK) {
failed_attempts++;
if (failed_attempts > 10) abort();
continue;
}
// Success: stop the loop.
break;
} catch (zmq::error_t &e) {
failed_attempts++;
if (failed_attempts > 10) abort();
if (e.num() == EINTR) {
continue;
}
// If it was something other than EINTR, rethrow the exception.
throw e;
}
}
}
示例6: s_send
/**
* Convert string to 0MQ string and send to socket.
*/
static bool s_send (zmq::socket_t& socket, const std::string& string) {
zmq::message_t message (string.size());
memcpy (message.data(), string.data(), string.size());
bool rc = socket.send (message);
return rc;
}
示例7: nag
void nag() {
//are we waiting on the next files
if(wait_until && wait_until < std::time(nullptr)) {
socket.send(std::string("N"), ZMQ_DONTWAIT);
wait_until = 0;
}
}
示例8: process_frontend
void process_frontend(zmq::socket_t& frontend, int& available_workers) {
zmq::message_t req;
frontend.recv(&req);
zmq::message_t reply(sizeof(available_workers));
memcpy(reply.data(), &available_workers, sizeof(available_workers));
frontend.send(reply);
}
示例9: send
bool send (zmq::socket_t & socket, std::string const& string)
{
zmq::message_t message(string.size());
std::memcpy(message.data(), string.data(), string.size());
bool rc = socket.send(message);
return (rc);
}
示例10: send
/** Send empty message. */
inline bool send(zmq::socket_t &s, const empty &v, int flags)
{
zmq::message_t msg(0);
IB_FIRST_PART(s.send(msg, flags));
return true;
}
示例11: handleOp
void handleOp(zmq::socket_t &socket, int opCode) {
std::string s_req, trace, line;
std::cout<<"Trace: ";
std::getline(std::cin, trace);
Request req;
Id id;
Person person;
Request_Header_Type type;
switch (opCode) {
case 1:
type = Request_Header_Type_LOOKUP;
std::cout<<"id: ";
line.clear();
std::getline(std::cin, line);
id = makeId(fromString<int>(line));
req = makeRequest(type, id, person, false, trace);
break;
case 3:
type = Request_Header_Type_REMOVE;
std::cout<<"id: ";
line.clear();
std::getline(std::cin, line);
id = makeId(fromString<int>(line));
req = makeRequest(type, id, person, false, trace);
break;
case 2:
{
type = Request_Header_Type_INSERT;
std::cout<<"id: ";
line.clear();
std::getline(std::cin, line);
id = makeId(fromString<int>(line));
line.clear();
std::cout<<"Name: ";
std::getline(std::cin, line);
std::string ph, ovr;
std::cout<<"Phone: ";
std::getline(std::cin, ph);
std::cout<<"Overwrite: (y/n) ";
std::getline(std::cin, ovr);
person = makePerson(line, ph);
req = makeRequest(type, id, person, ovr.compare("y") == 0,
trace);
break;
}
};
std::cout<<"Request: "<<requestToString(req);
TRACE(std::cout, "");
req.SerializeToString(&s_req);
zmq::message_t z_req(s_req.size());
memcpy(z_req.data(), (void *)s_req.data(), s_req.size());
socket.send(z_req);
zmq::message_t z_resp;
socket.recv(&z_resp);
std::string s_resp((char *)z_resp.data(), z_resp.size());
Response resp;
resp.ParseFromString(s_resp);
std::cout<<"Response = "<<responseToString(resp);
}
示例12: Update
void SampleSensor::Update(TimeValue dt)
{
//check to see if it is time to write an update to this sensor
m_sampleTimeLeft -= dt;
//if we still have time left, skip writing an update
if (m_sampleTimeLeft > 0.0)
return;
//Sending the image is dependent on the frame rate and if the user has closed the connection
if((frame % (int) (100 / sendRate) == 0) && running) {
// Get Video Data and Send as ZMQ Message
std::vector<SensorPtr> sensors = SensorManager::GetSingleton().GetAllSensors();
for (uint32 i = 0; i < sensors.size(); ++i)
{
if (sensors[i]->GetSensorType() != "CameraSensor")
continue;
CameraSensor* pCam = static_cast<CameraSensor*>(sensors[i].Get());
const std::vector<LensData>& lens = pCam->GetLensData();
if (lens.size() == 0)
continue;
const LensData& thisLens = lens[0];
const LensParams & lensParams = pCam->GetLensParams()[0];
if (thisLens.m_renderRequest.m_pOutputBuffer != NULL) {
//Pull the dimensions of the camera
int size, sizeX, sizeY;
sizeX = lensParams.m_resolutionX;
sizeY = lensParams.m_resolutionY;
size = sizeX * sizeY * 3;
//Make a buffer for the compressed jpeg
void *buf = malloc(size);
//Set the Quality Factor
jpge::params params;
params.m_quality = quality_factor;
//Compress the image to improve transfer speed
if(compress_image_to_jpeg_file_in_memory(buf, size, sizeX, sizeY, 3, thisLens.m_renderRequest.m_pOutputBuffer, params)) {
//Put the compressed data into a ZMQ message and send it over the socket
zmq::message_t image (size);
memcpy((void *) image.data(), buf, size);
socket_.send (image);
}
else {
LogMessage("Failed to compress image", kLogMsgError);
}
}
}
}
frame++;
m_sampleTimeLeft += m_sampleStep;
}
示例13: return
static bool
s_sendobj (zmq::socket_t & socket, Message& obj) {
msgPtr message = obj.fillmessage();
bool rc = socket.send (*message);
return (rc);
}
示例14: sendStringPart
bool sendStringPart(zmq::socket_t & socket, const std::string & string)
{
// Taken from zhelpers.hpp
zmq::message_t message(string.size());
memcpy(message.data(), string.data(), string.size());
return socket.send(message, ZMQ_SNDMORE);
}
示例15: sendStr
void sendStr(zmq::socket_t& socket, string const & s, int flags = 0) {
zmq::message_t reply(s.size() * sizeof(string::value_type));
std::memcpy(reply.data(), s.c_str(), s.size());
if (!socket.send(reply, flags)) {
std::cerr << "Envoi KO" << std::endl;
}
}