net: Implement shutdown() for local stream socket

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
This commit is contained in:
Zhe Weng
2023-01-29 16:34:30 +08:00
committed by Xiang Xiao
parent d3dd349649
commit c9e52cb283
2 changed files with 38 additions and 8 deletions
+2 -5
View File
@@ -228,7 +228,8 @@ psock_stream_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len,
/* Verify that this is a connected peer socket */ /* Verify that this is a connected peer socket */
if (conn->lc_state != LOCAL_STATE_CONNECTED) if (conn->lc_state != LOCAL_STATE_CONNECTED ||
conn->lc_infile.f_inode == NULL)
{ {
if (conn->lc_state == LOCAL_STATE_CONNECTING) if (conn->lc_state == LOCAL_STATE_CONNECTING)
{ {
@@ -239,10 +240,6 @@ psock_stream_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len,
return -ENOTCONN; return -ENOTCONN;
} }
/* The incoming FIFO should be open */
DEBUGASSERT(conn->lc_infile.f_inode != NULL);
/* Read the packet */ /* Read the packet */
ret = psock_fifo_read(psock, buf, &readlen, true); ret = psock_fifo_read(psock, buf, &readlen, true);
+36 -3
View File
@@ -983,10 +983,43 @@ errout:
static int local_shutdown(FAR struct socket *psock, int how) static int local_shutdown(FAR struct socket *psock, int how)
{ {
/* TODO: implement this. */ DEBUGASSERT(psock != NULL && psock->s_conn != NULL &&
psock->s_domain == PF_LOCAL);
nerr("ERROR: local_shutdown is not implemented"); switch (psock->s_type)
return -ENOTSUP; {
#ifdef CONFIG_NET_LOCAL_STREAM
case SOCK_STREAM:
{
FAR struct local_conn_s *conn = psock->s_conn;
if (how & SHUT_RD)
{
if (conn->lc_infile.f_inode != NULL)
{
file_close(&conn->lc_infile);
conn->lc_infile.f_inode = NULL;
}
}
if (how & SHUT_WR)
{
if (conn->lc_outfile.f_inode != NULL)
{
file_close(&conn->lc_outfile);
conn->lc_outfile.f_inode = NULL;
}
}
}
return OK;
#endif
#ifdef CONFIG_NET_LOCAL_DGRAM
case SOCK_DGRAM:
return -EOPNOTSUPP;
#endif
default:
return -EBADF;
}
} }
/**************************************************************************** /****************************************************************************