From 1659513edbfeb055bb5dcacdb34fd98bf55063b5 Mon Sep 17 00:00:00 2001 From: "chao.an" Date: Tue, 8 Feb 2022 11:04:52 +0800 Subject: [PATCH] net/inet: move socket error into socket_conn_s Signed-off-by: chao.an --- include/nuttx/net/net.h | 7 ++++++- net/socket/getsockopt.c | 4 ++-- net/socket/net_sendfile.c | 4 ++-- net/socket/socket.h | 5 +++-- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/include/nuttx/net/net.h b/include/nuttx/net/net.h index 778104b823..bdce837623 100644 --- a/include/nuttx/net/net.h +++ b/include/nuttx/net/net.h @@ -233,6 +233,12 @@ struct socket_conn_s uint8_t s_flags; /* See _SF_* definitions */ + /* Socket options */ + +#ifdef CONFIG_NET_SOCKOPTS + int16_t s_error; /* Last error that occurred on this socket */ +#endif + /* Connection-specific content may follow */ }; @@ -251,7 +257,6 @@ struct socket /* Socket options */ #ifdef CONFIG_NET_SOCKOPTS - int16_t s_error; /* Last error that occurred on this socket */ sockopt_t s_options; /* Selected socket options */ socktimeo_t s_rcvtimeo; /* Receive timeout value (in deciseconds) */ socktimeo_t s_sndtimeo; /* Send timeout value (in deciseconds) */ diff --git a/net/socket/getsockopt.c b/net/socket/getsockopt.c index 34142311e5..6696b4e624 100644 --- a/net/socket/getsockopt.c +++ b/net/socket/getsockopt.c @@ -242,8 +242,8 @@ static int psock_socketlevel_option(FAR struct socket *psock, int option, return -EINVAL; } - *(FAR int *)value = (int)psock->s_error; - psock->s_error = 0; + *(FAR int *)value = (int)conn->s_error; + conn->s_error = 0; } break; diff --git a/net/socket/net_sendfile.c b/net/socket/net_sendfile.c index 5138782019..ec262edcd2 100644 --- a/net/socket/net_sendfile.c +++ b/net/socket/net_sendfile.c @@ -113,7 +113,6 @@ ssize_t psock_sendfile(FAR struct socket *psock, FAR struct file *infile, if (psock == NULL || psock->s_conn == NULL) { nerr("ERROR: Invalid socket\n"); - psock->s_error = EBADF; return -EBADF; } @@ -134,7 +133,8 @@ ssize_t psock_sendfile(FAR struct socket *psock, FAR struct file *infile, if (ret < 0) { - psock->s_error = -ret; + FAR struct socket_conn_s *conn = psock->s_conn; + conn->s_error = -ret; } return ret; diff --git a/net/socket/socket.h b/net/socket/socket.h index 1a9829f690..e00bd457b3 100644 --- a/net/socket/socket.h +++ b/net/socket/socket.h @@ -95,9 +95,10 @@ # define _SO_SETERRNO(s,e) \ do \ { \ - if (s != NULL) \ + if (s != NULL && (s)->s_conn != NULL) \ { \ - s->s_error = (int16_t)e; \ + FAR struct socket_conn_s *_conn = (s)->s_conn; \ + _conn->s_error = (int16_t)e; \ } \ set_errno(e); \ } \