You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by pk...@apache.org on 2023/03/06 18:58:40 UTC
[nuttx] 04/07: net: Make si_listen callback optional
This is an automated email from the ASF dual-hosted git repository.
pkarashchenko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit a97e2523a47770486c61746e4920c613e4811df2
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Mon Mar 6 13:08:24 2023 +0800
net: Make si_listen callback optional
Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
net/bluetooth/bluetooth_sockif.c | 33 +-------------------------------
net/can/can_sockif.c | 34 +--------------------------------
net/icmp/icmp_sockif.c | 33 +-------------------------------
net/icmpv6/icmpv6_sockif.c | 33 +-------------------------------
net/ieee802154/ieee802154_sockif.c | 33 +-------------------------------
net/local/local_sockif.c | 39 ++++----------------------------------
net/netlink/netlink_sockif.c | 34 +--------------------------------
net/pkt/pkt_sockif.c | 33 +-------------------------------
net/socket/listen.c | 7 ++++++-
9 files changed, 17 insertions(+), 262 deletions(-)
diff --git a/net/bluetooth/bluetooth_sockif.c b/net/bluetooth/bluetooth_sockif.c
index 54689f1123..b111374c62 100644
--- a/net/bluetooth/bluetooth_sockif.c
+++ b/net/bluetooth/bluetooth_sockif.c
@@ -57,7 +57,6 @@ static int bluetooth_getsockname(FAR struct socket *psock,
FAR struct sockaddr *addr, FAR socklen_t *addrlen);
static int bluetooth_getpeername(FAR struct socket *psock,
FAR struct sockaddr *addr, FAR socklen_t *addrlen);
-static int bluetooth_listen(FAR struct socket *psock, int backlog);
static int bluetooth_connect(FAR struct socket *psock,
FAR const struct sockaddr *addr, socklen_t addrlen);
static int bluetooth_accept(FAR struct socket *psock,
@@ -87,7 +86,7 @@ const struct sock_intf_s g_bluetooth_sockif =
bluetooth_bind, /* si_bind */
bluetooth_getsockname, /* si_getsockname */
bluetooth_getpeername, /* si_getpeername */
- bluetooth_listen, /* si_listen */
+ NULL, /* si_listen */
bluetooth_connect, /* si_connect */
bluetooth_accept, /* si_accept */
bluetooth_poll_local, /* si_poll */
@@ -672,36 +671,6 @@ static int bluetooth_getpeername(FAR struct socket *psock,
return OK;
}
-/****************************************************************************
- * Name: bluetooth_listen
- *
- * Description:
- * To accept connections, a socket is first created with psock_socket(), a
- * willingness to accept incoming connections and a queue limit for
- * incoming connections are specified with psock_listen(), and then the
- * connections are accepted with psock_accept(). For the case of
- * PF_BLUETOOTH sockets, psock_listen() calls this function. The listen()
- * call does not apply only to PF_BLUETOOTH sockets.
- *
- * Input Parameters:
- * psock Reference to an internal, boound socket structure.
- * backlog The maximum length the queue of pending connections may grow.
- * If a connection request arrives with the queue full, the client
- * may receive an error with an indication of ECONNREFUSED or,
- * if the underlying protocol supports retransmission, the request
- * may be ignored so that retries succeed.
- *
- * Returned Value:
- * On success, zero is returned. On error, a negated errno value is
- * returned. See listen() for the set of appropriate error values.
- *
- ****************************************************************************/
-
-int bluetooth_listen(FAR struct socket *psock, int backlog)
-{
- return -EOPNOTSUPP;
-}
-
/****************************************************************************
* Name: bluetooth_poll
*
diff --git a/net/can/can_sockif.c b/net/can/can_sockif.c
index bfb0f24ec4..46b2f9d831 100644
--- a/net/can/can_sockif.c
+++ b/net/can/can_sockif.c
@@ -53,7 +53,6 @@ static sockcaps_t can_sockcaps(FAR struct socket *psock);
static void can_addref(FAR struct socket *psock);
static int can_bind(FAR struct socket *psock,
FAR const struct sockaddr *addr, socklen_t addrlen);
-static int can_listen(FAR struct socket *psock, int backlog);
static int can_connect(FAR struct socket *psock,
FAR const struct sockaddr *addr, socklen_t addrlen);
static int can_accept(FAR struct socket *psock, FAR struct sockaddr *addr,
@@ -74,7 +73,7 @@ const struct sock_intf_s g_can_sockif =
can_bind, /* si_bind */
NULL, /* si_getsockname */
NULL, /* si_getpeername */
- can_listen, /* si_listen */
+ NULL, /* si_listen */
can_connect, /* si_connect */
can_accept, /* si_accept */
can_poll_local, /* si_poll */
@@ -338,37 +337,6 @@ static int can_bind(FAR struct socket *psock,
return OK;
}
-/****************************************************************************
- * Name: can_listen
- *
- * Description:
- * To accept connections, a socket is first created with psock_socket(), a
- * willingness to accept incoming connections and a queue limit for
- * incoming connections are specified with psock_listen(), and then the
- * connections are accepted with psock_accept(). For the case of AFINET
- * and AFINET6 sockets, psock_listen() calls this function. The
- * psock_listen() call applies only to sockets of type SOCK_STREAM or
- * SOCK_SEQPACKET.
- *
- * Input Parameters:
- * psock Reference to an internal, bound socket structure.
- * backlog The maximum length the queue of pending connections may grow.
- * If a connection request arrives with the queue full, the client
- * may receive an error with an indication of ECONNREFUSED or,
- * if the underlying protocol supports retransmission, the request
- * may be ignored so that retries succeed.
- *
- * Returned Value:
- * On success, zero is returned. On error, a negated errno value is
- * returned. See listen() for the set of appropriate error values.
- *
- ****************************************************************************/
-
-static int can_listen(FAR struct socket *psock, int backlog)
-{
- return -EOPNOTSUPP;
-}
-
/****************************************************************************
* Name: can_connect
*
diff --git a/net/icmp/icmp_sockif.c b/net/icmp/icmp_sockif.c
index 9733ebc75a..cbf29361b4 100644
--- a/net/icmp/icmp_sockif.c
+++ b/net/icmp/icmp_sockif.c
@@ -47,7 +47,6 @@
static int icmp_setup(FAR struct socket *psock);
static sockcaps_t icmp_sockcaps(FAR struct socket *psock);
static void icmp_addref(FAR struct socket *psock);
-static int icmp_listen(FAR struct socket *psock, int backlog);
static int icmp_connect(FAR struct socket *psock,
FAR const struct sockaddr *addr, socklen_t addrlen);
static int icmp_accept(FAR struct socket *psock,
@@ -69,7 +68,7 @@ const struct sock_intf_s g_icmp_sockif =
NULL, /* si_bind */
NULL, /* si_getsockname */
NULL, /* si_getpeername */
- icmp_listen, /* si_listen */
+ NULL, /* si_listen */
icmp_connect, /* si_connect */
icmp_accept, /* si_accept */
icmp_netpoll, /* si_poll */
@@ -273,36 +272,6 @@ static int icmp_accept(FAR struct socket *psock, FAR struct sockaddr *addr,
return -EAFNOSUPPORT;
}
-/****************************************************************************
- * Name: icmp_listen
- *
- * Description:
- * To accept connections, a socket is first created with psock_socket(), a
- * willingness to accept incoming connections and a queue limit for
- * incoming connections are specified with psock_listen(), and then the
- * connections are accepted with psock_accept(). For the case of raw
- * packet sockets, psock_listen() calls this function. The psock_listen()
- * call applies only to sockets of type SOCK_STREAM or SOCK_SEQPACKET.
- *
- * Input Parameters:
- * psock Reference to an internal, boound socket structure.
- * backlog The maximum length the queue of pending connections may grow.
- * If a connection request arrives with the queue full, the client
- * may receive an error with an indication of ECONNREFUSED or,
- * if the underlying protocol supports retransmission, the request
- * may be ignored so that retries succeed.
- *
- * Returned Value:
- * On success, zero is returned. On error, a negated errno value is
- * returned. See listen() for the set of appropriate error values.
- *
- ****************************************************************************/
-
-int icmp_listen(FAR struct socket *psock, int backlog)
-{
- return -EOPNOTSUPP;
-}
-
/****************************************************************************
* Name: icmp_netpoll
*
diff --git a/net/icmpv6/icmpv6_sockif.c b/net/icmpv6/icmpv6_sockif.c
index 89113ec59d..c12f3adfd8 100644
--- a/net/icmpv6/icmpv6_sockif.c
+++ b/net/icmpv6/icmpv6_sockif.c
@@ -47,7 +47,6 @@
static int icmpv6_setup(FAR struct socket *psock);
static sockcaps_t icmpv6_sockcaps(FAR struct socket *psock);
static void icmpv6_addref(FAR struct socket *psock);
-static int icmpv6_listen(FAR struct socket *psock, int backlog);
static int icmpv6_connect(FAR struct socket *psock,
FAR const struct sockaddr *addr, socklen_t addrlen);
static int icmpv6_accept(FAR struct socket *psock,
@@ -69,7 +68,7 @@ const struct sock_intf_s g_icmpv6_sockif =
NULL, /* si_bind */
NULL, /* si_getsockname */
NULL, /* si_getpeername */
- icmpv6_listen, /* si_listen */
+ NULL, /* si_listen */
icmpv6_connect, /* si_connect */
icmpv6_accept, /* si_accept */
icmpv6_netpoll, /* si_poll */
@@ -273,36 +272,6 @@ static int icmpv6_accept(FAR struct socket *psock, FAR struct sockaddr *addr,
return -EAFNOSUPPORT;
}
-/****************************************************************************
- * Name: icmpv6_listen
- *
- * Description:
- * To accept connections, a socket is first created with psock_socket(), a
- * willingness to accept incoming connections and a queue limit for
- * incoming connections are specified with psock_listen(), and then the
- * connections are accepted with psock_accept(). For the case of raw
- * packet sockets, psock_listen() calls this function. The psock_listen()
- * call applies only to sockets of type SOCK_STREAM or SOCK_SEQPACKET.
- *
- * Input Parameters:
- * psock Reference to an internal, boound socket structure.
- * backlog The maximum length the queue of pending connections may grow.
- * If a connection request arrives with the queue full, the client
- * may receive an error with an indication of ECONNREFUSED or,
- * if the underlying protocol supports retransmission, the request
- * may be ignored so that retries succeed.
- *
- * Returned Value:
- * On success, zero is returned. On error, a negated errno value is
- * returned. See listen() for the set of appropriate error values.
- *
- ****************************************************************************/
-
-int icmpv6_listen(FAR struct socket *psock, int backlog)
-{
- return -EOPNOTSUPP;
-}
-
/****************************************************************************
* Name: icmpv6_netpoll
*
diff --git a/net/ieee802154/ieee802154_sockif.c b/net/ieee802154/ieee802154_sockif.c
index 1a462d6329..dfeecc5d1d 100644
--- a/net/ieee802154/ieee802154_sockif.c
+++ b/net/ieee802154/ieee802154_sockif.c
@@ -55,7 +55,6 @@ static int ieee802154_getsockname(FAR struct socket *psock,
FAR struct sockaddr *addr, FAR socklen_t *addrlen);
static int ieee802154_getpeername(FAR struct socket *psock,
FAR struct sockaddr *addr, FAR socklen_t *addrlen);
-static int ieee802154_listen(FAR struct socket *psock, int backlog);
static int ieee802154_connect(FAR struct socket *psock,
FAR const struct sockaddr *addr, socklen_t addrlen);
static int ieee802154_accept(FAR struct socket *psock,
@@ -77,7 +76,7 @@ const struct sock_intf_s g_ieee802154_sockif =
ieee802154_bind, /* si_bind */
ieee802154_getsockname, /* si_getsockname */
ieee802154_getpeername, /* si_getpeername */
- ieee802154_listen, /* si_listen */
+ NULL, /* si_listen */
ieee802154_connect, /* si_connect */
ieee802154_accept, /* si_accept */
ieee802154_poll_local, /* si_poll */
@@ -546,36 +545,6 @@ static int ieee802154_getpeername(FAR struct socket *psock,
return OK;
}
-/****************************************************************************
- * Name: ieee802154_listen
- *
- * Description:
- * To accept connections, a socket is first created with psock_socket(), a
- * willingness to accept incoming connections and a queue limit for
- * incoming connections are specified with psock_listen(), and then the
- * connections are accepted with psock_accept(). For the case of
- * PF_IEEE802154 sockets, psock_listen() calls this function. The listen()
- * call does not apply only to PF_IEEE802154 sockets.
- *
- * Input Parameters:
- * psock Reference to an internal, boound socket structure.
- * backlog The maximum length the queue of pending connections may grow.
- * If a connection request arrives with the queue full, the client
- * may receive an error with an indication of ECONNREFUSED or,
- * if the underlying protocol supports retransmission, the request
- * may be ignored so that retries succeed.
- *
- * Returned Value:
- * On success, zero is returned. On error, a negated errno value is
- * returned. See listen() for the set of appropriate error values.
- *
- ****************************************************************************/
-
-int ieee802154_listen(FAR struct socket *psock, int backlog)
-{
- return -EOPNOTSUPP;
-}
-
/****************************************************************************
* Name: ieee802154_poll
*
diff --git a/net/local/local_sockif.c b/net/local/local_sockif.c
index 234337d138..d895d28b7e 100644
--- a/net/local/local_sockif.c
+++ b/net/local/local_sockif.c
@@ -56,9 +56,6 @@ static int local_getsockname(FAR struct socket *psock,
FAR struct sockaddr *addr, FAR socklen_t *addrlen);
static int local_getpeername(FAR struct socket *psock,
FAR struct sockaddr *addr, FAR socklen_t *addrlen);
-#ifndef CONFIG_NET_LOCAL_STREAM
-static int local_listen(FAR struct socket *psock, int backlog);
-#endif
static int local_connect(FAR struct socket *psock,
FAR const struct sockaddr *addr, socklen_t addrlen);
#ifndef CONFIG_NET_LOCAL_STREAM
@@ -92,7 +89,11 @@ const struct sock_intf_s g_local_sockif =
local_bind, /* si_bind */
local_getsockname, /* si_getsockname */
local_getpeername, /* si_getpeername */
+#ifdef CONFIG_NET_LOCAL_STREAM
local_listen, /* si_listen */
+#else
+ NULL, /* si_listen */
+#endif
local_connect, /* si_connect */
local_accept, /* si_accept */
local_poll, /* si_poll */
@@ -548,38 +549,6 @@ static int local_setsockopt(FAR struct socket *psock, int level, int option,
#endif
-/****************************************************************************
- * Name: local_listen
- *
- * Description:
- * To accept connections, a socket is first created with psock_socket(), a
- * willingness to accept incoming connections and a queue limit for
- * incoming connections are specified with psock_listen(), and then the
- * connections are accepted with psock_accept(). For the case of local
- * unix sockets, psock_listen() calls this function. The psock_listen()
- * call applies only to sockets of type SOCK_STREAM or SOCK_SEQPACKET.
- *
- * Input Parameters:
- * psock Reference to an internal, boound socket structure.
- * backlog The maximum length the queue of pending connections may grow.
- * If a connection request arrives with the queue full, the client
- * may receive an error with an indication of ECONNREFUSED or,
- * if the underlying protocol supports retransmission, the request
- * may be ignored so that retries succeed.
- *
- * Returned Value:
- * On success, zero is returned. On error, a negated errno value is
- * returned. See listen() for the set of appropriate error values.
- *
- ****************************************************************************/
-
-#ifndef CONFIG_NET_LOCAL_STREAM
-int local_listen(FAR struct socket *psock, int backlog)
-{
- return -EOPNOTSUPP;
-}
-#endif
-
/****************************************************************************
* Name: local_connect
*
diff --git a/net/netlink/netlink_sockif.c b/net/netlink/netlink_sockif.c
index 99a652b606..55d2ab385c 100644
--- a/net/netlink/netlink_sockif.c
+++ b/net/netlink/netlink_sockif.c
@@ -56,7 +56,6 @@ static int netlink_getsockname(FAR struct socket *psock,
FAR struct sockaddr *addr, FAR socklen_t *addrlen);
static int netlink_getpeername(FAR struct socket *psock,
FAR struct sockaddr *addr, FAR socklen_t *addrlen);
-static int netlink_listen(FAR struct socket *psock, int backlog);
static int netlink_connect(FAR struct socket *psock,
FAR const struct sockaddr *addr, socklen_t addrlen);
static int netlink_accept(FAR struct socket *psock,
@@ -82,7 +81,7 @@ const struct sock_intf_s g_netlink_sockif =
netlink_bind, /* si_bind */
netlink_getsockname, /* si_getsockname */
netlink_getpeername, /* si_getpeername */
- netlink_listen, /* si_listen */
+ NULL, /* si_listen */
netlink_connect, /* si_connect */
netlink_accept, /* si_accept */
netlink_poll, /* si_poll */
@@ -365,37 +364,6 @@ static int netlink_getpeername(FAR struct socket *psock,
return OK;
}
-/****************************************************************************
- * Name: netlink_listen
- *
- * Description:
- * To accept connections, a socket is first created with psock_socket(), a
- * willingness to accept incoming connections and a queue limit for
- * incoming connections are specified with psock_listen(), and then the
- * connections are accepted with psock_accept(). For the case of AFINET
- * and AFINET6 sockets, psock_listen() calls this function. The
- * psock_listen() call applies only to sockets of type SOCK_STREAM or
- * SOCK_SEQPACKET.
- *
- * Input Parameters:
- * psock Reference to an internal, bound socket structure.
- * backlog The maximum length the queue of pending connections may grow.
- * If a connection request arrives with the queue full, the client
- * may receive an error with an indication of ECONNREFUSED or,
- * if the underlying protocol supports retransmission, the request
- * may be ignored so that retries succeed.
- *
- * Returned Value:
- * On success, zero is returned. On error, a negated errno value is
- * returned. See listen() for the set of appropriate error values.
- *
- ****************************************************************************/
-
-static int netlink_listen(FAR struct socket *psock, int backlog)
-{
- return -EOPNOTSUPP;
-}
-
/****************************************************************************
* Name: netlink_connect
*
diff --git a/net/pkt/pkt_sockif.c b/net/pkt/pkt_sockif.c
index 99beb66fc2..9bdeec9b59 100644
--- a/net/pkt/pkt_sockif.c
+++ b/net/pkt/pkt_sockif.c
@@ -52,7 +52,6 @@ static sockcaps_t pkt_sockcaps(FAR struct socket *psock);
static void pkt_addref(FAR struct socket *psock);
static int pkt_bind(FAR struct socket *psock,
FAR const struct sockaddr *addr, socklen_t addrlen);
-static int pkt_listen(FAR struct socket *psock, int backlog);
static int pkt_connect(FAR struct socket *psock,
FAR const struct sockaddr *addr, socklen_t addrlen);
static int pkt_accept(FAR struct socket *psock,
@@ -74,7 +73,7 @@ const struct sock_intf_s g_pkt_sockif =
pkt_bind, /* si_bind */
NULL, /* si_getsockname */
NULL, /* si_getpeername */
- pkt_listen, /* si_listen */
+ NULL, /* si_listen */
pkt_connect, /* si_connect */
pkt_accept, /* si_accept */
pkt_poll_local, /* si_poll */
@@ -368,36 +367,6 @@ static int pkt_bind(FAR struct socket *psock,
}
}
-/****************************************************************************
- * Name: pkt_listen
- *
- * Description:
- * To accept connections, a socket is first created with psock_socket(), a
- * willingness to accept incoming connections and a queue limit for
- * incoming connections are specified with psock_listen(), and then the
- * connections are accepted with psock_accept(). For the case of raw
- * packet sockets, psock_listen() calls this function. The psock_listen()
- * call applies only to sockets of type SOCK_STREAM or SOCK_SEQPACKET.
- *
- * Input Parameters:
- * psock Reference to an internal, boound socket structure.
- * backlog The maximum length the queue of pending connections may grow.
- * If a connection request arrives with the queue full, the client
- * may receive an error with an indication of ECONNREFUSED or,
- * if the underlying protocol supports retransmission, the request
- * may be ignored so that retries succeed.
- *
- * Returned Value:
- * On success, zero is returned. On error, a negated errno value is
- * returned. See listen() for the set of appropriate error values.
- *
- ****************************************************************************/
-
-int pkt_listen(FAR struct socket *psock, int backlog)
-{
- return -EOPNOTSUPP;
-}
-
/****************************************************************************
* Name: pkt_poll
*
diff --git a/net/socket/listen.c b/net/socket/listen.c
index 4e11b0743e..94957c70fb 100644
--- a/net/socket/listen.c
+++ b/net/socket/listen.c
@@ -82,7 +82,12 @@ int psock_listen(FAR struct socket *psock, int backlog)
/* Let the address family's listen() method handle the operation */
- DEBUGASSERT(psock->s_sockif != NULL && psock->s_sockif->si_listen != NULL);
+ DEBUGASSERT(psock->s_sockif != NULL);
+ if (psock->s_sockif->si_listen == NULL)
+ {
+ return -EOPNOTSUPP;
+ }
+
ret = psock->s_sockif->si_listen(psock, backlog);
if (ret >= 0)
{