riebl/vanetza

Blocking Runtime.schedule

buraksenkus opened this issue · 2 comments

Hi,

I've implemented very basic CaService and TLMService in facilities layer. CaService is very similar to CamApplication in socktap. I'm passing trigger.runtime() object into both CaService and TLMService to use in scheduling of periodic operations in these services.

I connect to a remote TCP socket in TLMService and get some data from it. When the connection is successfully established, I do not have any problems (CaService and TLMService's CAM and SPATEM messages can be seen on Wireshark at the required intervals), but if the remote TCP socket cannot be accessed, the connection operation waits for about 1 minute. During this time, naturally, SPATEM is not sent, but at the same time, CAMs are not produced. As far as I understand, the schedule function in the Runtime object works sequentially and if any callback is blocked (long-running operation), the next callbacks cannot be invoked.

Does the Runtime really work that way or am I using the wrong method to run multiple services asynchronously?

riebl commented

Yes, the callbacks invoked by Vanetza::Runtime are expected to return quickly. If you need to mix Vanetza code with "real" sockets, I suggest switching them to asynchronous mode. For example, you may use Boost.Asio for your TCP communications and call its io_context::run_one method periodically via a Vanetza::Runtime callback or use separate threads for both.

OK then. I'll try that way. Thanks!