This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

nRF9160 select() always returns 115

I have an nRF9160 with nrfx v2.5.0 and nrfxlib v1.5.1. We have integrated nrf_modem into our own OS. I would like to use TCP sockets asynchronously, but cannot establish a nonblocking connection.

I can establish a TCP connection to our server while blocking with no issues. I suspect I'm also getting a successful connection to the server in the nonblocking case too, but I cannot find a way to determine if the connection has been established.

I have tried polling on nrf_getsockopt(sock, NRF_SOL_SOCKET, NRF_SO_ERROR... ). This works in the case where the server disconnects (i.e. I get an error code), but there is nothing to indicate a successful connection.

The standard posix way of doing this would be to call select() and wait for writing to come available. No matter what I do, nrf_select() always returns 115 (EINPROGRESS), and does so immediately after calling.

I would expect that even if I were doing something wrong, the following would run until it timed out:

nrf_select(sock + 1, NULL, NULL, NULL, &tv);

but this also returns immediately with 115. I suspect that there is a subtlety in the API that I am missing.

Procedure overview:

  • nrf_fcntl(sock, NRF_F_GETFL, 0);
  • nrf_fcntl(sock, NRF_F_SETFL, res | NRF_O_NONBLOCK);
  • nrf_connect(sock, &zzz, sizeof(zzz));
  • nrf_select(sock + 1, NULL, &fdset, NULL, &tv); - returns 115, no matter  what I do with the arguments. I am using NRF_FD_ZERO, NRF_FD_SET.
  • nrf_getsockopt(sock, NRF_SOL_SOCKET, NRF_SO_ERROR, ...); - tells me when the link goes down but not when the connection is successful.

TLDR: The root issue I am trying to solve is: how do I determine that my NONBLOCKING nrf_connect() has successfully connected with nrf_modem. I would also like to know what is going wrong with nrf_select() that is preventing me from using it, but this is less important.

Parents Reply Children
  • Hi Markus, thank you for following up with my select() enquiry. For clarification, I am receiving -1 in case of error, but I get 115 when I pull errno (i.e. that set by nrf_modem_os_errno_set()) . It is perhaps possible that select() is a function that does not set errno, though this seems unlikely as I had cleared errno prior to calling select().

    Regardless, is there anywhere that it is publicly documented that select() only works under Zephyr? I'm just interested in understanding what I have missed, because I have sunk a lot of time into trying to understand something that was never going to work for me. If it's not documented, may I ask that it be added to the documentation of that function so others don't similarly get let astray?

    Thanks again.

Related