drivers: nsos: support ioctl(FIONREAD)
This further increases compatibility with tests defined in 'tests/net/socket/udp/'. Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
This commit is contained in:
parent
cd2c425efe
commit
736fe29349
3 changed files with 24 additions and 0 deletions
|
|
@ -138,6 +138,8 @@ void nsos_adapt_poll_update(struct nsos_mid_pollfd *pollfd);
|
|||
int nsos_adapt_fcntl_getfl(int fd);
|
||||
int nsos_adapt_fcntl_setfl(int fd, int flags);
|
||||
|
||||
int nsos_adapt_fionread(int fd, int *avail);
|
||||
|
||||
int nsos_adapt_getaddrinfo(const char *node, const char *service,
|
||||
const struct nsos_mid_addrinfo *hints,
|
||||
struct nsos_mid_addrinfo **res,
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/epoll.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
|
@ -939,6 +940,18 @@ int nsos_adapt_fcntl_setfl(int fd, int flags)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int nsos_adapt_fionread(int fd, int *avail)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = ioctl(fd, FIONREAD, avail);
|
||||
if (ret < 0) {
|
||||
return -errno_to_nsos_mid(errno);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void nsos_adapt_init(void)
|
||||
{
|
||||
nsos_epoll_fd = epoll_create(1);
|
||||
|
|
|
|||
|
|
@ -371,6 +371,15 @@ static int nsos_ioctl(void *obj, unsigned int request, va_list args)
|
|||
|
||||
return -errno_from_nsos_mid(-ret);
|
||||
}
|
||||
|
||||
case ZFD_IOCTL_FIONREAD: {
|
||||
int *avail = va_arg(args, int *);
|
||||
int ret;
|
||||
|
||||
ret = nsos_adapt_fionread(sock->pollfd.fd, avail);
|
||||
|
||||
return -errno_from_nsos_mid(-ret);
|
||||
}
|
||||
}
|
||||
|
||||
return -EINVAL;
|
||||
|
|
|
|||
Loading…
Reference in a new issue