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

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 */
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)
{
@ -239,10 +240,6 @@ psock_stream_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len,
return -ENOTCONN;
}
/* The incoming FIFO should be open */
DEBUGASSERT(conn->lc_infile.f_inode != NULL);
/* Read the packet */
ret = psock_fifo_read(psock, buf, &readlen, true);

View file

@ -983,10 +983,43 @@ errout:
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");
return -ENOTSUP;
switch (psock->s_type)
{
#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;
}
}
/****************************************************************************