diff options
author | Gregory Nutt <gnutt@nuttx.org> | 2014-06-21 15:23:39 -0600 |
---|---|---|
committer | Gregory Nutt <gnutt@nuttx.org> | 2014-06-21 15:23:39 -0600 |
commit | aa84d73299cb5234cecacc406a54d13cc4dcfe5c (patch) | |
tree | 69154426e6e1c111b48deda4321289a899edd9f4 | |
parent | ae9cd96e4302ce45e0169ff6ee48f7c149412478 (diff) | |
download | nuttx-aa84d73299cb5234cecacc406a54d13cc4dcfe5c.tar.gz nuttx-aa84d73299cb5234cecacc406a54d13cc4dcfe5c.tar.bz2 nuttx-aa84d73299cb5234cecacc406a54d13cc4dcfe5c.zip |
net: Add net/tcp/tcp.h; rename uip_tcpwrbuffer_ to tcp_wrbuffer_*
-rw-r--r-- | nuttx/include/nuttx/net/uip/uip-tcp.h | 10 | ||||
-rw-r--r-- | nuttx/net/net_send_buffered.c | 21 | ||||
-rw-r--r-- | nuttx/net/tcp/tcp.h | 130 | ||||
-rw-r--r-- | nuttx/net/tcp/tcp_conn.c | 11 | ||||
-rw-r--r-- | nuttx/net/tcp/tcp_wrbuffer.c | 18 | ||||
-rw-r--r-- | nuttx/net/uip/uip_initialize.c | 3 | ||||
-rw-r--r-- | nuttx/net/uip/uip_internal.h | 11 |
7 files changed, 159 insertions, 45 deletions
diff --git a/nuttx/include/nuttx/net/uip/uip-tcp.h b/nuttx/include/nuttx/net/uip/uip-tcp.h index fd07e333b..cbb125a74 100644 --- a/nuttx/include/nuttx/net/uip/uip-tcp.h +++ b/nuttx/include/nuttx/net/uip/uip-tcp.h @@ -261,7 +261,7 @@ struct uip_readahead_s /* This structure supports TCP write buffering */ #ifdef CONFIG_NET_TCP_WRITE_BUFFERS -struct uip_wrbuffer_s +struct tcp_wrbuffer_s { sq_entry_t wb_node; /* Supports a singly linked list */ uint32_t wb_seqno; /* Sequence number of the write segment */ @@ -435,14 +435,6 @@ FAR struct uip_readahead_s *uip_tcpreadahead_alloc(void); void uip_tcpreadahead_release(FAR struct uip_readahead_s *readahead); #endif /* CONFIG_NET_TCP_READAHEAD */ -/* Access to TCP write buffers */ - -#ifdef CONFIG_NET_TCP_WRITE_BUFFERS -struct timespec; -FAR struct uip_wrbuffer_s *uip_tcpwrbuffer_alloc(FAR const struct timespec *abstime); -void uip_tcpwrbuffer_release(FAR struct uip_wrbuffer_s *wrbuffer); -#endif /* CONFIG_NET_TCP_WRITE_BUFFERS */ - /* Backlog support */ #ifdef CONFIG_NET_TCPBACKLOG diff --git a/nuttx/net/net_send_buffered.c b/nuttx/net/net_send_buffered.c index 5bf5e77e2..3717b609b 100644 --- a/nuttx/net/net_send_buffered.c +++ b/nuttx/net/net_send_buffered.c @@ -67,6 +67,7 @@ #include <nuttx/net/uip/uip-arch.h> #include "net_internal.h" +#include "tcp/tcp.h" #include "uip/uip_internal.h" /**************************************************************************** @@ -102,7 +103,7 @@ * ****************************************************************************/ -static void send_insert_seqment(FAR struct uip_wrbuffer_s *segment, +static void send_insert_seqment(FAR struct tcp_wrbuffer_s *segment, FAR sq_queue_t *q) { sq_entry_t *entry = (sq_entry_t*)segment; @@ -111,7 +112,7 @@ static void send_insert_seqment(FAR struct uip_wrbuffer_s *segment, sq_entry_t *itr; for (itr = sq_peek(q); itr; itr = sq_next(itr)) { - FAR struct uip_wrbuffer_s *segment0 = (FAR struct uip_wrbuffer_s*)itr; + FAR struct tcp_wrbuffer_s *segment0 = (FAR struct tcp_wrbuffer_s*)itr; if (segment0->wb_seqno < segment->wb_seqno) { insert = itr; @@ -168,14 +169,14 @@ static uint16_t send_interrupt(FAR struct uip_driver_s *dev, FAR void *pvconn, { FAR sq_entry_t *entry; FAR sq_entry_t *next; - FAR struct uip_wrbuffer_s *segment; + FAR struct tcp_wrbuffer_s *segment; uint32_t ackno; ackno = uip_tcpgetsequence(TCPBUF->ackno); for (entry = sq_peek(&conn->unacked_q); entry; entry = next) { next = sq_next(entry); - segment = (FAR struct uip_wrbuffer_s*)entry; + segment = (FAR struct tcp_wrbuffer_s*)entry; if (segment->wb_seqno < ackno) { @@ -188,7 +189,7 @@ static uint16_t send_interrupt(FAR struct uip_driver_s *dev, FAR void *pvconn, /* Return the write buffer to the pool of free buffers */ - uip_tcpwrbuffer_release(segment); + tcp_wrbuffer_release(segment); } } } @@ -217,7 +218,7 @@ static uint16_t send_interrupt(FAR struct uip_driver_s *dev, FAR void *pvconn, while ((entry = sq_remlast(&conn->unacked_q))) { - struct uip_wrbuffer_s *segment = (struct uip_wrbuffer_s*)entry; + struct tcp_wrbuffer_s *segment = (struct tcp_wrbuffer_s*)entry; if (segment->wb_nrtx >= UIP_MAXRTX) { @@ -225,7 +226,7 @@ static uint16_t send_interrupt(FAR struct uip_driver_s *dev, FAR void *pvconn, /* Return the write buffer */ - uip_tcpwrbuffer_release(segment); + tcp_wrbuffer_release(segment); /* NOTE expired is different from un-ACKed, it is designed to * represent the number of segments that have been sent, @@ -282,13 +283,13 @@ static uint16_t send_interrupt(FAR struct uip_driver_s *dev, FAR void *pvconn, if (arp_find(conn->ripaddr) != NULL) #endif { - FAR struct uip_wrbuffer_s *segment; + FAR struct tcp_wrbuffer_s *segment; FAR void *sndbuf; size_t sndlen; /* Get the amount of data that we can send in the next packet */ - segment = (FAR struct uip_wrbuffer_s *)sq_remfirst(&conn->write_q); + segment = (FAR struct tcp_wrbuffer_s *)sq_remfirst(&conn->write_q); if (segment) { sndbuf = segment->wb_buffer; @@ -495,7 +496,7 @@ ssize_t psock_send(FAR struct socket *psock, FAR const void *buf, size_t len, while (completed < len) { - FAR struct uip_wrbuffer_s *segment = uip_tcpwrbuffer_alloc(NULL); + FAR struct tcp_wrbuffer_s *segment = tcp_wrbuffer_alloc(NULL); if (segment) { size_t cnt; diff --git a/nuttx/net/tcp/tcp.h b/nuttx/net/tcp/tcp.h new file mode 100644 index 000000000..b2b515793 --- /dev/null +++ b/nuttx/net/tcp/tcp.h @@ -0,0 +1,130 @@ +/**************************************************************************** + * net/tcp/tcp.h + * + * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef _NET_TCP_TCP_H +#define _NET_TCP_TCP_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#ifdef CONFIG_NET_TCP + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Type Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +#ifdef __cplusplus +# define EXTERN extern "C" +extern "C" +{ +#else +# define EXTERN extern +#endif + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Function: tcp_wrbuffer_initialize + * + * Description: + * Initialize the list of free write buffers + * + * Assumptions: + * Called once early initialization. + * + ****************************************************************************/ + +#ifdef CONFIG_NET_TCP_WRITE_BUFFERS +void tcp_wrbuffer_initialize(void); +#endif /* CONFIG_NET_TCP_WRITE_BUFFERS */ + +/**************************************************************************** + * Function: tcp_wrbuffer_alloc + * + * Description: + * Allocate a TCP write buffer by taking a pre-allocated buffer from + * the free list. This function is called from TCP logic when a buffer + * of TCP data is about to sent + * + * Assumptions: + * Called from user logic with interrupts enabled. + * + ****************************************************************************/ + +#ifdef CONFIG_NET_TCP_WRITE_BUFFERS +struct tcp_wrbuffer_s; +struct timespec; + +FAR struct tcp_wrbuffer_s * +tcp_wrbuffer_alloc(FAR const struct timespec *abstime); +#endif /* CONFIG_NET_TCP_WRITE_BUFFERS */ + +/**************************************************************************** + * Function: tcp_wrbuffer_release + * + * Description: + * Release a TCP write buffer by returning the buffer to the free list. + * This function is called from user logic after it is consumed the + * buffered data. + * + * Assumptions: + * Called from interrupt level with interrupts disabled. + * + ****************************************************************************/ + +#ifdef CONFIG_NET_TCP_WRITE_BUFFERS +void tcp_wrbuffer_release(FAR struct tcp_wrbuffer_s *wrbuffer); +#endif /* CONFIG_NET_TCP_WRITE_BUFFERS */ + +#undef EXTERN +#ifdef __cplusplus +} +#endif + +#endif /* CONFIG_NET_TCP */ +#endif /* _NET_TCP_TCP_H */ diff --git a/nuttx/net/tcp/tcp_conn.c b/nuttx/net/tcp/tcp_conn.c index 0881d9ff9..bae10a754 100644 --- a/nuttx/net/tcp/tcp_conn.c +++ b/nuttx/net/tcp/tcp_conn.c @@ -55,6 +55,7 @@ #include <nuttx/net/uip/uip.h> #include <nuttx/net/uip/uip-arch.h> +#include "tcp/tcp.h" #include "uip/uip_internal.h" /**************************************************************************** @@ -320,7 +321,7 @@ void uip_tcpfree(struct uip_conn *conn) FAR struct uip_readahead_s *readahead; #endif #ifdef CONFIG_NET_TCP_WRITE_BUFFERS - FAR struct uip_wrbuffer_s *wrbuffer; + FAR struct tcp_wrbuffer_s *wrbuffer; #endif uip_lock_t flags; @@ -365,14 +366,14 @@ void uip_tcpfree(struct uip_conn *conn) #ifdef CONFIG_NET_TCP_WRITE_BUFFERS /* Release any write buffers attached to the connection */ - while ((wrbuffer = (struct uip_wrbuffer_s *)sq_remfirst(&conn->write_q)) != NULL) + while ((wrbuffer = (struct tcp_wrbuffer_s *)sq_remfirst(&conn->write_q)) != NULL) { - uip_tcpwrbuffer_release(wrbuffer); + tcp_wrbuffer_release(wrbuffer); } - while ((wrbuffer = (struct uip_wrbuffer_s *)sq_remfirst(&conn->unacked_q)) != NULL) + while ((wrbuffer = (struct tcp_wrbuffer_s *)sq_remfirst(&conn->unacked_q)) != NULL) { - uip_tcpwrbuffer_release(wrbuffer); + tcp_wrbuffer_release(wrbuffer); } #endif diff --git a/nuttx/net/tcp/tcp_wrbuffer.c b/nuttx/net/tcp/tcp_wrbuffer.c index 309ea18d7..cba5f5d23 100644 --- a/nuttx/net/tcp/tcp_wrbuffer.c +++ b/nuttx/net/tcp/tcp_wrbuffer.c @@ -72,7 +72,7 @@ struct wrbuffer_s /* These are the pre-allocated write buffers */ - struct uip_wrbuffer_s buffers[CONFIG_NET_NTCP_WRITE_BUFFERS]; + struct tcp_wrbuffer_s buffers[CONFIG_NET_NTCP_WRITE_BUFFERS]; }; /**************************************************************************** @@ -92,7 +92,7 @@ static struct wrbuffer_s g_wrbuffer; ****************************************************************************/ /**************************************************************************** - * Function: uip_tcpwrbuffer_init + * Function: tcp_wrbuffer_initialize * * Description: * Initialize the list of free write buffers @@ -102,7 +102,7 @@ static struct wrbuffer_s g_wrbuffer; * ****************************************************************************/ -void uip_tcpwrbuffer_init(void) +void tcp_wrbuffer_initialize(void) { int i; @@ -117,7 +117,7 @@ void uip_tcpwrbuffer_init(void) } /**************************************************************************** - * Function: uip_tcpwrbuffer_alloc + * Function: tcp_wrbuffer_alloc * * Description: * Allocate a TCP write buffer by taking a pre-allocated buffer from @@ -129,8 +129,8 @@ void uip_tcpwrbuffer_init(void) * ****************************************************************************/ -FAR struct uip_wrbuffer_s * -uip_tcpwrbuffer_alloc(FAR const struct timespec *abstime) +FAR struct tcp_wrbuffer_s * +tcp_wrbuffer_alloc(FAR const struct timespec *abstime) { int ret; @@ -148,11 +148,11 @@ uip_tcpwrbuffer_alloc(FAR const struct timespec *abstime) return NULL; } - return (FAR struct uip_wrbuffer_s*)sq_remfirst(&g_wrbuffer.freebuffers); + return (FAR struct tcp_wrbuffer_s*)sq_remfirst(&g_wrbuffer.freebuffers); } /**************************************************************************** - * Function: uip_tcpwrbuffer_release + * Function: tcp_wrbuffer_release * * Description: * Release a TCP write buffer by returning the buffer to the free list. @@ -164,7 +164,7 @@ uip_tcpwrbuffer_alloc(FAR const struct timespec *abstime) * ****************************************************************************/ -void uip_tcpwrbuffer_release(FAR struct uip_wrbuffer_s *wrbuffer) +void tcp_wrbuffer_release(FAR struct tcp_wrbuffer_s *wrbuffer) { sq_addlast(&wrbuffer->wb_node, &g_wrbuffer.freebuffers); sem_post(&g_wrbuffer.sem); diff --git a/nuttx/net/uip/uip_initialize.c b/nuttx/net/uip/uip_initialize.c index eac765407..03266fc91 100644 --- a/nuttx/net/uip/uip_initialize.c +++ b/nuttx/net/uip/uip_initialize.c @@ -47,6 +47,7 @@ #include <stdint.h> #include <nuttx/net/uip/uip.h> +#include "tcp/tcp.h" #include "uip_internal.h" /**************************************************************************** @@ -148,7 +149,7 @@ void uip_initialize(void) /* Initialize the TCP/IP write buffering */ #ifdef CONFIG_NET_TCP_WRITE_BUFFERS - uip_tcpwrbuffer_init(); + tcp_wrbuffer_initialize(); #endif /* Initialize the UDP connection structures */ diff --git a/nuttx/net/uip/uip_internal.h b/nuttx/net/uip/uip_internal.h index d3be9011e..a5ebc56ec 100644 --- a/nuttx/net/uip/uip_internal.h +++ b/nuttx/net/uip/uip_internal.h @@ -194,17 +194,6 @@ FAR struct uip_readahead_s *uip_tcpreadahead_alloc(void); void uip_tcpreadahead_release(FAR struct uip_readahead_s *readahead); #endif /* CONFIG_NET_TCP_READAHEAD */ -/* Defined in tcp_wrbuffer.c ************************************************/ - -#ifdef CONFIG_NET_TCP_WRITE_BUFFERS -void uip_tcpwrbuffer_init(void); - -struct uip_wrbuffer_s; -struct timespec; -FAR struct uip_wrbuffer_s *uip_tcpwrbuffer_alloc(FAR const struct timespec *abstime); -void uip_tcpwrbuffer_release(FAR struct uip_wrbuffer_s *wrbuffer); -#endif /* CONFIG_NET_TCP_WRITE_BUFFERS */ - #endif /* CONFIG_NET_TCP */ #ifdef CONFIG_NET_UDP |