Skip to content

Commit 42966e3

Browse files
committed
local_socket: corrent send/recv return value after shutdown
Signed-off-by: ligd <liguiding1@xiaomi.com>
1 parent 5076b0c commit 42966e3

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

net/local/local_recvmsg.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,11 +539,19 @@ psock_dgram_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len,
539539
ssize_t local_recvmsg(FAR struct socket *psock, FAR struct msghdr *msg,
540540
int flags)
541541
{
542+
FAR struct local_conn_s *conn = psock->s_conn;
542543
FAR socklen_t *fromlen = &msg->msg_namelen;
543544
FAR struct sockaddr *from = msg->msg_name;
544545
FAR void *buf = msg->msg_iov->iov_base;
545546
size_t len = msg->msg_iov->iov_len;
546547

548+
/* Check shutdown state */
549+
550+
if (conn->lc_infile.f_inode == NULL)
551+
{
552+
return 0;
553+
}
554+
547555
DEBUGASSERT(buf);
548556

549557
/* Check for a stream socket */

net/local/local_sendmsg.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -431,12 +431,20 @@ static ssize_t local_sendto(FAR struct socket *psock,
431431
ssize_t local_sendmsg(FAR struct socket *psock, FAR struct msghdr *msg,
432432
int flags)
433433
{
434+
FAR struct local_conn_s *conn = psock->s_conn;
434435
FAR const struct sockaddr *to = msg->msg_name;
435436
FAR const struct iovec *buf = msg->msg_iov;
436437
socklen_t tolen = msg->msg_namelen;
437438
size_t len = msg->msg_iovlen;
439+
440+
/* Check shutdown state */
441+
442+
if (conn->lc_outfile.f_inode == NULL)
443+
{
444+
return -EPIPE;
445+
}
446+
438447
#ifdef CONFIG_NET_LOCAL_SCM
439-
FAR struct local_conn_s *conn = psock->s_conn;
440448
int count = 0;
441449

442450
if (msg->msg_control &&
@@ -448,17 +456,19 @@ ssize_t local_sendmsg(FAR struct socket *psock, FAR struct msghdr *msg,
448456
return count;
449457
}
450458
}
451-
#endif /* CONFIG_NET_LOCAL_SCM */
452459

453460
len = to ? local_sendto(psock, buf, len, flags, to, tolen) :
454461
local_send(psock, buf, len, flags);
455-
#ifdef CONFIG_NET_LOCAL_SCM
462+
456463
if (len < 0 && count > 0)
457464
{
458465
net_lock();
459466
local_freectl(conn, count);
460467
net_unlock();
461468
}
469+
#else
470+
len = to ? local_sendto(psock, buf, len, flags, to, tolen) :
471+
local_send(psock, buf, len, flags);
462472
#endif
463473

464474
return len;

0 commit comments

Comments
 (0)