[zeromq-dev] patch: handle idle connections

Martin Sustrik sustrik at fastmq.com
Thu Mar 26 14:16:28 CET 2009

> Here's a diagram of flipping active to passive (or vice versa)...

The same thing in pseudocode:

vector <pipe_t*> pipes;
int active; // number of active pipes
int current; // index of the current pipe in the array

To get next active pipe:

current = (current + 1) % active;
return pipes [current];

To flip pipe x from active to passive state:

std::swap (pipes [x], pipes [active - 1]);

To flip pipe x from passive to active state:

std::swap (pipes [x], pipes [active]);

A side note: I've did an analysis of the algorithm and although it looks 
kind of strange it actually turns out that it provides fairness 
guarantee in the presence of network hickups (connections flipped to 
passive and then to active almost immediately). Interestingly enough, 
obvious solutions (like maintaining two linked lists or having a single 
array with each element flagged as active/passive) don't provide this 
guarantee. If anyone is interested in the math, I can provide it.


More information about the zeromq-dev mailing list