From c9e52cb28393ee355cd52b574fbbcf361e1242e6 Mon Sep 17 00:00:00 2001 From: Zhe Weng Date: Sun, 29 Jan 2023 16:34:30 +0800 Subject: [PATCH] net: Implement shutdown() for local stream socket Signed-off-by: Zhe Weng --- net/local/local_recvmsg.c | 7 ++----- net/local/local_sockif.c | 39 ++++++++++++++++++++++++++++++++++++--- 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/net/local/local_recvmsg.c b/net/local/local_recvmsg.c index 265ed6c2fb..c775b37229 100644 --- a/net/local/local_recvmsg.c +++ b/net/local/local_recvmsg.c @@ -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); diff --git a/net/local/local_sockif.c b/net/local/local_sockif.c index 5131f8ba54..754ef7757f 100644 --- a/net/local/local_sockif.c +++ b/net/local/local_sockif.c @@ -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; + } } /****************************************************************************