Skip to content

Commit 736fe29

Browse files
mniestrojcarlescufi
authored andcommitted
drivers: nsos: support ioctl(FIONREAD)
This further increases compatibility with tests defined in 'tests/net/socket/udp/'. Signed-off-by: Marcin Niestroj <[email protected]>
1 parent cd2c425 commit 736fe29

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

drivers/net/nsos.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ void nsos_adapt_poll_update(struct nsos_mid_pollfd *pollfd);
138138
int nsos_adapt_fcntl_getfl(int fd);
139139
int nsos_adapt_fcntl_setfl(int fd, int flags);
140140

141+
int nsos_adapt_fionread(int fd, int *avail);
142+
141143
int nsos_adapt_getaddrinfo(const char *node, const char *service,
142144
const struct nsos_mid_addrinfo *hints,
143145
struct nsos_mid_addrinfo **res,

drivers/net/nsos_adapt.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <stdlib.h>
2121
#include <string.h>
2222
#include <sys/epoll.h>
23+
#include <sys/ioctl.h>
2324
#include <sys/socket.h>
2425
#include <unistd.h>
2526

@@ -939,6 +940,18 @@ int nsos_adapt_fcntl_setfl(int fd, int flags)
939940
return 0;
940941
}
941942

943+
int nsos_adapt_fionread(int fd, int *avail)
944+
{
945+
int ret;
946+
947+
ret = ioctl(fd, FIONREAD, avail);
948+
if (ret < 0) {
949+
return -errno_to_nsos_mid(errno);
950+
}
951+
952+
return 0;
953+
}
954+
942955
static void nsos_adapt_init(void)
943956
{
944957
nsos_epoll_fd = epoll_create(1);

drivers/net/nsos_sockets.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,15 @@ static int nsos_ioctl(void *obj, unsigned int request, va_list args)
371371

372372
return -errno_from_nsos_mid(-ret);
373373
}
374+
375+
case ZFD_IOCTL_FIONREAD: {
376+
int *avail = va_arg(args, int *);
377+
int ret;
378+
379+
ret = nsos_adapt_fionread(sock->pollfd.fd, avail);
380+
381+
return -errno_from_nsos_mid(-ret);
382+
}
374383
}
375384

376385
return -EINVAL;

0 commit comments

Comments
 (0)