How to become notified of BSD non-blocking events

Hi there,

I'm intending to use the nrfxlib modem library and its BSD socket implementation on the nRF9160. My goal is to use non-blocking APIs and use `nrf_poll` in response to various events.

For example, I'd like to use `nrf_recv` (1) with `NRF_O_NONBLOCK` and then receive a notification when there is data available given its respective file descriptor. To achieve this, I'm wondering if I can connect an IPC RECEIVE event with all IPC channels, which'd see that `nrf_poll` is then called by my code.

Thanks for any guidance here.

(1) https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrfxlib/nrf_modem/doc/api.html#group__nrf__socket__api_1ga1a288076f560857cb46fa0df46e1c7e5

Parents Reply Children
  • Triggering of a hw event indicates that something has happened, it does not indicate what. This comes by parsing the data, which is done in the "libmodem", which then exposes a given API towards your application. 

    Yes, understood. I'm happy to call poll often even if the peripheral event is only a hint toward poll needing to be called.

    This is the callback that is triggered when one (or more) events have occurred on a socket:

    I should explain that I'm not using Zephyr. However, it appears that the purpose of this callback is to sleep. I don't want to do that. :-) I want my program to call poll if it is likely that there has been some socket activity. Apologies if I'm being unclear. I appreciate your replies.

  • Hi,

     

    Have you looked at this page in the docs?

    https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrfxlib/nrf_modem/doc/ug_nrf_modem_porting_os.html#

     

    Christopher Hunt said:
    However, it appears that the purpose of this callback is to sleep. I don't want to do that. :-) I want my program to call poll if it is likely that there has been some socket activity. Apologies if I'm being unclear. I appreciate your replies.

    No apologies necessary, I'm equal to blame for misunderstanding!

     

    You're halfway right in the understanding of the function, its main purpose is to sleep for a timeout-period or until something happens on that specific socket. Think of it as an event based system.

    The specific function takes a semaphore/mutex, with a timeout provided by the socket call, and if an event occurs before the timeout, it will give the sem/mutex and return an event to the application.

     

    Kind regards,

    Håkon

Related