mirror of
https://github.com/apache/nuttx.git
synced 2026-05-28 20:08:15 +08:00
Add uIP support more multi-threaded socket access
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@858 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
+29
-22
@@ -95,6 +95,7 @@
|
||||
*/
|
||||
|
||||
struct uip_driver_s; /* Forward reference */
|
||||
struct uip_callback_s; /* Forward reference */
|
||||
struct uip_conn
|
||||
{
|
||||
dq_entry_t node; /* Implements a doubly linked list */
|
||||
@@ -121,9 +122,6 @@ struct uip_conn
|
||||
uint8 timer; /* The retransmission timer (units: half-seconds) */
|
||||
uint8 nrtx; /* The number of retransmissions for the last
|
||||
* segment sent */
|
||||
uint8 data_flags; /* Flags that will be handled by the data_event()
|
||||
* callback function (see data_event() discussion below).
|
||||
*/
|
||||
|
||||
/* Read-ahead buffering */
|
||||
|
||||
@@ -131,37 +129,41 @@ struct uip_conn
|
||||
sq_queue_t readahead;
|
||||
#endif
|
||||
|
||||
/* Higher level logic can retain application specific information
|
||||
* in the following:
|
||||
/* Application callbacks:
|
||||
*
|
||||
* data_event() is called on all events. Normally, the input flags are
|
||||
* returned, however, the implemenation may set one of the following:
|
||||
* Data transfer events are retained in 'list'. Event handlers in 'list'
|
||||
* are called for events specified in the flags set within struct
|
||||
* uip_callback_s
|
||||
*
|
||||
* UIP_CLOSE - Gracefully close the current connection
|
||||
* UIP_ABORT - Abort (reset) the current connection on an error that
|
||||
* prevents UIP_CLOSE from working.
|
||||
* When an callback is executed from 'list', the input flags are normally
|
||||
* returned, however, the implementation may set one of the following:
|
||||
*
|
||||
* Or clear the following:
|
||||
* UIP_CLOSE - Gracefully close the current connection
|
||||
* UIP_ABORT - Abort (reset) the current connection on an error that
|
||||
* prevents UIP_CLOSE from working.
|
||||
*
|
||||
* UIP_NEWDATA - May be cleared to suppress returning the ACK response.
|
||||
* (dev->d_len should also be set to zero in this case).
|
||||
* And/Or set/clear the following:
|
||||
*
|
||||
*
|
||||
* The provider of the data_event callback must also set data_flags. This
|
||||
* will inform the uIP layer which flags are and are not handled by the
|
||||
* callback.
|
||||
* accept() is called when the TCP logic has created a connection
|
||||
* connection_event() is called on any of the subset of connection-related events
|
||||
* UIP_NEWDATA - May be cleared to indicate that the data was consumed
|
||||
* and that no further process of the new data should be
|
||||
* attempted.
|
||||
* UIP_SNDACK - If UIP_NEWDATA is cleared, then UIP_SNDACK may be set
|
||||
* to indicate that an ACK should be included in the response.
|
||||
* (In UIP_NEWDATA is cleared bu UIP_SNDACK is not set, then
|
||||
* dev->d_len should also be cleared).
|
||||
*/
|
||||
|
||||
void *data_private;
|
||||
uint8 (*data_event)(struct uip_driver_s *dev, struct uip_conn *conn, uint8 flags);
|
||||
struct uip_callback_s *list;
|
||||
|
||||
/* accept() is called when the TCP logic has created a connection */
|
||||
|
||||
void *accept_private;
|
||||
int (*accept)(struct uip_conn *listener, struct uip_conn *conn);
|
||||
|
||||
/* connection_event() is called on any of the subset of connection-related events */
|
||||
|
||||
void *connection_private;
|
||||
void (*connection_event)(struct uip_conn *conn, uint8 flags);
|
||||
void (*connection_event)(struct uip_conn *conn, uint16 flags);
|
||||
};
|
||||
|
||||
/* The following structure is used to handle read-ahead buffering for TCP
|
||||
@@ -267,6 +269,11 @@ struct uip_tcpip_hdr
|
||||
|
||||
extern struct uip_conn *uip_tcpalloc(void);
|
||||
|
||||
/* Allocate a new TCP data callback */
|
||||
|
||||
#define uip_tcpcallbackalloc(conn) uip_callbackalloc(&conn->list)
|
||||
#define uip_tcpcallbackfree(conn,cb) uip_callbackfree(cb, &conn->list)
|
||||
|
||||
/* Free a connection structure that is no longer in use. This should
|
||||
* be done by the implementation of close()
|
||||
*/
|
||||
|
||||
@@ -69,6 +69,7 @@
|
||||
/* Representation of a uIP UDP connection */
|
||||
|
||||
struct uip_driver_s; /* Forward reference */
|
||||
struct uip_callback_s; /* Forward reference */
|
||||
struct uip_udp_conn
|
||||
{
|
||||
dq_entry_t node; /* Supports a doubly linked list */
|
||||
@@ -77,10 +78,9 @@ struct uip_udp_conn
|
||||
uint16 rport; /* The remote port number in network byte order */
|
||||
uint8 ttl; /* Default time-to-live */
|
||||
|
||||
/* Defines the UDP callback */
|
||||
/* Defines the list of UDP callbacks */
|
||||
|
||||
void *private;
|
||||
void (*event)(struct uip_driver_s *dev, struct uip_udp_conn *conn, uint8 flags);
|
||||
struct uip_callback_s *list;
|
||||
};
|
||||
|
||||
/* The UDP and IP headers */
|
||||
@@ -159,6 +159,11 @@ struct uip_udp_stats_s
|
||||
|
||||
extern struct uip_udp_conn *uip_udpalloc(void);
|
||||
|
||||
/* Allocate a new TCP data callback */
|
||||
|
||||
#define uip_udpcallbackalloc(conn) uip_callbackalloc(&conn->list)
|
||||
#define uip_udpcallbackfree(conn,cb) uip_callbackfree(cb, &conn->list)
|
||||
|
||||
/* Free a connection structure that is no longer in use. This should
|
||||
* be done by the implementation of close()
|
||||
*/
|
||||
|
||||
+67
-20
@@ -5,7 +5,7 @@
|
||||
* are used by uIP programs as well as internal uIP structures and function
|
||||
* declarations.
|
||||
*
|
||||
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
*
|
||||
* This logic was leveraged from uIP which also has a BSD-style license:
|
||||
@@ -55,6 +55,7 @@
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include <net/uip/uipopt.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Definitions
|
||||
****************************************************************************/
|
||||
@@ -62,26 +63,52 @@
|
||||
/* The following flags may be set in the set of flags before calling the
|
||||
* application callback. The UIP_ACKDATA, UIP_NEWDATA, and UIP_CLOSE flags
|
||||
* may be set at the same time, whereas the others are mutualy exclusive.
|
||||
*
|
||||
* UIP_ACKDATA IN: Signifies that the outstanding data was acked and
|
||||
* the application should send out new data instead
|
||||
* of retransmitting the last data
|
||||
* OUT: Input state must be preserved on output.
|
||||
* UIP_NEWDATA IN: Set to indicate that the peer has sent us new data.
|
||||
* OUT: Cleared (only) by the application logic to indicate
|
||||
* that the new data was consumed, suppressing further
|
||||
* attempts to process the new data.
|
||||
* UIP_SNDACK IN: Not used; always zero
|
||||
* OUT: Set by the application if the new data was consumed
|
||||
* and an ACK should be sent in the response.
|
||||
* UIP_REXMIT IN: Tells the application to retransmit the data that
|
||||
* was last sent
|
||||
* OUT: Not used
|
||||
* UIP_POLL IN: Used for polling the application. This is provided
|
||||
* periodically from the drivers to support (1) timed
|
||||
* operations, and (2) to check if the application has
|
||||
* data that it wants to send
|
||||
* OUT: Not used
|
||||
* UIP_CLOSE IN: The remote host has closed the connection, thus the
|
||||
* connection has gone away.
|
||||
* OUT: The application signals that it wants to close the
|
||||
* connection
|
||||
* UIP_ABORT IN: The remote host has aborted the connection, thus the
|
||||
* connection has gone away.
|
||||
* OUT: The application signals that it wants to abort the
|
||||
* connection
|
||||
* UIP_CONNECTED IN: We have got a connection from a remote host and have
|
||||
* set up a new connection for it, or an active connection
|
||||
* has been successfully established
|
||||
* OUT: Not used
|
||||
* UIP_TIMEDOUT IN: The connection has been aborted due to too many
|
||||
* retransmissions
|
||||
* OUT: Not used
|
||||
*/
|
||||
|
||||
#define UIP_ACKDATA (1 << 0) /* Signifies that the outstanding data was acked and the
|
||||
* application should send out new data instead of retransmitting
|
||||
* the last data */
|
||||
#define UIP_NEWDATA (1 << 1) /* Flags the fact that the peer has sent us new data */
|
||||
#define UIP_REXMIT (1 << 2) /* Tells the application to retransmit the data that was last
|
||||
* sent */
|
||||
#define UIP_POLL (1 << 3) /* Used for polling the application, to check if the application
|
||||
* has data that it wants to send */
|
||||
#define UIP_CLOSE (1 << 4) /* The remote host has closed the connection, thus the connection
|
||||
* has gone away. Or the application signals that it wants to
|
||||
* close the connection */
|
||||
#define UIP_ABORT (1 << 5) /* The remote host has aborted the connection, thus the connection
|
||||
* has gone away. Or the application signals that it wants to
|
||||
* abort the connection */
|
||||
#define UIP_CONNECTED (1 << 6) /* We have got a connection from a remote host and have set up a
|
||||
* new connection for it, or an active connection has been
|
||||
* successfully established */
|
||||
#define UIP_TIMEDOUT (1 << 7) /* The connection has been aborted due to too many retransmissions */
|
||||
#define UIP_ACKDATA (1 << 0)
|
||||
#define UIP_NEWDATA (1 << 1)
|
||||
#define UIP_SNDACK (1 << 2)
|
||||
#define UIP_REXMIT (1 << 3)
|
||||
#define UIP_POLL (1 << 4)
|
||||
#define UIP_CLOSE (1 << 5)
|
||||
#define UIP_ABORT (1 << 6)
|
||||
#define UIP_CONNECTED (1 << 7)
|
||||
#define UIP_TIMEDOUT (1 << 8)
|
||||
|
||||
#define UIP_DATA_EVENTS (UIP_ACKDATA|UIP_NEWDATA|UIP_REXMIT|UIP_POLL)
|
||||
#define UIP_CONN_EVENTS (UIP_CLOSE|UIP_ABORT|UIP_CONNECTED|UIP_TIMEDOUT)
|
||||
@@ -116,7 +143,7 @@
|
||||
* Public Type Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Repressentation of an IP address */
|
||||
/* Representation of an IP address */
|
||||
|
||||
typedef in_addr_t uip_ip4addr_t;
|
||||
typedef uint16 uip_ip6addr_t[8];
|
||||
@@ -162,6 +189,26 @@ struct uip_ip_hdr
|
||||
#endif /* CONFIG_NET_IPv6 */
|
||||
};
|
||||
|
||||
/* Describes a uIP callback
|
||||
*
|
||||
* flink - Supports a singly linked list
|
||||
* event - Provides the address of the callback function entry point.
|
||||
* pvconn is a pointer to one of struct uip_conn or struct uip_udp_conn.
|
||||
* private - Holds a reference to application specific data that will
|
||||
* provided
|
||||
* flags - Set by the application to inform the uIP layer which flags
|
||||
* are and are not handled by the callback.
|
||||
*/
|
||||
|
||||
struct uip_driver_s; /* Forward reference */
|
||||
struct uip_callback_s
|
||||
{
|
||||
FAR struct uip_callback_s *flink;
|
||||
uint16 (*event)(struct uip_driver_s *dev, void *pvconn, void *pvprivate, uint16 flags);
|
||||
void *private;
|
||||
uint16 flags;
|
||||
};
|
||||
|
||||
/* Protocol-specific support */
|
||||
|
||||
#include <net/uip/uip-tcp.h>
|
||||
|
||||
@@ -103,7 +103,11 @@
|
||||
/* The maximum amount of concurrent UDP connection, Default: 10 */
|
||||
|
||||
#ifndef CONFIG_NET_UDP_CONNS
|
||||
# define CONFIG_NET_UDP_CONNS 10
|
||||
# ifdef CONFIG_NET_UDP
|
||||
# define CONFIG_NET_UDP_CONNS 10
|
||||
# else
|
||||
# define CONFIG_NET_UDP_CONNS 0
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* TCP configuration options */
|
||||
@@ -116,7 +120,11 @@
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_NET_TCP_CONNS
|
||||
# define CONFIG_NET_TCP_CONNS 10
|
||||
# ifdef CONFIG_NET_TCP
|
||||
# define CONFIG_NET_TCP_CONNS 10
|
||||
# else
|
||||
# define CONFIG_NET_TCP_CONNS 0
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* The maximum number of simultaneously listening TCP ports.
|
||||
@@ -128,6 +136,15 @@
|
||||
# define CONFIG_NET_MAX_LISTENPORTS 20
|
||||
#endif
|
||||
|
||||
/* Define the maximum number of concurrently active UDP and TCP
|
||||
* ports. This number must be greater than the number of open
|
||||
* sockets in order to support multi-threaded read/write operations.
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_NET_NACTIVESOCKETS
|
||||
# define CONFIG_NET_NACTIVESOCKETS (CONFIG_NET_TCP_CONNS + CONFIG_NET_UDP_CONNS)
|
||||
#endif
|
||||
|
||||
/* The initial retransmission timeout counted in timer pulses.
|
||||
*
|
||||
* This should not be changed.
|
||||
|
||||
Reference in New Issue
Block a user