net/soerr: add new _SO_CONN_SETERRNO() macro

support so error code set from conn instance

Signed-off-by: chao an <anchao@xiaomi.com>
This commit is contained in:
chao an
2022-11-24 19:15:10 +08:00
committed by Xiang Xiao
parent 6d8c28a83c
commit f2a7711ef8
4 changed files with 22 additions and 13 deletions
+1 -2
View File
@@ -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_SETERRNO(psock, -ret);
}
return ret;
+19 -3
View File
@@ -94,18 +94,34 @@
/* Macro to set socket errors */
#ifdef CONFIG_NET_SOCKOPTS
# define _SO_SETERRNO(s,e) \
# define _SO_CONN_SETERRNO(c,e) \
do \
{ \
if (s != NULL && (s)->s_conn != NULL) \
if ((c) != NULL) \
{ \
FAR struct socket_conn_s *_conn = (s)->s_conn; \
FAR struct socket_conn_s *_conn = \
(FAR struct socket_conn_s *)(c); \
_conn->s_error = (int16_t)e; \
} \
set_errno(e); \
} \
while (0)
# define _SO_SETERRNO(s,e) \
do \
{ \
if (s != NULL) \
{ \
_SO_CONN_SETERRNO((s)->s_conn, e); \
} \
else \
{ \
set_errno(e); \
} \
} \
while (0)
#else
# define _SO_CONN_SETERRNO(c,e) set_errno(e)
# define _SO_SETERRNO(s,e) set_errno(e)
#endif /* CONFIG_NET_SOCKOPTS */
+1 -4
View File
@@ -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, OK);
/* Indicate that the socket is now connected */
+1 -4
View File
@@ -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, reason);
/* Mark that the connection has been lost */