libzmq: zmq_socket options ZMQ_RCVHWM, ZMQ_SNDHWM ignored
Hi! I use zeromq-4.0.5 library, from sources without any patches. My system is:
~ $ uname -a
Linux deb-dev-test 3.2.0-4-amd64 #1 SMP Debian 3.2.65-1+deb7u2 x86_64 GNU/Linux
~ $ cat /etc/debian_version
7.8
I’m try to use ZMQ_RCVHWM & ZMQ_SNDHWM options on ZMQ_PAIR/ZMQ_PUSH sockets, but this has no effect.
Pubilsher code:
#include <iostream>
#include <zmq.hpp>
int main(int, char**) {
zmq::context_t context (1);
zmq::socket_t socket (context, ZMQ_PAIR);
int HWM = 1;
socket.setsockopt(ZMQ_SNDHWM, &HWM, sizeof(HWM));
socket.setsockopt(ZMQ_RCVHWM, &HWM, sizeof(HWM));
socket.bind("tcp://*:9876");
int count = 0;
while(true) {
zmq::message_t msg(1024);
socket.send(msg);
std::cout << "count " << count << '\n';
count++;
}
}
Subscriber code:
#include <unistd.h>
#include <iostream>
#include <zmq.hpp>
int main(int, char**) {
zmq::context_t context (1);
zmq::socket_t socket (context, ZMQ_PAIR);
int HWM = 1;
socket.setsockopt(ZMQ_RCVHWM, &HWM, sizeof(HWM));
socket.setsockopt(ZMQ_SNDHWM, &HWM, sizeof(HWM));
socket.connect("tcp://127.0.0.1:9876");
int count = 0;
while(true) {
zmq::message_t msg;
socket.recv(&msg);
std::cout << "count " << count << '\n';
count++;
usleep(1000000);
}
}
I expect that the publisher will be blocked, after sending second message. But this doesn’t happen. Publisher example:
$ ./pub
count 0
count 1
count 2
count 3
******
count 385
count 386
count 387
count 388
^C
Subscriber at same moment:
roman@deb-dev-test.virtual cpp $ ./sub
count 0
count 1
^C
What I do wrong, or this is bug?
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 18 (9 by maintainers)
I’m seeing a related HWM issue where values below 1000 appear to be ignored. I put together a test case and write up. I have also seen the broker in my example buffer all 100000 messages but I haven’t been able to reproduce it reliably.