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 5dd037c599c4470a364ab3363175abdccc7e0f23
Author: Xiang Xiao <xiaoxi...@xiaomi.com>
AuthorDate: Mon Mar 6 13:11:38 2023 +0800

    net: Make si_connect callback optional
    
    Signed-off-by: Xiang Xiao <xiaoxi...@xiaomi.com>
---
 net/can/can_sockif.c       | 30 +-----------------------------
 net/icmp/icmp_sockif.c     | 42 +-----------------------------------------
 net/icmpv6/icmpv6_sockif.c | 42 +-----------------------------------------
 net/pkt/pkt_sockif.c       | 42 +-----------------------------------------
 net/socket/connect.c       |  8 ++++++--
 5 files changed, 10 insertions(+), 154 deletions(-)

diff --git a/net/can/can_sockif.c b/net/can/can_sockif.c
index 46b2f9d831..878d3c8fc6 100644
--- a/net/can/can_sockif.c
+++ b/net/can/can_sockif.c
@@ -53,8 +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_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,
               FAR socklen_t *addrlen, FAR struct socket *newsock);
 static int  can_poll_local(FAR struct socket *psock, FAR struct pollfd *fds,
@@ -74,7 +72,7 @@ const struct sock_intf_s g_can_sockif =
   NULL,             /* si_getsockname */
   NULL,             /* si_getpeername */
   NULL,             /* si_listen */
-  can_connect,      /* si_connect */
+  NULL,             /* si_connect */
   can_accept,       /* si_accept */
   can_poll_local,   /* si_poll */
   can_sendmsg,      /* si_sendmsg */
@@ -337,32 +335,6 @@ static int can_bind(FAR struct socket *psock,
   return OK;
 }
 
-/****************************************************************************
- * Name: can_connect
- *
- * Description:
- *   Perform a can connection
- *
- * Input Parameters:
- *   psock   A reference to the socket structure of the socket
- *           to be connected
- *   addr    The address of the remote server to connect to
- *   addrlen Length of address buffer
- *
- * Returned Value:
- *   None
- *
- * Assumptions:
- *
- ****************************************************************************/
-
-static int can_connect(FAR struct socket *psock,
-                       FAR const struct sockaddr *addr,
-                       socklen_t addrlen)
-{
-  return -EOPNOTSUPP;
-}
-
 /****************************************************************************
  * Name: can_accept
  *
diff --git a/net/icmp/icmp_sockif.c b/net/icmp/icmp_sockif.c
index cbf29361b4..f9a96929d9 100644
--- a/net/icmp/icmp_sockif.c
+++ b/net/icmp/icmp_sockif.c
@@ -47,8 +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_connect(FAR struct socket *psock,
-                    FAR const struct sockaddr *addr, socklen_t addrlen);
 static int        icmp_accept(FAR struct socket *psock,
                     FAR struct sockaddr *addr, FAR socklen_t *addrlen,
                     FAR struct socket *newsock);
@@ -69,7 +67,7 @@ const struct sock_intf_s g_icmp_sockif =
   NULL,             /* si_getsockname */
   NULL,             /* si_getpeername */
   NULL,             /* si_listen */
-  icmp_connect,     /* si_connect */
+  NULL,             /* si_connect */
   icmp_accept,      /* si_accept */
   icmp_netpoll,     /* si_poll */
   icmp_sendmsg,     /* si_sendmsg */
@@ -184,44 +182,6 @@ static void icmp_addref(FAR struct socket *psock)
   conn->crefs++;
 }
 
-/****************************************************************************
- * Name: icmp_connect
- *
- * Description:
- *   icmp_connect() connects the local socket referred to by the structure
- *   'psock' to the address specified by 'addr'. The addrlen argument
- *   specifies the size of 'addr'.  The format of the address in 'addr' is
- *   determined by the address space of the socket 'psock'.
- *
- *   If the socket 'psock' is of type SOCK_DGRAM then 'addr' is the address
- *   to which datagrams are sent by default, and the only address from which
- *   datagrams are received. If the socket is of type SOCK_STREAM or
- *   SOCK_SEQPACKET, this call attempts to make a connection to the socket
- *   that is bound to the address specified by 'addr'.
- *
- *   Generally, connection-based protocol sockets may successfully
- *   icmp_connect() only once; connectionless protocol sockets may use
- *   icmp_connect() multiple times to change their association.
- *   Connectionless sockets may dissolve the association by connecting to
- *   an address with the sa_family member of sockaddr set to AF_UNSPEC.
- *
- * Input Parameters:
- *   psock     Pointer to a socket structure initialized by psock_socket()
- *   addr      Server address (form depends on type of socket)
- *   addrlen   Length of actual 'addr'
- *
- * Returned Value:
- *   0 on success; a negated errno value on failure.  See connect() for the
- *   list of appropriate errno values to be returned.
- *
- ****************************************************************************/
-
-static int icmp_connect(FAR struct socket *psock,
-                       FAR const struct sockaddr *addr, socklen_t addrlen)
-{
-  return -EAFNOSUPPORT;
-}
-
 /****************************************************************************
  * Name: icmp_accept
  *
diff --git a/net/icmpv6/icmpv6_sockif.c b/net/icmpv6/icmpv6_sockif.c
index c12f3adfd8..06aab6b7dd 100644
--- a/net/icmpv6/icmpv6_sockif.c
+++ b/net/icmpv6/icmpv6_sockif.c
@@ -47,8 +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_connect(FAR struct socket *psock,
-                    FAR const struct sockaddr *addr, socklen_t addrlen);
 static int        icmpv6_accept(FAR struct socket *psock,
                     FAR struct sockaddr *addr, FAR socklen_t *addrlen,
                     FAR struct socket *newsock);
@@ -69,7 +67,7 @@ const struct sock_intf_s g_icmpv6_sockif =
   NULL,               /* si_getsockname */
   NULL,               /* si_getpeername */
   NULL,               /* si_listen */
-  icmpv6_connect,     /* si_connect */
+  NULL,               /* si_connect */
   icmpv6_accept,      /* si_accept */
   icmpv6_netpoll,     /* si_poll */
   icmpv6_sendmsg,     /* si_sendmsg */
@@ -184,44 +182,6 @@ static void icmpv6_addref(FAR struct socket *psock)
   conn->crefs++;
 }
 
-/****************************************************************************
- * Name: icmpv6_connect
- *
- * Description:
- *   icmpv6_connect() connects the local socket referred to by the structure
- *   'psock' to the address specified by 'addr'. The addrlen argument
- *   specifies the size of 'addr'.  The format of the address in 'addr' is
- *   determined by the address space of the socket 'psock'.
- *
- *   If the socket 'psock' is of type SOCK_DGRAM then 'addr' is the address
- *   to which datagrams are sent by default, and the only address from which
- *   datagrams are received. If the socket is of type SOCK_STREAM or
- *   SOCK_SEQPACKET, this call attempts to make a connection to the socket
- *   that is bound to the address specified by 'addr'.
- *
- *   Generally, connection-based protocol sockets may successfully
- *   icmpv6_connect() only once; connectionless protocol sockets may use
- *   icmpv6_connect() multiple times to change their association.
- *   Connectionless sockets may dissolve the association by connecting to
- *   an address with the sa_family member of sockaddr set to AF_UNSPEC.
- *
- * Input Parameters:
- *   psock     Pointer to a socket structure initialized by psock_socket()
- *   addr      Server address (form depends on type of socket)
- *   addrlen   Length of actual 'addr'
- *
- * Returned Value:
- *   0 on success; a negated errno value on failure.  See connect() for the
- *   list of appropriate errno values to be returned.
- *
- ****************************************************************************/
-
-static int icmpv6_connect(FAR struct socket *psock,
-                       FAR const struct sockaddr *addr, socklen_t addrlen)
-{
-  return -EAFNOSUPPORT;
-}
-
 /****************************************************************************
  * Name: icmpv6_accept
  *
diff --git a/net/pkt/pkt_sockif.c b/net/pkt/pkt_sockif.c
index 9bdeec9b59..0dfde2d0b2 100644
--- a/net/pkt/pkt_sockif.c
+++ b/net/pkt/pkt_sockif.c
@@ -52,8 +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_connect(FAR struct socket *psock,
-                    FAR const struct sockaddr *addr, socklen_t addrlen);
 static int        pkt_accept(FAR struct socket *psock,
                     FAR struct sockaddr *addr, FAR socklen_t *addrlen,
                     FAR struct socket *newsock);
@@ -74,7 +72,7 @@ const struct sock_intf_s g_pkt_sockif =
   NULL,            /* si_getsockname */
   NULL,            /* si_getpeername */
   NULL,            /* si_listen */
-  pkt_connect,     /* si_connect */
+  NULL,            /* si_connect */
   pkt_accept,      /* si_accept */
   pkt_poll_local,  /* si_poll */
   pkt_sendmsg,     /* si_sendmsg */
@@ -205,44 +203,6 @@ static void pkt_addref(FAR struct socket *psock)
   conn->crefs++;
 }
 
-/****************************************************************************
- * Name: pkt_connect
- *
- * Description:
- *   pkt_connect() connects the local socket referred to by the structure
- *   'psock' to the address specified by 'addr'. The addrlen argument
- *   specifies the size of 'addr'.  The format of the address in 'addr' is
- *   determined by the address space of the socket 'psock'.
- *
- *   If the socket 'psock' is of type SOCK_DGRAM then 'addr' is the address
- *   to which datagrams are sent by default, and the only address from which
- *   datagrams are received. If the socket is of type SOCK_STREAM or
- *   SOCK_SEQPACKET, this call attempts to make a connection to the socket
- *   that is bound to the address specified by 'addr'.
- *
- *   Generally, connection-based protocol sockets may successfully
- *   pkt_connect() only once; connectionless protocol sockets may use
- *   pkt_connect() multiple times to change their association.
- *   Connectionless sockets may dissolve the association by connecting to
- *   an address with the sa_family member of sockaddr set to AF_UNSPEC.
- *
- * Input Parameters:
- *   psock     Pointer to a socket structure initialized by psock_socket()
- *   addr      Server address (form depends on type of socket)
- *   addrlen   Length of actual 'addr'
- *
- * Returned Value:
- *   0 on success; a negated errno value on failure.  See connect() for the
- *   list of appropriate errno values to be returned.
- *
- ****************************************************************************/
-
-static int pkt_connect(FAR struct socket *psock,
-                       FAR const struct sockaddr *addr, socklen_t addrlen)
-{
-  return -EAFNOSUPPORT;
-}
-
 /****************************************************************************
  * Name: pkt_accept
  *
diff --git a/net/socket/connect.c b/net/socket/connect.c
index 99266a173d..d236d48f41 100644
--- a/net/socket/connect.c
+++ b/net/socket/connect.c
@@ -134,8 +134,12 @@ int psock_connect(FAR struct socket *psock, FAR const 
struct sockaddr *addr,
 
   /* Let the address family's connect() method handle the operation */
 
-  DEBUGASSERT(psock->s_sockif != NULL &&
-              psock->s_sockif->si_connect != NULL);
+  DEBUGASSERT(psock->s_sockif != NULL);
+  if (psock->s_sockif->si_connect == NULL)
+    {
+      return -EOPNOTSUPP;
+    }
+
   ret = psock->s_sockif->si_connect(psock, addr, addrlen);
   if (ret >= 0)
     {

Reply via email to