ZeroMQ setsockopt和getsockopt返回无效参数

时间:2015-11-18 01:59:59

标签: c++ zeromq

int main () 
{
    zmq::context_t context(1);

    //  Socket to talk to clients
    zmq::socket_t push (context, ZMQ_PUSH);
    unsigned long long hwm;
    size_t hwmsz;
    push.getsockopt( ZMQ_HWM, &hwm, &hwmsz);
    cout << "HWM:" << hwm << endl;
}

使用zeromq 4.1.4版执行上述代码会导致以下异常。任何套接字选项都会导致setsockopt()getsockopt()的参数无效。

terminate called after throwing an instance of 'zmq::error_t'
  what():  Invalid argument
Aborted (core dumped)

2 个答案:

答案 0 :(得分:0)

您可能需要根据API规范检查代码以获取详细信息:

socket_t::socket_t(        context_t  &context,
                           int         type
                           );

映射到ZeroMQ API:

void *zmq_socket (   void *context,
                     int   type
                     );

void socket_t::getsockopt( int         option_name,
                           void       *option_value,
                           size_t     *option_len
                           );

映射到ZeroMQ API:

int zmq_getsockopt ( void   *socket,
                     int     option_name,
                     void   *option_value,
                     size_t *option_len
                     );

答案 1 :(得分:0)

首先:必须初始化选项长度。

size_t hwmsz = sizeof(unsigned long long);

第二件事:

ZMQ_HWM - 这是一个弃用的选项吗?

尝试获取ZMQ_SNDHWM和ZMQ_RCVHWM的值(它们是int`s)