I have an existing application that makes extensive use of libev for its event loop. I would now like to add OPC UA server functionality, but am unsure how best to integrate the open62541 event loop into libev.
The following possibilities come to mind:
- Call
UA_Server_run_iterate
from within the libev event loop with awaitInternal
time of 0. This would either mean that the server could never sleep (polling open62541 in anev_idle
), or that requests from an OPC UA client would experience an additional latency of up to 50ms (the default max wait time of open62541). - Patch open62541 to allow retrieval of the file descriptors currently in use (serverSockets and connections) by the server network layer. This would allow adding libev events for those file descriptors, which could in turn poll
UA_Server_run_iterate
only when necessary. - Implement a custom server network layer that makes use of libev. This seems to imply quite a bit of code duplication... Are there any examples/tutorials for implementing a custom network layer?
- Run the open62541 event loop in a separate thread. I really really really want to avoid this, since the whole purpose of an event system such as libev is to avoid issues associated with asynchronous operation. For example, all callbacks from open62541 would have to synchronize with the the main libev thread.
Which of the above options would you consider "best" in terms of complexity and performance?
Can you think of any other options not listed above?