From 561973060e7dddd088d5bdf1f50fe023f8e1eff4 Mon Sep 17 00:00:00 2001 From: Robert Lubos Date: Tue, 14 Jan 2020 13:59:12 +0100 Subject: [PATCH] net: sockets: Extend ioctl poll protocol with offloading feature Allow to use offloaded `poll` implementation via the existing ioctl poll control mechanism. Signed-off-by: Robert Lubos --- include/sys/fdtable.h | 1 + subsys/net/lib/sockets/sockets.c | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/include/sys/fdtable.h b/include/sys/fdtable.h index 370f11b0f29..0cd4b2513d0 100644 --- a/include/sys/fdtable.h +++ b/include/sys/fdtable.h @@ -140,6 +140,7 @@ enum { ZFD_IOCTL_LSEEK, ZFD_IOCTL_POLL_PREPARE, ZFD_IOCTL_POLL_UPDATE, + ZFD_IOCTL_POLL_OFFLOAD, ZFD_IOCTL_GETSOCKNAME, }; diff --git a/subsys/net/lib/sockets/sockets.c b/subsys/net/lib/sockets/sockets.c index 396556a31ec..14beb9f6fa1 100644 --- a/subsys/net/lib/sockets/sockets.c +++ b/subsys/net/lib/sockets/sockets.c @@ -1052,7 +1052,7 @@ int z_impl_zsock_poll(struct zsock_pollfd *fds, int nfds, int timeout) pev = poll_events; for (pfd = fds, i = nfds; i--; pfd++) { - struct net_context *ctx; + void *ctx; int result; /* Per POSIX, negative fd's are just ignored */ @@ -1077,6 +1077,16 @@ int z_impl_zsock_poll(struct zsock_pollfd *fds, int nfds, int timeout) */ timeout = K_NO_WAIT; continue; + } else if (result == -EXDEV) { + /* If POLL_PREPARE returned EXDEV, it means + * it detected an offloaded socket. + * In case the fds array contains a mixup of offloaded + * and non-offloaded sockets, the offloaded poll handler + * shall return an error. + */ + return z_fdtable_call_ioctl(vtable, ctx, + ZFD_IOCTL_POLL_OFFLOAD, + fds, nfds, timeout); } else if (result != 0) { errno = -result; return -1; @@ -1098,7 +1108,7 @@ int z_impl_zsock_poll(struct zsock_pollfd *fds, int nfds, int timeout) pev = poll_events; for (pfd = fds, i = nfds; i--; pfd++) { - struct net_context *ctx; + void *ctx; int result; pfd->revents = 0;