zeromq / libzmq

ZeroMQ core engine in C++, implements ZMTP/3.1
https://www.zeromq.org
Mozilla Public License 2.0
9.53k stars 2.34k forks source link

zmq_setsockopt should allow to set ZMQ_MULTICAST_HOPS to 0 #4572

Open NoAnyLove opened 1 year ago

NoAnyLove commented 1 year ago

Issue description

According to the following references, the valid TTL, which is referred as multicast hops in zmq, is from 0 to 255.

It is useful to set it to 0 when user wants to multicast data to consumers on the same host.

However, several checks in zmq code prevent user to set ZMQ_MULTICAST_HOPS to , e.g.,

Besides, it does not have upper limit check either (<= 255).

Minimal test code / Steps to reproduce the issue

#include <stdio.h>
#include <zmq.h>

int main() {
  void* ctx = zmq_ctx_new();
  void* socket = zmq_socket(ctx, ZMQ_RADIO);
  int value = 0;
  int rc = zmq_setsockopt(socket, ZMQ_MULTICAST_HOPS, &value, sizeof(value));
  printf("rc=%d\n", rc);
}

What's the actual result? (include assertion message & call stack if applicable)

It outputs,

rc=-1

What's the expected result?

I'm expecting it works and rc returns 0.