Delivery Notifications
One of the nice things about the multithreaded API model weâre using is that itâs essentially message-based. This makes it ideal for returning events back to the caller. A more conventional API approach would be to use callbacks, but callbacks that cross thread boundaries are somewhat delicate. Hereâs how the client sends a message back when it has received a complete file:
zstr_sendm
(
self
->
pipe
,
"DELIVER"
);
zstr_sendm
(
self
->
pipe
,
filename
);
zstr_sendf
(
self
->
pipe
,
"%s/%s"
,
inbox
,
filename
);
We can now add a _recv()
method to the API that
waits for events back from the client. It makes a clean style for the
caller: create the client object, configure it, and then receive and
process any events it returns.
Get ZeroMQ now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.