Skip to content

Commit

Permalink
local_socket: corrent send/recv return value after shutdown
Browse files Browse the repository at this point in the history
Signed-off-by: ligd <[email protected]>
  • Loading branch information
GUIDINGLI authored and xiaoxiang781216 committed Oct 12, 2024
1 parent a5c0dbe commit 01676cb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
8 changes: 8 additions & 0 deletions net/local/local_recvmsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -539,11 +539,19 @@ psock_dgram_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len,
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 */
Expand Down
16 changes: 13 additions & 3 deletions net/local/local_sendmsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -431,12 +431,20 @@ static ssize_t local_sendto(FAR struct socket *psock,
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 &&
Expand All @@ -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;
Expand Down

0 comments on commit 01676cb

Please sign in to comment.