Networking: Move two more TCP specific files from inet/ to tcp/. There is other TCP-specific logic in inet/ that should be moved sometime, but those are more entangled.

This commit is contained in:
Gregory Nutt 2017-08-29 09:25:22 -06:00
parent 92f44c5607
commit ed58536c3a
7 changed files with 219 additions and 220 deletions

View File

@ -36,10 +36,10 @@
# PF_INET/PF_INET6 socket address families
ifeq ($(CONFIG_NET_IPv4),y)
SOCK_CSRCS += inet_sockif.c inet_recvfrom.c inet_connect.c inet_close.c
SOCK_CSRCS += inet_sockif.c inet_recvfrom.c inet_close.c
SOCK_CSRCS += inet_globals.c
else ifeq ($(CONFIG_NET_IPv6),y)
SOCK_CSRCS += inet_sockif.c inet_recvfrom.c inet_connect.c inet_close.c
SOCK_CSRCS += inet_sockif.c inet_recvfrom.c inet_close.c
SOCK_CSRCS += inet_globals.c
endif
@ -51,14 +51,6 @@ ifeq ($(CONFIG_NET_IPv6),y)
SOCK_CSRCS += ipv6_getsockname.c
endif
ifeq ($(CONFIG_NET_SENDFILE),y)
ifeq ($(CONFIG_NET_TCP),y)
ifneq ($(CONFIG_NET_TCP_NO_STACK),y)
SOCK_CSRCS += inet_sendfile.c
endif
endif
endif
# Include inet build support
DEPPATH += --dep-path inet

View File

@ -157,67 +157,6 @@ int ipv6_getsockname(FAR struct socket *psock, FAR struct sockaddr *addr,
FAR socklen_t *addrlen);
#endif
/****************************************************************************
* Name: inet_connect
*
* Description:
* inet_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
* inet_connect() only once; connectionless protocol sockets may use
* inet_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.
*
* 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 failue. See connect() for the
* list of appropriate errno values to be returned.
*
****************************************************************************/
int inet_connect(FAR struct socket *psock, FAR const struct sockaddr *addr,
socklen_t addrlen);
/****************************************************************************
* Name: inet_sendfile
*
* Description:
* The inet_sendfile() call may be used only when the INET socket is in a
* connected state (so that the intended recipient is known).
*
* Parameters:
* psock An instance of the internal socket structure.
* buf Data to send
* len Length of data to send
* flags Send flags
*
* Returned Value:
* On success, returns the number of characters sent. On error,
* a negated errno value is returned. See sendfile() for a list
* appropriate error return values.
*
****************************************************************************/
#if defined(CONFIG_NET_SENDFILE) && defined(CONFIG_NET_TCP) && \
!defined(CONFIG_NET_TCP_NO_STACK)
ssize_t inet_sendfile(FAR struct socket *psock, FAR struct file *infile,
FAR off_t *offset, size_t count);
#endif
/****************************************************************************
* Name: inet_recvfrom
*

View File

@ -68,6 +68,8 @@ static int inet_bind(FAR struct socket *psock,
static int inet_getsockname(FAR struct socket *psock,
FAR struct sockaddr *addr, FAR socklen_t *addrlen);
static int inet_listen(FAR struct socket *psock, int backlog);
static int inet_connect(FAR struct socket *psock,
FAR const struct sockaddr *addr, socklen_t addrlen);
static int inet_accept(FAR struct socket *psock,
FAR struct sockaddr *addr, FAR socklen_t *addrlen,
FAR struct socket *newsock);
@ -80,6 +82,10 @@ static ssize_t inet_send(FAR struct socket *psock, FAR const void *buf,
static ssize_t inet_sendto(FAR struct socket *psock, FAR const void *buf,
size_t len, int flags, FAR const struct sockaddr *to,
socklen_t tolen);
#ifdef CONFIG_NET_SENDFILE
static ssize_t inet_sendfile(FAR struct socket *psock, FAR struct file *infile,
FAR off_t *offset, size_t count);
#endif
/****************************************************************************
* Public Data
@ -101,11 +107,7 @@ const struct sock_intf_s g_inet_sockif =
inet_send, /* si_send */
inet_sendto, /* si_sendto */
#ifdef CONFIG_NET_SENDFILE
#if defined(CONFIG_NET_TCP) && defined(NET_TCP_HAVE_STACK)
inet_sendfile, /* si_sendfile */
#else
NULL, /* si_sendfile */
#endif
#endif
inet_recvfrom, /* si_recvfrom */
inet_close /* si_close */
@ -591,6 +593,116 @@ int inet_listen(FAR struct socket *psock, int backlog)
#endif /* CONFIG_NET_TCP */
}
/****************************************************************************
* Name: inet_connect
*
* Description:
* inet_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
* inet_connect() only once; connectionless protocol sockets may use
* inet_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.
*
* 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 failue. See connect() for the
* list of appropriate errno values to be returned.
*
****************************************************************************/
static int inet_connect(FAR struct socket *psock,
FAR const struct sockaddr *addr, socklen_t addrlen)
{
FAR const struct sockaddr_in *inaddr = (FAR const struct sockaddr_in *)addr;
/* Verify that a valid address has been provided */
switch (inaddr->sin_family)
{
#ifdef CONFIG_NET_IPv4
case AF_INET:
{
if (addrlen < sizeof(struct sockaddr_in))
{
return -EBADF;
}
}
break;
#endif
#ifdef CONFIG_NET_IPv6
case AF_INET6:
{
if (addrlen < sizeof(struct sockaddr_in6))
{
return -EBADF;
}
}
break;
#endif
default:
DEBUGPANIC();
return -EAFNOSUPPORT;
}
/* Perform the connection depending on the protocol type */
switch (psock->s_type)
{
#if defined(CONFIG_NET_TCP) && defined(NET_TCP_HAVE_STACK)
case SOCK_STREAM:
{
/* Verify that the socket is not already connected */
if (_SS_ISCONNECTED(psock->s_flags))
{
return -EISCONN;
}
/* It's not ... Connect the TCP/IP socket */
return psock_tcp_connect(psock, addr);
}
#endif /* CONFIG_NET_TCP */
#if defined(CONFIG_NET_UDP) && defined(NET_UDP_HAVE_STACK)
case SOCK_DGRAM:
{
int ret = udp_connect(psock->s_conn, addr);
if (ret < 0 || addr == NULL)
{
psock->s_flags &= ~_SF_CONNECTED;
}
else
{
psock->s_flags |= _SF_CONNECTED;
}
return ret;
}
#endif /* CONFIG_NET_UDP */
default:
return -EBADF;
}
}
/****************************************************************************
* Name: inet_accept
*
@ -1057,6 +1169,39 @@ static ssize_t inet_sendto(FAR struct socket *psock, FAR const void *buf,
return nsent;
}
/****************************************************************************
* Name: inet_sendfile
*
* Description:
* The inet_sendfile() call may be used only when the INET socket is in a
* connected state (so that the intended recipient is known).
*
* Parameters:
* psock An instance of the internal socket structure.
* buf Data to send
* len Length of data to send
* flags Send flags
*
* Returned Value:
* On success, returns the number of characters sent. On error,
* a negated errno value is returned. See sendfile() for a list
* appropriate error return values.
*
****************************************************************************/
#ifdef CONFIG_NET_SENDFILE
static ssize_t inet_sendfile(FAR struct socket *psock,
FAR struct file *infile, FAR off_t *offset,
size_t count)
{
#if defined(CONFIG_NET_TCP) && !defined(CONFIG_NET_TCP_NO_STACK)
return tcp_sendfile(psock, infile, offset, size_t count);
#else
return -ENOSYS;
#endif
}
#endif
/****************************************************************************
* Public Functions
****************************************************************************/

View File

@ -40,7 +40,7 @@ ifneq ($(CONFIG_NET_TCP_NO_STACK),y)
# Socket layer
SOCK_CSRCS += tcp_accept.c
SOCK_CSRCS += tcp_connect.c tcp_accept.c
ifeq ($(CONFIG_NET_TCP_WRITE_BUFFERS),y)
SOCK_CSRCS += tcp_send_buffered.c
@ -48,6 +48,10 @@ else
SOCK_CSRCS += tcp_send_unbuffered.c
endif
ifeq ($(CONFIG_NET_SENDFILE),y)
SOCK_CSRCS += tcp_sendfile.c
endif
ifneq ($(CONFIG_DISABLE_POLL),y)
ifeq ($(CONFIG_NET_TCP_READAHEAD),y)
NET_CSRCS += tcp_netpoll.c

View File

@ -528,6 +528,27 @@ int tcp_bind(FAR struct tcp_conn_s *conn, FAR const struct sockaddr *addr);
int tcp_connect(FAR struct tcp_conn_s *conn, FAR const struct sockaddr *addr);
/****************************************************************************
* Name: psock_tcp_connect
*
* Description:
* Perform a TCP connection
*
* Parameters:
* psock - A reference to the socket structure of the socket to be connected
* addr - The address of the remote server to connect to
*
* Returned Value:
* None
*
* Assumptions:
* Running at the interrupt level
*
****************************************************************************/
int psock_tcp_connect(FAR struct socket *psock,
FAR const struct sockaddr *addr);
/****************************************************************************
* Name: tcp_start_monitor
*
@ -834,6 +855,31 @@ int tcp_accept_connection(FAR struct net_driver_s *dev,
void tcp_send(FAR struct net_driver_s *dev, FAR struct tcp_conn_s *conn,
uint16_t flags, uint16_t len);
/****************************************************************************
* Name: tcp_sendfile
*
* Description:
* The tcp_sendfile() call may be used only when the INET socket is in a
* connected state (so that the intended recipient is known).
*
* Parameters:
* psock An instance of the internal socket structure.
* buf Data to send
* len Length of data to send
* flags Send flags
*
* Returned Value:
* On success, returns the number of characters sent. On error,
* a negated errno value is returned. See sendfile() for a list
* appropriate error return values.
*
****************************************************************************/
#ifdef CONFIG_NET_SENDFILE
ssize_t tcp_sendfile(FAR struct socket *psock, FAR struct file *infile,
FAR off_t *offset, size_t count);
#endif
/****************************************************************************
* Name: tcp_reset
*

View File

@ -1,5 +1,5 @@
/****************************************************************************
* net/inet/inet_connect.c
* net/tcp/tcp_connect.c
*
* Copyright (C) 2007-2012, 2015-2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
@ -56,19 +56,15 @@
#include <nuttx/net/tcp.h>
#include "devif/devif.h"
#include "tcp/tcp.h"
#include "udp/udp.h"
#include "socket/socket.h"
#include "usrsock/usrsock.h"
#include "inet/inet.h"
#include "tcp/tcp.h"
#ifdef CONFIG_NET
#ifdef NET_TCP_HAVE_STACK
/****************************************************************************
* Private Types
****************************************************************************/
#ifdef NET_TCP_HAVE_STACK
struct tcp_connect_s
{
FAR struct tcp_conn_s *tc_conn; /* Reference to TCP connection structure */
@ -77,13 +73,11 @@ struct tcp_connect_s
sem_t tc_sem; /* Semaphore signals recv completion */
int tc_result; /* OK on success, otherwise a negated errno. */
};
#endif
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
#ifdef NET_TCP_HAVE_STACK
static inline int psock_setup_callbacks(FAR struct socket *psock,
FAR struct tcp_connect_s *pstate);
static void psock_teardown_callbacks(FAR struct tcp_connect_s *pstate,
@ -91,18 +85,15 @@ static void psock_teardown_callbacks(FAR struct tcp_connect_s *pstate,
static uint16_t psock_connect_interrupt(FAR struct net_driver_s *dev,
FAR void *pvconn, FAR void *pvpriv,
uint16_t flags);
static inline int psock_tcp_connect(FAR struct socket *psock,
FAR const struct sockaddr *addr);
#endif /* NET_TCP_HAVE_STACK */
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
/****************************************************************************
* Name: psock_setup_callbacks
****************************************************************************/
#ifdef NET_TCP_HAVE_STACK
static inline int psock_setup_callbacks(FAR struct socket *psock,
FAR struct tcp_connect_s *pstate)
{
@ -138,13 +129,11 @@ static inline int psock_setup_callbacks(FAR struct socket *psock,
return ret;
}
#endif /* NET_TCP_HAVE_STACK */
/****************************************************************************
* Name: psock_teardown_callbacks
****************************************************************************/
#ifdef NET_TCP_HAVE_STACK
static void psock_teardown_callbacks(FAR struct tcp_connect_s *pstate,
int status)
{
@ -166,7 +155,6 @@ static void psock_teardown_callbacks(FAR struct tcp_connect_s *pstate,
tcp_stop_monitor(conn);
}
}
#endif /* NET_TCP_HAVE_STACK */
/****************************************************************************
* Name: psock_connect_interrupt
@ -188,7 +176,6 @@ static void psock_teardown_callbacks(FAR struct tcp_connect_s *pstate,
*
****************************************************************************/
#ifdef NET_TCP_HAVE_STACK
static uint16_t psock_connect_interrupt(FAR struct net_driver_s *dev,
FAR void *pvconn, FAR void *pvpriv,
uint16_t flags)
@ -318,7 +305,10 @@ static uint16_t psock_connect_interrupt(FAR struct net_driver_s *dev,
return flags;
}
#endif /* NET_TCP_HAVE_STACK */
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: psock_tcp_connect
@ -338,9 +328,8 @@ static uint16_t psock_connect_interrupt(FAR struct net_driver_s *dev,
*
****************************************************************************/
#ifdef NET_TCP_HAVE_STACK
static inline int psock_tcp_connect(FAR struct socket *psock,
FAR const struct sockaddr *addr)
int psock_tcp_connect(FAR struct socket *psock,
FAR const struct sockaddr *addr)
{
struct tcp_connect_s state;
int ret = OK;
@ -430,120 +419,5 @@ static inline int psock_tcp_connect(FAR struct socket *psock,
net_unlock();
return ret;
}
#endif /* NET_TCP_HAVE_STACK */
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: inet_connect
*
* Description:
* inet_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
* inet_connect() only once; connectionless protocol sockets may use
* inet_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.
*
* 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 failue. See connect() for the
* list of appropriate errno values to be returned.
*
****************************************************************************/
int inet_connect(FAR struct socket *psock, FAR const struct sockaddr *addr,
socklen_t addrlen)
{
FAR const struct sockaddr_in *inaddr = (FAR const struct sockaddr_in *)addr;
/* Verify that a valid address has been provided */
switch (inaddr->sin_family)
{
#ifdef CONFIG_NET_IPv4
case AF_INET:
{
if (addrlen < sizeof(struct sockaddr_in))
{
return -EBADF;
}
}
break;
#endif
#ifdef CONFIG_NET_IPv6
case AF_INET6:
{
if (addrlen < sizeof(struct sockaddr_in6))
{
return -EBADF;
}
}
break;
#endif
default:
DEBUGPANIC();
return -EAFNOSUPPORT;
}
/* Perform the connection depending on the protocol type */
switch (psock->s_type)
{
#if defined(CONFIG_NET_TCP) && defined(NET_TCP_HAVE_STACK)
case SOCK_STREAM:
{
/* Verify that the socket is not already connected */
if (_SS_ISCONNECTED(psock->s_flags))
{
return -EISCONN;
}
/* It's not ... Connect the TCP/IP socket */
return psock_tcp_connect(psock, addr);
}
#endif /* CONFIG_NET_TCP */
#if defined(CONFIG_NET_UDP) && defined(NET_UDP_HAVE_STACK)
case SOCK_DGRAM:
{
int ret = udp_connect(psock->s_conn, addr);
if (ret < 0 || addr == NULL)
{
psock->s_flags &= ~_SF_CONNECTED;
}
else
{
psock->s_flags |= _SF_CONNECTED;
}
return ret;
}
#endif /* CONFIG_NET_UDP */
default:
return -EBADF;
}
}
#endif /* CONFIG_NET */

View File

@ -1,5 +1,5 @@
/****************************************************************************
* net/inet/inet_sendfile.c
* net/tcp/tcp_sendfile.c
*
* Copyright (C) 2013 UVC Ingenieure. All rights reserved.
* Copyright (C) 2007-2017 Gregory Nutt. All rights reserved.
@ -68,9 +68,8 @@
#include "arp/arp.h"
#include "icmpv6/icmpv6.h"
#include "neighbor/neighbor.h"
#include "tcp/tcp.h"
#include "inet/inet.h"
#include "socket/socket.h"
#include "tcp/tcp.h"
#if defined(CONFIG_NET_SENDFILE) && defined(CONFIG_NET_TCP) && \
defined(NET_TCP_HAVE_STACK)
@ -528,10 +527,10 @@ static inline void sendfile_txnotify(FAR struct socket *psock,
****************************************************************************/
/****************************************************************************
* Name: inet_sendfile
* Name: tcp_sendfile
*
* Description:
* The inet_sendfile() call may be used only when the INET socket is in a
* The tcp_sendfile() call may be used only when the INET socket is in a
* connected state (so that the intended recipient is known).
*
* Parameters:
@ -547,7 +546,7 @@ static inline void sendfile_txnotify(FAR struct socket *psock,
*
****************************************************************************/
ssize_t inet_sendfile(FAR struct socket *psock, FAR struct file *infile,
ssize_t tcp_sendfile(FAR struct socket *psock, FAR struct file *infile,
FAR off_t *offset, size_t count)
{
FAR struct tcp_conn_s *conn;