Skip to content

Commit

Permalink
net: Make si_connect callback optional
Browse files Browse the repository at this point in the history
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
  • Loading branch information
xiaoxiang781216 authored and pkarashchenko committed Mar 6, 2023
1 parent a97e252 commit 5dd037c
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 154 deletions.
30 changes: 1 addition & 29 deletions net/can/can_sockif.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 */
Expand Down Expand Up @@ -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
*
Expand Down
42 changes: 1 addition & 41 deletions net/icmp/icmp_sockif.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 */
Expand Down Expand Up @@ -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
*
Expand Down
42 changes: 1 addition & 41 deletions net/icmpv6/icmpv6_sockif.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 */
Expand Down Expand Up @@ -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
*
Expand Down
42 changes: 1 addition & 41 deletions net/pkt/pkt_sockif.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 */
Expand Down Expand Up @@ -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
*
Expand Down
8 changes: 6 additions & 2 deletions net/socket/connect.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down

0 comments on commit 5dd037c

Please sign in to comment.