Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not get option ZMQ_IDENTITY in ZMQ_STREAM #156

Open
qtcdxxyuc opened this issue Nov 1, 2019 · 1 comment
Open

Can not get option ZMQ_IDENTITY in ZMQ_STREAM #156

qtcdxxyuc opened this issue Nov 1, 2019 · 1 comment

Comments

@qtcdxxyuc
Copy link

ZMQ

 int rv = 0;
auto context = zmq_init(1);
auto socket = zmq_socket(context,ZMQ_STREAM);
rv = zmq_connect(socket,ADDRESS);
assert(rv==0);
std::string id;
id.resize(5);
size_t sz = 5;
rv = zmq_getsockopt(socket,ZMQ_IDENTITY,id.data(),&sz);

can get ZMQ_IDENTITY. e.g. k�Eg.


AZMQ

boost::asio::io_context ioc;
azmq::socket client(ioc,ZMQ_STREAM);
client.connect(ADDRESS);
azmq::socket::identity id;
client.get_option(id);
//throw Boost::system_error: Invalid argument

other

now ZMQ_IDENTITY renamed ZMQ_ROUTING_ID.

version

zmq:4.3.2

boost: 1.7.1

azmq:github-lasted: 19.11.1

@qtcdxxyuc
Copy link
Author

qtcdxxyuc commented Nov 1, 2019

I found the reason.

//main.cpp
azmq::socket::identity id;
//typename opt::binary<ZMQ_IDENTITY>
// it create with default constructor,so
// id.size = 0.

//socket_ops.hpp
//when it do this func:
template<typename Option>
static boost::system::error_code 
get_option(socket_type & socket,  Option & opt,  boost::system::error_code & ec) {
    BOOST_ASSERT_MSG(socket, "invalid socket");
    size_t size = opt.size();
    auto rc = zmq_getsockopt(socket.get(), opt.name(), opt.data(), &size);
    //if size = 0 ,rc = -1;
    if (rc < 0)
        ec = make_error_code();
    return ec;
}

solution

boost::asio::io_context ioc;
azmq::socket client(ioc,ZMQ_STREAM);
client.connect(ADDRESS);
string id_str('0',5);
azmq::socket::identity id(id_str);
client.get_option(id);

Is it possible to add a constructor for this option?

 binary(size_t sz) {
     data_.resize(sz);
     pv_ = data_.data();
    size_ = sz;
 }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant