zeromq/libzmq — pull request #626 by dkrikun (2013-08-17 23:57:18+00:00)
Title: Add ZMQ_CONFLATE socket option

ZMQ_CONFLATE socket option forces a socket to keep only *the most recent message* in its inbound/outbound queue, older messages are discarded.
It is applicable both for sender and receiver: sending socket will pass to the application the most recent message it has received; receiving socket will send only the most recent message it got from the application.
Supported socket types: pull/push, pub/sub and dealer.
If the option is set, HWM *is ignored*, which makes sense.
Multi-part messages are currently *not supported*, in particular, only one part of the multi-part message is kept, which is certainly not good.

Implementation details:
Double buffer is used instead of lock-free queue to achieve the desired effect. The double-buffer implementation is not lock-free, it probably might be improved, though I've failed to observe any performance degradation due to mutexes.

Some use-case example: https://gist.github.com/dkrikun/6259172
Relevant discussion on the mail-list: http://lists.zeromq.org/pipermail/zeromq-dev/2013-August/022434.html