The modem sockets poll implementation does not allow
a combination of poll on modem sockets and on other sockets
like eventfd. This blocks trivial application signalling. Current
users are using a poll timeout, which needs to check if other
work needs to be done in the thread (eg: lwm2m engine).
To allow proper signalling with eventfd, the non offload poll
methods needs to work for the modem sockets.
This commit is implementing this for POLLIN.
Signed-off-by: Wouter Cappelle <wouter.cappelle@crodeon.com>
The current modem sockets poll implementation has 2 limitations
as of today:
- not following posix spec wrt timeout of -1 (should be forever,
but as today it's was returning immediately)
- not able to poll from multiple threads on different sockets
on the same modem.
This pull request should implement these limitations.
Signed-off-by: Wouter Cappelle <wouter.cappelle@crodeon.com>
z_free_fd() is called twice then you close(). For example in ublox sara
r4 driver offload_close() calls modem_socket_put() where z_free_fd() is
called first time. Then this same function is called another time in
socket.c in z_impl_zsock_close() after this function has called
offload_close() in ublox sara r4 driver. This causes socket
descriptor leak.
Fixes#26819
Signed-off-by: Akseli Peltola <peltsu1324@gmail.com>
Some data where not properly reset on socket_put() and not correctly
initialized at socket creation. Which means we were potentially re-using
data from previous use of this socket.
Signed-off-by: Xavier Chapron <xavier.chapron@stimio.fr>
Before this commit, if a socket had received data before calling the
poll function, then the poll was waiting for either new data or a
timeout.
With this fix, polled socket are check for pending data before the
semaphore wait.
Signed-off-by: Xavier Chapron <xavier.chapron@stimio.fr>
By using the Zephyr-native zsock_ family of types and functions, these
drivers will be decoupled from NET_SOCKETS_POSIX_NAMES.
Signed-off-by: Adam Porter <porter.adam@gmail.com>
This fixes some cases where an integer timeout received as a parameter
was not converted to a timeout before being used in standard API.
Changes to the POSIX library were not included as that's being
reworked in a separate PR.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
Let's add a field which the drivers can use to keep track of whether
they are connected or not. This will normally be enabled / disabled
in the socket connect and URC for socket close notify.
Signed-off-by: Michael Scott <mike@foundries.io>
Let's hide the internals of sock->packet_sizes[] by adding a function
which returns the size of the next waiting packet.
Signed-off-by: Michael Scott <mike@foundries.io>
Let's hide the internals of the modem_socket's sem_data_ready and
poll handling with 2 new functions:
- modem_socket_wait_data: take a semaphore and wait for data
- modem_socket_data_ready: give back the data ready semaphore and
unblock poll() users
Signed-off-by: Michael Scott <mike@foundries.io>
Add lock behavior for functions in modem_socket, to prevent race
conditions when performing socket data maintenance.
Signed-off-by: Michael Scott <mike@foundries.io>
Let's allow protocols to request portions of the current packet.
This is seen in the MQTT library when parsing headers for the type
and variable length of the packet.
This fixes basic parsing done in the MQTT library and probably others.
Signed-off-by: Michael Scott <mike@foundries.io>
modem_socket_put() originally took an index as a parameter and was
later swapped to sock_fd as the reference.
The internal code was never updated to reflect that sock_fd isn't an
index -- it's a separate reference generated via z_reserve_fd().
Let's correct the modem_socket_put() logic.
Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/18238
Reported-by: Tobias Svehagen <tobias.svehagen@gmail.com>
Signed-off-by: Michael Scott <mike@foundries.io>
Many modems implement socket-based APIs to manage data connections.
This layer provides much of the groundwork for keeping track of
these "sockets" throughout their lifecycle (from the initial offload
API calls through the command handler call back layers):
- structure for holding socket data like IP protocol, destination,
source and incoming packet sizes
- configuration to note modem starting socket id and number of
sockets
- methods to get/put socket structs from/to the pool
- function to update the # and size of packets in the modem receive
queue
- prebuilt modem_socket_poll() method for socket offload poll() API
Example modem driver setup code looks like this:
/* socket data */
static struct modem_socket_config socket_config;
static struct modem_socket sockets[MDM_MAX_SOCKETS];
static int modem_init(struct device *dev)
{
...
/* setup socket config */
socket_config.sockets = &sockets[0];
socket_config.sockets_len = ARRAY_SIZE(sockets);
socket_config.base_socket_num = 0;
ret = modem_socket_init(&socket_config);
...
}
Signed-off-by: Michael Scott <mike@foundries.io>