[erlang-questions] knowing if messages are available with 'ei'

Samuel Hornus samuel.hornus@REDACTED
Fri Mar 23 07:35:56 CET 2007

Please pardon my ignorance as I'm new to Erlang.
I am implementing a C-node that send and receive messages to erlang
processes. I'm using the 'ei' library.
I'd like to know if there is a way to check wether a message has
arrived or not ?
Currently I do this with :

int got = ei_xreceive_msg_tmo(gFD, &emsg, &eibuf, 1);

This has many problems : 1/ it does eat at least 1precious millisecond (probably
much more). 2/ if the mailbox is empty, it returns an error due to
timeout, which
can be confused with "real" errors.
So, is there a nicer solution ? or a way to avoid checking for new messages ?

The reason is that the C-node implements graphical representation every, say,
30 milliseconds. Before re-drawing, I wantto check if new messages modifying
the state of the elements to be drawn have arrived or not... witout wasting 1
millisecond timeout.

Also, is there a way to do that in Erlang (maybe with 'after 0' statement in a
receive expression, but I'm not sure).
Thanks you very much,

More information about the erlang-questions mailing list