On 4/16/2020 3:20 PM, r.gokool@... wrote:
Hello, I am new to Zephyr. I have a need to write code that runs on both RTOS and linux. It is structured as an event loop that can monitor sockets, local queues and timers for Linux. When looking at the APIs in the RTOS I noticed that there is no common poll API. Isee k_poll() can poll kernel objects while zsock_poll() can poll sockets. Is there a way to monitor sockets and kernel objects using the same event loop?Mostly for the same sorts of reasons that poll() in Linux can't wait on a POSIX condition variable or futex.
The zsock_poll() implementation is designed to work the way it works on existing Berkley sockets code, and it understands sockets in the network layer. The kernel k_poll() abstraction understands existing kernel objects, which aren't sockets.
That said, it wouldn't be impossible to make these interoperate. The k_poll_event object has a "signal" type which allows arbitrary external code to provide wakeup notifications to threads blocked in k_poll(). Someone could write a constructor for such a k_poll_event in the network layer without too much trouble, I think.
It's possible we could remove the zsock_poll() implementation entirely and replace it with this sort of wrapper around k_poll, actually. But I haven't looked at that implementation and don't know what would be involved or what the costs might be.