[openamq-dev] OpenAMQ and file descriptors
Martin Sustrik
sustrik at imatix.com
Sun Jan 13 10:49:31 CET 2008
Hi all,
There have been several questions about whether it is possible to
poll/select on the OpenAMQ traffic on the list.
I've coded a small example of how the thing can be done. amq_poller.h
contains a generic polling object, im_receiver.c shows how to use it.
(im_receiver.c is a modified version of im_receiver.c found here:
http://wiki.openamq.org/package:chatroom-example. You can use
im_sender.c from this page to interact with it.)
Basically, you have to create a poller object attached to your openAMQ
session:
poller = amq_poller_create (session);
Then you can poll/select on the 'fd' member of the poller object - the
only event valid is POLLIN:
struct pollfd pollset [1];
pollset [0].fd = poller->fd;
pollset [0].events = POLLIN;
Once the poll/select signals that the descriptor is ready for reading,
you can retrieve the messages in standard openAMQ way:
content = amq_client_session_basic_arrived (session);
When you are done with processing the messages, you should ask poller to
continue and then you are free to poll/select again:
amq_poller_continue (poller);
poll (...);
I would appreciate feedback on the issue. If people are happy with it,
we can post in the openAMQ web site.
Martin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: amq_poller.h
Type: text/x-chdr
Size: 4186 bytes
Desc: not available
Url : http://lists.openamq.org/pipermail/openamq-dev/attachments/20080113/720a708d/attachment.h
-------------- next part --------------
A non-text attachment was scrubbed...
Name: im_receiver.c
Type: text/x-csrc
Size: 5585 bytes
Desc: not available
Url : http://lists.openamq.org/pipermail/openamq-dev/attachments/20080113/720a708d/attachment.c
More information about the openamq-dev
mailing list