CESNET / libnetconf2

C NETCONF library
BSD 3-Clause "New" or "Revised" License
203 stars 147 forks source link

Delucidation on nc_recv_notif_dispatch #482

Closed safesintesi closed 6 months ago

safesintesi commented 6 months ago

Hello, I'm trying to achieve a dynamic notification callback that can be changed at runtime.

From my understanding nc_recv_notif_dispatch opens a new thread that doesn't close until the end of the session (or until the stop time). If I want to change the callback can I send a nc_rpc_deletesub and then open a new subscription or does this leave the thread open? At the moment I solved this with a callback that actually calls the real changing callback passed as usr_data with a mutex to be thread-safe, but I'm not sure this is the indicated approach. Any guidance would be appreciated.

michalvasko commented 6 months ago

Yeah, the thread can only exit on its own, you cannot manually terminate it. But the idea is to have a simple asynchronous mechanism for reading notifications, not much else. If you require anything more complex, it should no trouble to write your own thread receiving notifications and doing exactly what you want. Using user_data for whatever you need is also a possibility and is certainly fine, if it works. Nevertheless, like I said, my suggestion is not to use nc_recv_notif_dispatch() at all.

safesintesi commented 6 months ago

Thank you for your time. I will move to a dedicated thread as you suggest.