Free (GPLv2) TCP/IP stack developed by TASS Belgium
Dependents: lpc1768-picotcp-demo ZeroMQ_PicoTCP_Publisher_demo TCPSocket_HelloWorld_PicoTCP Pico_TCP_UDP_Test ... more
PicoTCP. Copyright (c) 2013 TASS Belgium NV.
Released under the GNU General Public License, version 2.
Different licensing models may exist, at the sole discretion of the Copyright holders.
Official homepage: http://www.picotcp.com
Bug tracker: https://github.com/tass-belgium/picotcp/issues
Development steps:
initial integration with mbed RTOSgeneric mbed Ethernet driverhigh performance NXP LPC1768 specific Ethernet driverMulti-threading support for mbed RTOSBerkeley sockets and integration with the New Socket APIFork of the apps running on top of the New Socket APIScheduling optimizations- Debugging/benchmarking/testing
Demo application (measuring TCP sender performance):
Import programlpc1768-picotcp-demo
A PicoTCP demo app testing the ethernet throughput on the lpc1768 mbed board.
Diff: include/pico_socket.h
- Revision:
- 149:5f4cb161cec3
- Parent:
- 137:a1c8bfa9d691
- Child:
- 152:a3d286bf94e5
--- a/include/pico_socket.h Tue Mar 11 15:34:51 2014 +0100 +++ b/include/pico_socket.h Wed Apr 09 14:31:41 2014 +0200 @@ -3,12 +3,13 @@ See LICENSE and COPYING for usage. *********************************************************************/ -#ifndef _INCLUDE_PICO_SOCKET -#define _INCLUDE_PICO_SOCKET +#ifndef INCLUDE_PICO_SOCKET +#define INCLUDE_PICO_SOCKET #include "pico_queue.h" #include "pico_addressing.h" #include "pico_config.h" #include "pico_protocol.h" +#include "pico_tree.h" #ifdef __linux__ #define PICO_DEFAULT_SOCKETQ (16 * 1024) /* Linux host, so we want full throttle */ @@ -20,20 +21,20 @@ #define PICO_SHUT_WR 2 #define PICO_SHUT_RDWR 3 +struct pico_sockport +{ + struct pico_tree socks; /* how you make the connection ? */ + uint16_t number; + uint16_t proto; +}; + struct pico_socket { struct pico_protocol *proto; struct pico_protocol *net; - union { - struct pico_ip4 ip4; - struct pico_ip6 ip6; - } local_addr; - - union { - struct pico_ip4 ip4; - struct pico_ip6 ip6; - } remote_addr; + union pico_address local_addr; + union pico_address remote_addr; uint16_t local_port; uint16_t remote_port; @@ -49,8 +50,8 @@ struct pico_socket *backlog; struct pico_socket *next; struct pico_socket *parent; - int max_backlog; - uint8_t number_of_pending_conn; + uint16_t max_backlog; + uint16_t number_of_pending_conn; #endif #ifdef PICO_SUPPORT_MCAST struct pico_tree *MCASTListen; @@ -67,12 +68,8 @@ void *priv; }; -struct pico_remote_duple { - union { - struct pico_ip4 ip4; - struct pico_ip6 ip6; - } remote_addr; - +struct pico_remote_endpoint { + union pico_address remote_addr; uint16_t remote_port; }; @@ -89,32 +86,33 @@ struct pico_ip4 mcast_link_addr; }; -#define PICO_SOCKET_STATE_UNDEFINED 0x0000 -#define PICO_SOCKET_STATE_SHUT_LOCAL 0x0001 -#define PICO_SOCKET_STATE_SHUT_REMOTE 0x0002 -#define PICO_SOCKET_STATE_BOUND 0x0004 -#define PICO_SOCKET_STATE_CONNECTED 0x0008 -#define PICO_SOCKET_STATE_CLOSING 0x0010 -#define PICO_SOCKET_STATE_CLOSED 0x0020 +#define PICO_SOCKET_STATE_UNDEFINED 0x0000u +#define PICO_SOCKET_STATE_SHUT_LOCAL 0x0001u +#define PICO_SOCKET_STATE_SHUT_REMOTE 0x0002u +#define PICO_SOCKET_STATE_BOUND 0x0004u +#define PICO_SOCKET_STATE_CONNECTED 0x0008u +#define PICO_SOCKET_STATE_CLOSING 0x0010u +#define PICO_SOCKET_STATE_CLOSED 0x0020u -# define PICO_SOCKET_STATE_TCP 0xFF00 -# define PICO_SOCKET_STATE_TCP_UNDEF 0x00FF -# define PICO_SOCKET_STATE_TCP_CLOSED 0x0100 -# define PICO_SOCKET_STATE_TCP_LISTEN 0x0200 -# define PICO_SOCKET_STATE_TCP_SYN_SENT 0x0300 -# define PICO_SOCKET_STATE_TCP_SYN_RECV 0x0400 -# define PICO_SOCKET_STATE_TCP_ESTABLISHED 0x0500 -# define PICO_SOCKET_STATE_TCP_CLOSE_WAIT 0x0600 -# define PICO_SOCKET_STATE_TCP_LAST_ACK 0x0700 -# define PICO_SOCKET_STATE_TCP_FIN_WAIT1 0x0800 -# define PICO_SOCKET_STATE_TCP_FIN_WAIT2 0x0900 -# define PICO_SOCKET_STATE_TCP_CLOSING 0x0a00 -# define PICO_SOCKET_STATE_TCP_TIME_WAIT 0x0b00 -# define PICO_SOCKET_STATE_TCP_ARRAYSIZ 0x0c +# define PICO_SOCKET_STATE_TCP 0xFF00u +# define PICO_SOCKET_STATE_TCP_UNDEF 0x00FFu +# define PICO_SOCKET_STATE_TCP_CLOSED 0x0100u +# define PICO_SOCKET_STATE_TCP_LISTEN 0x0200u +# define PICO_SOCKET_STATE_TCP_SYN_SENT 0x0300u +# define PICO_SOCKET_STATE_TCP_SYN_RECV 0x0400u +# define PICO_SOCKET_STATE_TCP_ESTABLISHED 0x0500u +# define PICO_SOCKET_STATE_TCP_CLOSE_WAIT 0x0600u +# define PICO_SOCKET_STATE_TCP_LAST_ACK 0x0700u +# define PICO_SOCKET_STATE_TCP_FIN_WAIT1 0x0800u +# define PICO_SOCKET_STATE_TCP_FIN_WAIT2 0x0900u +# define PICO_SOCKET_STATE_TCP_CLOSING 0x0a00u +# define PICO_SOCKET_STATE_TCP_TIME_WAIT 0x0b00u +# define PICO_SOCKET_STATE_TCP_ARRAYSIZ 0x0cu + +/* Socket options */ # define PICO_TCP_NODELAY 1 - -# define PICO_SOCKET_OPT_TCPNODELAY 0x0000 +# define PICO_SOCKET_OPT_TCPNODELAY 0x0000u # define PICO_IP_MULTICAST_EXCLUDE 0 # define PICO_IP_MULTICAST_INCLUDE 1 @@ -130,22 +128,26 @@ # define PICO_SOCKET_OPT_MULTICAST_LOOP 1 +# define PICO_SOCKET_OPT_RCVBUF 52 +# define PICO_SOCKET_OPT_SNDBUF 53 + +/* Constants */ # define PICO_IP_DEFAULT_MULTICAST_TTL 1 # define PICO_IP_DEFAULT_MULTICAST_LOOP 1 #define PICO_SOCKET_TIMEOUT 90000u /* 90 seconds */ #define PICO_SOCKET_BOUND_TIMEOUT 30000u /* 30 seconds */ -#define PICO_SOCKET_SHUTDOWN_WRITE 0x01 -#define PICO_SOCKET_SHUTDOWN_READ 0x02 +#define PICO_SOCKET_SHUTDOWN_WRITE 0x01u +#define PICO_SOCKET_SHUTDOWN_READ 0x02u #define TCPSTATE(s) ((s)->state & PICO_SOCKET_STATE_TCP) -#define PICO_SOCK_EV_RD 1 -#define PICO_SOCK_EV_WR 2 -#define PICO_SOCK_EV_CONN 4 -#define PICO_SOCK_EV_CLOSE 8 -#define PICO_SOCK_EV_FIN 0x10 -#define PICO_SOCK_EV_ERR 0x80 +#define PICO_SOCK_EV_RD 1u +#define PICO_SOCK_EV_WR 2u +#define PICO_SOCK_EV_CONN 4u +#define PICO_SOCK_EV_CLOSE 8u +#define PICO_SOCK_EV_FIN 0x10u +#define PICO_SOCK_EV_ERR 0x80u struct pico_socket *pico_socket_open(uint16_t net, uint16_t proto, void (*wakeup)(uint16_t ev, struct pico_socket *s)); @@ -160,6 +162,8 @@ int pico_socket_recv(struct pico_socket *s, void *buf, int len); int pico_socket_bind(struct pico_socket *s, void *local_addr, uint16_t *port); +int pico_socket_getname(struct pico_socket *s, void *local_addr, uint16_t *port, uint16_t *proto); + int pico_socket_connect(struct pico_socket *s, const void *srv_addr, uint16_t remote_port); int pico_socket_listen(struct pico_socket *s, const int backlog); struct pico_socket *pico_socket_accept(struct pico_socket *s, void *orig, uint16_t *port); @@ -209,5 +213,14 @@ /* Port check */ int pico_is_port_free(uint16_t proto, uint16_t port, void *addr, void *net); +struct pico_sockport *pico_get_sockport(uint16_t proto, uint16_t port); + +uint16_t pico_socket_get_mtu(struct pico_socket *s); +int pico_socket_set_family(struct pico_socket *s, uint16_t family); + +#define PICO_SOCKET_SETOPT_EN(socket, index) (socket->opt_flags |= (1 << index)) +#define PICO_SOCKET_SETOPT_DIS(socket, index) (socket->opt_flags &= (uint16_t) ~(1 << index)) +#define PICO_SOCKET_GETOPT(socket, index) ((socket->opt_flags & (1u << index)) != 0) + #endif