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.