This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

BSD Library nrf_connect() results an EINPROGRESS error when non blocking is enabled

Hi, 

Is it expected to get an EINPROGRESS error when calling nrf_connect() with NRF_O_NONBLOCK set. How do I know if the call was successful or not? Should I expect a positive result from nrf_poll()?

By the way our firmware is running on a custom OS and preferred non blocking calls in this current situation. 

Thank you. 

mcGyver

  • Hi,

     

    I can confirm that the behavior is to return NRF_EINPROGRESS with O_NONBLOCK configured in fcntl().

    For connect, this is the intended behavior, per the "man connect":

           EINPROGRESS
                  The socket is nonblocking and the connection cannot be
                  completed immediately.  (UNIX domain sockets failed with
                  EAGAIN instead.)  It is possible to select(2) or poll(2) for
                  completion by selecting the socket for writing.  After
                  select(2) indicates writability, use getsockopt(2) to read the
                  SO_ERROR option at level SOL_SOCKET to determine whether
                  connect() completed successfully (SO_ERROR is zero) or
                  unsuccessfully (SO_ERROR is one of the usual error codes
                  listed here, explaining the reason for the failure).

     

    EINPROGRESS (or possible EAGAIN) should be expected for connect().

     

    Kind regards,

    Håkon

  • With regards to the non-blocking nrf_connect(), how do I check and make sure that the nrf_connect() has successfully been initiated?

    I have tried using nrf_getsockopt(). This function returns good but when I do nrf_send() it would always returns a NRF_ENOTCONN error. 

    SOCK_NO_ERROR == nrf_getsockopt(sock, NRF_SOL_SOCKET, NRF_SO_ERROR, &optVal, &optLen)
    if (optVal == 0) {
        Socket[sock].state = stateConnected;
    }

    How do I properly poll for the result of nrf_connect()?

Related