diff --git a/net/local/local_recvmsg.c b/net/local/local_recvmsg.c index 4973dfb053..cdbb61ffbf 100644 --- a/net/local/local_recvmsg.c +++ b/net/local/local_recvmsg.c @@ -539,11 +539,19 @@ errout_with_halfduplex: ssize_t local_recvmsg(FAR struct socket *psock, FAR struct msghdr *msg, int flags) { + FAR struct local_conn_s *conn = psock->s_conn; FAR socklen_t *fromlen = &msg->msg_namelen; FAR struct sockaddr *from = msg->msg_name; FAR void *buf = msg->msg_iov->iov_base; size_t len = msg->msg_iov->iov_len; + /* Check shutdown state */ + + if (conn->lc_infile.f_inode == NULL) + { + return 0; + } + DEBUGASSERT(buf); /* Check for a stream socket */ diff --git a/net/local/local_sendmsg.c b/net/local/local_sendmsg.c index 0e8e67ff3f..b64bdf5b3b 100644 --- a/net/local/local_sendmsg.c +++ b/net/local/local_sendmsg.c @@ -431,12 +431,20 @@ errout_with_lock: ssize_t local_sendmsg(FAR struct socket *psock, FAR struct msghdr *msg, int flags) { + FAR struct local_conn_s *conn = psock->s_conn; FAR const struct sockaddr *to = msg->msg_name; FAR const struct iovec *buf = msg->msg_iov; socklen_t tolen = msg->msg_namelen; size_t len = msg->msg_iovlen; + + /* Check shutdown state */ + + if (conn->lc_outfile.f_inode == NULL) + { + return -EPIPE; + } + #ifdef CONFIG_NET_LOCAL_SCM - FAR struct local_conn_s *conn = psock->s_conn; int count = 0; if (msg->msg_control && @@ -448,17 +456,19 @@ ssize_t local_sendmsg(FAR struct socket *psock, FAR struct msghdr *msg, return count; } } -#endif /* CONFIG_NET_LOCAL_SCM */ len = to ? local_sendto(psock, buf, len, flags, to, tolen) : local_send(psock, buf, len, flags); -#ifdef CONFIG_NET_LOCAL_SCM + if (len < 0 && count > 0) { net_lock(); local_freectl(conn, count); net_unlock(); } +#else + len = to ? local_sendto(psock, buf, len, flags, to, tolen) : + local_send(psock, buf, len, flags); #endif return len;