net: nsos_sockets: notify pollers on socket close

Raise the poll signal when the socket is being closed to prevent users
of `zsock_poll` blocking after the socket is no more.

Signed-off-by: Jordan Yates <jordan@embeint.com>
This commit is contained in:
Jordan Yates 2024-12-04 20:32:20 +10:00 committed by Benjamin Cabé
commit 023e266651

View file

@ -258,6 +258,7 @@ static ssize_t nsos_write(void *obj, const void *buf, size_t sz)
static int nsos_close(void *obj)
{
struct nsos_socket *sock = obj;
struct nsos_socket_poll *poll;
int ret;
ret = nsi_host_close(sock->poll.mid.fd);
@ -265,6 +266,13 @@ static int nsos_close(void *obj)
errno = nsos_adapt_get_zephyr_errno();
}
SYS_DLIST_FOR_EACH_CONTAINER(&nsos_polls, poll, node) {
if (poll == &sock->poll) {
poll->mid.revents = ZSOCK_POLLHUP;
poll->mid.cb(&poll->mid);
}
}
k_free(sock);
return ret;