[zeromq-dev] Round robin problems with offline servers

Ian Barber ian.barber at gmail.com
Fri Jun 1 19:01:59 CEST 2012


OK, I've knocked up a patch that demonstrates this functionality with the
use of a sockopt ZMQ_DELAY_ATTACH_ON_CONNECT - I would really appreciate a
review on it, to make sure I haven't borked anything, or done something
horrible with session_base_t:

https://github.com/zeromq/libzmq/pull/357

The sample programme from Ben now appropriately balances to the one
connected node:

#include <cstdlib>
#include <cstring>
#include <iostream>

#include "zmq.h"

int main (void)
{
       void *context = zmq_ctx_new();
       int val = 1;

       void *to = zmq_socket(context, ZMQ_PULL);
       zmq_bind(to, "tcp://*:5555");

       void *from = zmq_socket (context, ZMQ_PUSH);
       zmq_setsockopt(from, ZMQ_DELAY_ATTACH_ON_CONNECT, &val, sizeof(val));
       zmq_connect(from, "tcp://localhost:5556");
       zmq_connect(from, "tcp://localhost:5555");

       for (int i = 0; i < 10; ++i)
       {
               std::string message("message ");
               message += ('0' + i);

               std::cout << "Sending " << message << std::endl;
               zmq_send(from, message.data(), message.size(), 0);
       }

       char buffer[16];
       for (int i = 0; i < 10; ++i)
       {
               memset(&buffer, 0, sizeof(buffer));
               zmq_recv(to, &buffer, sizeof(buffer), 0);
               std::cout << "Got " << buffer << std::endl;
       }

       zmq_close(from);
       zmq_close(to);
       zmq_ctx_destroy(context);

       return EXIT_SUCCESS;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20120601/c9e0a55e/attachment.htm>


More information about the zeromq-dev mailing list