This is an automated email from the ASF dual-hosted git repository. GUIDINGLI pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit e92dc2ba576fe34f511124dd3c8ee9570624b42a Author: yintao <[email protected]> AuthorDate: Wed Sep 10 17:05:27 2025 +0800 net: let a socket address family implement mmap() mmap() on a socket file always failed because sock_file_ops has no mmap method. Add si_mmap to struct sock_intf_s and call it from a new sock_file_mmap(); an address family without it returns -EOPNOTSUPP. Signed-off-by: yintao <[email protected]> Signed-off-by: Bowen Wang <[email protected]> --- fs/socket/socket.c | 23 ++++++++++++++++++++++- include/nuttx/net/net.h | 3 +++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/fs/socket/socket.c b/fs/socket/socket.c index 03c475e5057..a9474886821 100644 --- a/fs/socket/socket.c +++ b/fs/socket/socket.c @@ -31,6 +31,7 @@ #include <nuttx/fs/fs.h> #include <nuttx/fs/uio.h> #include <nuttx/mm/mm.h> +#include <nuttx/mm/map.h> #include <sys/socket.h> #include <assert.h> @@ -54,6 +55,8 @@ static ssize_t sock_file_write(FAR struct file *filep, FAR const char *buffer, size_t buflen); static int sock_file_ioctl(FAR struct file *filep, int cmd, unsigned long arg); +static int sock_file_mmap(FAR struct file *filep, + FAR struct mm_map_entry_s *map); static int sock_file_poll(FAR struct file *filep, struct pollfd_s *fds, bool setup); static int sock_file_truncate(FAR struct file *filep, off_t length); @@ -74,7 +77,7 @@ static const struct file_operations g_sock_fileops = sock_file_write, /* write */ NULL, /* seek */ sock_file_ioctl, /* ioctl */ - NULL, /* mmap */ + sock_file_mmap, /* mmap */ sock_file_truncate, /* truncate */ sock_file_poll, /* poll */ sock_file_readv, /* readv */ @@ -150,6 +153,24 @@ static int sock_file_ioctl(FAR struct file *filep, int cmd, return psock_ioctl(filep->f_priv, cmd, arg); } +static int sock_file_mmap(FAR struct file *filep, + FAR struct mm_map_entry_s *map) +{ + struct socket *psock = filep->f_priv; + + DEBUGASSERT(psock != NULL && map != NULL); + + /* Let the address family's mmap() method handle the operation */ + + DEBUGASSERT(psock->s_sockif != NULL); + if (psock->s_sockif->si_mmap == NULL) + { + return -EOPNOTSUPP; + } + + return psock->s_sockif->si_mmap(psock, map); +} + static int sock_file_poll(FAR struct file *filep, FAR struct pollfd_s *fds, bool setup) { diff --git a/include/nuttx/net/net.h b/include/nuttx/net/net.h index f0a71f0c1bd..4872b1c2dcd 100644 --- a/include/nuttx/net/net.h +++ b/include/nuttx/net/net.h @@ -38,6 +38,7 @@ #include <nuttx/queue.h> #include <nuttx/mutex.h> +#include <nuttx/mm/map.h> #ifdef CONFIG_MM_IOB # include <nuttx/mm/iob.h> #endif @@ -197,6 +198,8 @@ struct sock_intf_s FAR struct file *infile, FAR off_t *offset, size_t count); #endif + CODE int (*si_mmap)(FAR struct socket *psock, + FAR struct mm_map_entry_s *map); }; /* Each socket refers to a connection structure of type FAR void *. Each
