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 3b172f44c47859906e62f83c99f9370886376f52 Author: chenrun1 <[email protected]> AuthorDate: Thu Nov 12 13:47:39 2026 +0800 fs/socket: add readv and writev to the socket file operations The socket file operations have no readv or writev method, so readv() and writev() on a socket descriptor fall back to one read or write call per iovec. On a datagram socket writev() sends each buffer as a separate datagram, and readv() truncates a datagram to the first buffer and then waits for another datagram for the next. Implement them with psock_recvmsg() and psock_sendmsg(), so the whole iovec is one message, and raise SIGPIPE from writev() as sock_file_write() does. Signed-off-by: chenrun1 <[email protected]> Signed-off-by: jingfei <[email protected]> --- fs/socket/socket.c | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/fs/socket/socket.c b/fs/socket/socket.c index 306cea6684a..03c475e5057 100644 --- a/fs/socket/socket.c +++ b/fs/socket/socket.c @@ -36,6 +36,7 @@ #include <assert.h> #include <fcntl.h> #include <errno.h> +#include <string.h> #include <nuttx/debug.h> #include "inode/inode.h" @@ -56,6 +57,10 @@ static int sock_file_ioctl(FAR struct file *filep, int cmd, 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); +static ssize_t sock_file_readv(FAR struct file *filep, + FAR struct uio *uio); +static ssize_t sock_file_writev(FAR struct file *filep, + FAR struct uio *uio); /**************************************************************************** * Private Data @@ -71,7 +76,9 @@ static const struct file_operations g_sock_fileops = sock_file_ioctl, /* ioctl */ NULL, /* mmap */ sock_file_truncate, /* truncate */ - sock_file_poll /* poll */ + sock_file_poll, /* poll */ + sock_file_readv, /* readv */ + sock_file_writev, /* writev */ }; static struct inode g_sock_inode = @@ -154,6 +161,33 @@ static int sock_file_truncate(FAR struct file *filep, off_t length) return -EINVAL; } +static ssize_t sock_file_readv(FAR struct file *filep, + FAR struct uio *uio) +{ + struct msghdr msg; + + memset(&msg, 0, sizeof(struct msghdr)); + msg.msg_iov = (FAR struct iovec *)uio->uio_iov; + msg.msg_iovlen = uio->uio_iovcnt; + + return psock_recvmsg(filep->f_priv, &msg, 0); +} + +static ssize_t sock_file_writev(FAR struct file *filep, + FAR struct uio *uio) +{ + struct msghdr msg; + ssize_t ret; + + memset(&msg, 0, sizeof(struct msghdr)); + msg.msg_iov = (FAR struct iovec *)uio->uio_iov; + msg.msg_iovlen = uio->uio_iovcnt; + + ret = psock_sendmsg(filep->f_priv, &msg, 0); + psock_sigpipe(filep->f_priv, ret, 0); + return ret; +} + /**************************************************************************** * Public Functions ****************************************************************************/
