xiaoxiang781216 commented on code in PR #7675: URL: https://github.com/apache/incubator-nuttx/pull/7675#discussion_r1031403475
########## net/tcp/tcp_monitor.c: ########## @@ -165,10 +165,7 @@ static uint16_t tcp_monitor_event(FAR struct net_driver_s *dev, /* Clear the socket error */ -#ifdef CONFIG_NET_SOCKOPTS - conn->sconn.s_error = OK; -#endif - set_errno(OK); + _SO_CONN_SETERRNO(&conn->sconn, OK); Review Comment: _SO_CONN_SETERRNO(conn, OK); ########## net/socket/net_sendfile.c: ########## @@ -133,8 +133,7 @@ ssize_t psock_sendfile(FAR struct socket *psock, FAR struct file *infile, if (ret < 0) { - FAR struct socket_conn_s *conn = psock->s_conn; - conn->s_error = -ret; + _SO_CONN_SETERRNO((FAR struct socket_conn_s *)psock->s_conn, -ret); Review Comment: move the cast to _SO_CONN_SETERRNO ########## net/tcp/tcp_netpoll.c: ########## @@ -128,10 +128,7 @@ static uint16_t tcp_poll_eventhandler(FAR struct net_driver_s *dev, reason = ECONNREFUSED; } -#ifdef CONFIG_NET_SOCKOPTS - info->conn->sconn.s_error = reason; -#endif - set_errno(reason); + _SO_CONN_SETERRNO(&info->conn->sconn, reason); Review Comment: _SO_CONN_SETERRNO(info->conn, reason); ########## net/socket/socket.h: ########## @@ -94,18 +94,30 @@ /* Macro to set socket errors */ #ifdef CONFIG_NET_SOCKOPTS +# define _SO_CONN_SETERRNO(c,e) \ + do \ + { \ + (c)->s_error = (int16_t)e; \ + set_errno(e); \ + } \ + while (0) + # define _SO_SETERRNO(s,e) \ do \ { \ if (s != NULL && (s)->s_conn != NULL) \ { \ FAR struct socket_conn_s *_conn = (s)->s_conn; \ - _conn->s_error = (int16_t)e; \ + _SO_CONN_SETERRNO(_conn, e); \ Review Comment: _SO_CONN_SETERRNO((s)->s_conn, e); and remove line 109 ########## net/rpmsg/rpmsg_sockif.c: ########## @@ -287,11 +286,9 @@ static int rpmsg_socket_ept_cb(FAR struct rpmsg_endpoint *ept, nxmutex_lock(&conn->recvlock); conn->sendsize = head->size; - if (conn->psock) - { - conn->sconn.s_flags |= _SF_CONNECTED; - _SO_SETERRNO(conn->psock, OK); - } + conn->sconn.s_flags |= _SF_CONNECTED; + + _SO_CONN_SETERRNO(&conn->sconn, OK); Review Comment: _SO_CONN_SETERRNO(conn, OK); ########## net/can/can_recvmsg.c: ########## @@ -608,7 +606,7 @@ ssize_t can_recvmsg(FAR struct socket *psock, FAR struct msghdr *msg, } #endif - state.pr_sock = psock; + state.pr_conn = conn; Review Comment: remove extra space before = ########## net/socket/socket.h: ########## @@ -94,18 +94,30 @@ /* Macro to set socket errors */ #ifdef CONFIG_NET_SOCKOPTS +# define _SO_CONN_SETERRNO(c,e) \ + do \ + { \ + (c)->s_error = (int16_t)e; \ + set_errno(e); \ + } \ + while (0) + # define _SO_SETERRNO(s,e) \ do \ { \ if (s != NULL && (s)->s_conn != NULL) \ Review Comment: let's move (s)->s_conn check to _SO_CONN_SETERRNO -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org