本文整理汇总了C++中zmq::socket_t::getsockopt方法的典型用法代码示例。如果您正苦于以下问题:C++ socket_t::getsockopt方法的具体用法?C++ socket_t::getsockopt怎么用?C++ socket_t::getsockopt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类zmq::socket_t
的用法示例。
在下文中一共展示了socket_t::getsockopt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: receive
Message receive(zmq::socket_t& socket)
{
std::vector<std::string> address;
std::string frame = receiveString(socket);
// Do we have an address?
while (frame.compare("") != 0)
{
address.push_back(frame);
frame = receiveString(socket);
}
// address is a stack, so reverse it to get the right way around
std::reverse(address.begin(), address.end());
// We've just read the delimiter, so now get subject
auto subjectString = receiveString(socket);
//the underlying representation is (explicitly) an int so fairly safe
Subject subject = (Subject)detail::unserialise<std::uint32_t>(subjectString);
std::vector<std::string> data;
while (true)
{
int isMore = 0;
size_t moreSize = sizeof(isMore);
socket.getsockopt(ZMQ_RCVMORE, &isMore, &moreSize);
if (!isMore)
break;
data.push_back(receiveString(socket));
}
return Message(address, subject, data);
}
示例4: getRequest
bool Server::getRequest (zmq::socket_t &socket, pb::RequestEnvelope &envelope) {
long long more;
size_t sz = sizeof (more);
zmq::message_t request;
socket.recv (&request);
socket.getsockopt (ZMQ_RCVMORE, &more, &sz);
bool isAnotherRequest = more != 0;
envelope.ParseFromArray (request.data(), request.size());
return isAnotherRequest;
}
示例5: receiveAllStr
void receiveAllStr(zmq::socket_t& socket, string& s, int flags = 0) {
int64_t more = 1;
size_t moreSize = sizeof(int64_t);
while (more == 1) {
receiveStr(socket, s, flags);
socket.getsockopt(ZMQ_RCVMORE, &more, &moreSize);
}
}
示例6: sizeof
bool
has_more(zmq::socket_t& sock)
{
int64_t more = 0;
size_t more_size = sizeof(more);
sock.getsockopt(ZMQ_RCVMORE, &more, &more_size);
return (more != 0);
}
示例7: sockopt_rcvmore
bool sockopt_rcvmore(zmq::socket_t & socket)
{
int64_t rcvmore = 0;
size_t type_size = sizeof(int64_t);
socket.getsockopt(ZMQ_RCVMORE, &rcvmore, &type_size);
// std::cout << rcvmore << std::endl;
return rcvmore ? true : false;
}
示例8: recv_multipart
void recv_multipart(zmq::socket_t &socket) {
int64_t more=-1;
size_t more_size = sizeof (more);
while(more) {
zmq::message_t response;
socket.recv(&response);
std::string response_str((const char *)response.data(),
response.size());
cout << response_str << endl;
socket.getsockopt(ZMQ_RCVMORE, &more, &more_size);
}
}
示例9: process_backend
// relay data from workers to frontend
void process_backend(zmq::socket_t& frontend, zmq::socket_t& backend) {
int64_t more;
size_t moresz;
moresz = sizeof(more);
while(true) {
zmq::message_t worker_msg;
backend.recv(&worker_msg);
backend.getsockopt(ZMQ_RCVMORE, &more, &moresz);
frontend.send(worker_msg, more ? ZMQ_SNDMORE : 0);
if(!more) {
break;
}
}
}
示例10: receiveFrom
bool MultipartMessage::receiveFrom(zmq::socket_t& s, int flags) {
int64_t has_more = 0 ;
size_t ilen = sizeof(int64_t);
parts.clear();
while (true) {
Message m ;
bool res = m.receiveFrom(s, flags);
if (!res) {
parts.clear();
return res ;
}
parts.push_back(m);
s.getsockopt(ZMQ_RCVMORE, &has_more, &ilen);
if (!has_more)
break ;
}
return true ;
}
示例11: process_frontend
// job allocation, relay request to workers
void process_frontend(zmq::socket_t& frontend, zmq::socket_t& backend, int& number_of_workers) {
int64_t more;
size_t moresz;
moresz = sizeof(more);
// decrement available workers
--number_of_workers;
// process incoming using multipart aware code
while(true) {
zmq::message_t client_msg;
frontend.recv(&client_msg);
frontend.getsockopt(ZMQ_RCVMORE, &more, &moresz);
backend.send(client_msg, more ? ZMQ_SNDMORE : 0);
if(!more) {
break;
}
}
}
示例12: data
// Receives all message parts from socket, prints neatly
//
static void
s_dump (zmq::socket_t & socket)
{
std::cout << "----------------------------------------" << std::endl;
while (1) {
// Process all parts of the message
zmq::message_t message;
socket.recv(&message);
// Dump the message as text or binary
int size = message.size();
std::string data(static_cast<char*>(message.data()), size);
bool is_text = true;
int char_nbr;
unsigned char byte;
for (char_nbr = 0; char_nbr < size; char_nbr++) {
byte = data [char_nbr];
if (byte < 32 || byte > 127)
is_text = false;
}
std::cout << "[" << std::setfill('0') << std::setw(3) << size << "]";
for (char_nbr = 0; char_nbr < size; char_nbr++) {
if (is_text)
std::cout << (char)data [char_nbr];
else
std::cout << std::setfill('0') << std::setw(2)
<< std::hex << (unsigned int) data [char_nbr];
}
std::cout << std::endl;
int more = 0; // Multipart detection
size_t more_size = sizeof (more);
socket.getsockopt (ZMQ_RCVMORE, &more, &more_size);
if (!more)
break; // Last message part
}
}
示例13: data
// Receives all message parts from socket, prints neatly
//
static void
s_dump (zmq::socket_t & socket)
{
std::cout << "----------------------------------------" << std::endl;
while (1) {
// Process all parts of the message
zmq::message_t message;
socket.recv(&message);
// Dump the message as text or binary
std::string data(static_cast<char*>(message.data()));
int size = message.size();
bool is_text = true;
int char_nbr;
for (char_nbr = 0; char_nbr < size; char_nbr++)
if (data [char_nbr] < 32 || data [char_nbr] > 127)
is_text = 0;
printf ("[%03d] ", size);
for (char_nbr = 0; char_nbr < size; char_nbr++) {
if (is_text)
printf ("%c", data [char_nbr]);
else
printf ("%02X", (unsigned char) data [char_nbr]);
}
printf ("\n");
int64_t more; // Multipart detection
size_t more_size = sizeof (more);
socket.getsockopt(ZMQ_RCVMORE, &more, &more_size);
if (!more)
break; // Last message part
}
}
示例14: TransferMessage
bool TransferMessage(::zmq::socket_t &receiver, ::zmq::socket_t &sender)
{
message_t msg;
int32 more;
size_t moresz;
while (true) {
if (!receiver.recv(&msg, 0)) {
return false;
}
moresz = sizeof(more);
receiver.getsockopt(ZMQ_RCVMORE, &more, &moresz);
if (!sender.send(msg, more ? ZMQ_SNDMORE : 0)) {
return false;
}
if (!more) break;
}
return true;
}
示例15: RecvMsgAsync
// 0 for received nothing
int32_t RecvMsgAsync(zmq::socket_t &sock, boost::shared_array<uint8_t> &data,
bool *_more){
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);
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;
}