本文整理汇总了C++中zmq::socket_t::recv方法的典型用法代码示例。如果您正苦于以下问题:C++ socket_t::recv方法的具体用法?C++ socket_t::recv怎么用?C++ socket_t::recv使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类zmq::socket_t
的用法示例。
在下文中一共展示了socket_t::recv方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: recv
bool recv(zmq::socket_t & socket) {
clear();
while(1) {
zmq::message_t message(0);
try {
if (!socket.recv(&message, 0)) {
return false;
}
} catch (zmq::error_t error) {
//std::cout << "E: " << error.what() << std::endl;
return false;
}
char *data = reinterpret_cast<char*>(message.data());
if (message.size() == 17 && data[0] == 0) {
push_back(encode_uuid(msg_to_string(message)));
} else {
push_back(msg_to_string(message));
}
boost::int64_t more;
size_t more_size = sizeof(more);
socket.getsockopt(ZMQ_RCVMORE, &more, &more_size);
if (!more) {
break;
}
}
return true;
}
示例2: recv
inline bool recv (zmq::socket_t & socket, tile_protocol & tile)
{
zmq::message_t msg;
socket.recv(&msg);
std::string buf(static_cast<char*>(msg.data()),msg.size());
return unserialise(buf, tile);
}
示例3: string
// Receive 0MQ string from socket and convert into string
static std::string
s_recv (zmq::socket_t & socket) {
zmq::message_t message;
socket.recv(&message);
return std::string(static_cast<char*>(message.data()), message.size());
}
示例4: 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);
}
示例5: recursive_receive
bool recursive_receive(zmq::socket_t& receiving_socket, zmq::message_t& message,
const REQ& req, RES& response, bool& succeed) {
bool rc = receiving_socket.recv(&message);
if (rc) {
auto serialized_resp = kZmqUtil->message_to_string(message);
response.ParseFromString(serialized_resp);
if (req.request_id() == response.response_id()) {
succeed = true;
return false;
} else {
return true;
}
} else {
// timeout
if (errno == EAGAIN) {
succeed = false;
} else {
succeed = false;
}
return false;
}
}
示例6: recv_msg_async
// 0 for received nothing
int recv_msg_async(zmq::socket_t &sock, boost::shared_array<uint8_t> &data)
{
zmq::message_t msgt;
int nbytes;
try{
nbytes = sock.recv(&msgt, ZMQ_DONTWAIT);
}catch(zmq::error_t e){
return -1;
}
if(nbytes == 0){
if(zmq_errno() == EAGAIN)
return 0;
else
return -1;
}
size_t len = msgt.size();
uint8_t *dataptr;
try{
dataptr = new uint8_t[len];
}catch(std::bad_alloc e){
return -1;
}
memcpy(dataptr, msgt.data(), len);
data.reset(dataptr);
return len;
}
示例7: recv_msg
/*
* return number of bytes received, negative if error, 0 for received nothing, which should be treated as error
*/
int recv_msg(zmq::socket_t &sock, boost::shared_array<uint8_t> &data)
{
zmq::message_t msgt;
int nbytes;
try{
nbytes = sock.recv(&msgt);
}catch(zmq::error_t e){
//LOG(NOR, stderr, "recv failed: %s\n", e.what());
return -1;
}
if(nbytes == 0) return 0;
size_t len = msgt.size();
uint8_t *dataptr;
try{
dataptr = new uint8_t[len];
}catch(std::bad_alloc e){
//LOG(DBG, stderr, "can not allocate memory!\n");
return -1;
}
memcpy(dataptr, msgt.data(), len);
data.reset(dataptr);
return len;
}
示例8: 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();
}
}
}
示例9: RecvMsg
/*
* return number of bytes received, negative if error, 0 for received nothing,
* which should be treated as error
*/
int32_t RecvMsg(zmq::socket_t &sock, boost::shared_array<uint8_t> &data,
bool *_more){
zmq::message_t msgt;
int nbytes;
try{
nbytes = sock.recv(&msgt);
}catch(zmq::error_t &e){
LOG(ERROR) << "RecvMsg error = " << e.what();
return -1;
}
if(nbytes == 0) return 0;
size_t len = msgt.size();
uint8_t *dataptr;
try{
dataptr = new uint8_t[len];
}catch(std::bad_alloc &e){
return -1;
}
memcpy(dataptr, msgt.data(), len);
data.reset(dataptr);
if(_more != NULL){
int more_recv;
size_t s = sizeof(int);
sock.getsockopt(ZMQ_RCVMORE, &more_recv, &s);
*_more = (more_recv == 1) ? true : false;
}
return len;
}
示例10: 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);
}
示例11: receiveStr
void receiveStr(zmq::socket_t& socket, string& s, int flags = 0) {
zmq::message_t request;
if (!socket.recv(&request, flags)) {
std::cerr << "Reception KO" << std::endl;
}
s.append((char const *) request.data(), request.size());
}
示例12: _receive
void _receive(zmq::socket_t & socket, std::list<zmq::message_t*> *result) {
do {
zmq::message_t * msg = new zmq::message_t();
// TODO: error handling
socket.recv(msg);
result->push_back(msg);
} while (sockopt_rcvmore(socket));
}
示例13: s_recv
unsigned s_recv (zmq::socket_t & socket, std::string& buffer) {
zmq::message_t message;
socket.recv(&message);
buffer.clear();
buffer.assign(static_cast<char*>(message.data()), message.size());
return message.size();
}
示例14: process_status_request
// capacity request
void process_status_request(zmq::socket_t& status, int& number_of_workers) {
// null request
zmq::message_t incoming_msg;
status.recv(&incoming_msg);
// send current capacity
zmq::message_t status_msg(sizeof(number_of_workers));
memcpy(status_msg.data(), &number_of_workers, sizeof(number_of_workers));
status.send(status_msg);
}
示例15: recv_zmq_message
static bool recv_zmq_message(zmq::socket_t& sock,
zmq::message_t& msg,
T& object,
int flags = ZMQ_NOBLOCK)
{
if (!sock.recv(&msg, flags)) {
return false;
}
memcpy(&object, msg.data(), msg.size());
return true;
}