EVM posting and subscribing clients connect to the EVM daemon
using the EvmConnCreate() function call, and must specify one of three possible
response modes: EvmRESPONSE_IGNORE, EvmRESPONSE_WAIT, or EvmRESPONSE_CALLBACK. For
more information about modes, see EvmConnCreate(3).
The subscribing clients must specify EvmRESPONSE_CALLBACK as
the response mode. The incoming events are passed to them by the
callback function that you supply as the fourth argument to EvmConnCreate(). For an example of the usage of a callback function
by a subscribing client, see “Subscribing Event
Notifications”.
When working with a callback function, it is important to
understand that your function is not called asynchronously, in the
manner of a signal handler. Rather, your program must monitor the
connection for input activity, using EvmConnWait() or select() or a related function, and then call EvmConnDispatch() to handle the activity. EvmConnDispatch() then reads an incoming message from the connection and
invokes your callback function, if necessary. For a list of reasons
for callback being invoked, see EvmCallback(5).
As with any function, the arguments passed to your callback
function are passed on the program stack and are available only
within the scope of the function. Therefore, to save values for
use after you have returned from the callback, you must copy them
to global memory space before returning.
If the callback is reporting an incoming event and you want
to preserve the event instead of handling it and then destroying
it within the callback, you can declare a globally accessible variable
of type EvmEvent_t and assign the incoming event
to it, for example:
/* In global declarations */ EvmEvent_t SavedEvent; ... /* In your callback function */ SavedEvent = cbdata->event; |
In this case, you must not destroy the event in the callback
function, because the assignment copies only the reference to the
event, not the event body. You need to destroy the event from outside
the callback function, after you have finished using the event; otherwise,
you may encounter memory leak.
For information about assigning an event, see “Reassigning and Replicating
EVM Events”.