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: Socket/bsd/stack_endpoint.cpp
- Revision:
- 32:865c101e0874
- Parent:
- 29:1a47b7151851
- Child:
- 33:d8af3f85a484
--- a/Socket/bsd/stack_endpoint.cpp Sun Jun 16 20:27:04 2013 +0000 +++ b/Socket/bsd/stack_endpoint.cpp Thu Jun 20 12:36:39 2013 +0000 @@ -15,6 +15,9 @@ //#define ptsock_dbg printf #define ptsock_dbg(...) +#define TRUE 1 +#define FALSE 0 + int in_the_stack = 0; Mutex *PicoTcpLock; Queue<void,16> *PicoTcpEvents; @@ -34,22 +37,22 @@ * WARNING: PicoTcpLock (big stack lock) must be acquired before entering this. */ -static inline int __critical_select(struct stack_endpoint *ep, uint32_t time) +static inline int __critical_select(struct stack_endpoint *ep, uint32_t time, uint8_t lock) { int retval = 0; uint16_t ev = ep->revents; uint32_t in_time = PICO_TIME_MS(); - PicoTcpLock->unlock(); + if(lock) PicoTcpLock->unlock(); while ((ep->events & ep->revents) == 0) { ep->queue->get(time); if ((time != osWaitForever) && (PICO_TIME_MS() > in_time + time)) { printf("TIMEOUT in critical select... (ev:%04x rev:%04x \n", ep->events, ep->revents); - PicoTcpLock->lock(); + if(lock) PicoTcpLock->lock(); return 0; } } - PicoTcpLock->lock(); + if(lock) PicoTcpLock->lock(); return 1; } @@ -69,6 +72,16 @@ // printf("Activating RD\n"); ep->revents |= ev; + if(ev & PICO_SOCK_EV_ERR) + { + if(pico_err == PICO_ERR_ECONNRESET) + { + printf("Connection reset by peer...\n"); + ep->state = SOCK_RESET_BY_PEER; + pico_socket_close(ep->s); + ep->s->priv = NULL; + } + } if ((ev & PICO_SOCK_EV_CLOSE) || (ev & PICO_SOCK_EV_FIN)) { ep->connected = 0; } @@ -146,7 +159,7 @@ PicoTcpLock->lock(); pico_socket_connect(ep->s, (struct pico_ip4 *)(&srv_addr->sin_addr.s_addr), srv_addr->sin_port); ep->events = PICO_SOCK_EV_CONN | PICO_SOCK_EV_ERR; - __critical_select(ep, osWaitForever); + __critical_select(ep, osWaitForever, TRUE); if ((ep->revents & PICO_SOCK_EV_CONN) && ep->connected) { ep->revents &= (~PICO_SOCK_EV_CONN); ep->revents |= PICO_SOCK_EV_WR; @@ -174,13 +187,14 @@ PicoTcpLock->lock(); ep->events = PICO_SOCK_EV_CONN | PICO_SOCK_EV_ERR; - __critical_select(ep, osWaitForever); + __critical_select(ep, osWaitForever, TRUE); if (ep->revents & PICO_SOCK_EV_CONN) { printf("Calling Accept\n"); aep->s = pico_socket_accept(ep->s, (struct pico_ip4 *)(&cli_addr->sin_addr.s_addr), &cli_addr->sin_port); printf("Accept returned\n"); aep->s->priv = aep; ep->revents &= (~PICO_SOCK_EV_CONN); + aep->revents = 0; // set this to 0 to allow seq connections aep->revents |= PICO_SOCK_EV_WR; printf("Added socket (accept)\n"); @@ -207,7 +221,7 @@ } if (write) ep->events |= PICO_SOCK_EV_WR; - ret = __critical_select(ep, ep->timeout); + ret = __critical_select(ep, ep->timeout,FALSE); return ret; } @@ -303,8 +317,11 @@ int picotcp_close(struct stack_endpoint *ep) { PicoTcpLock->lock(); - pico_socket_close(ep->s); - ep->s->priv = NULL; + if(ep->state != SOCK_RESET_BY_PEER) + { + pico_socket_close(ep->s); + ep->s->priv = NULL; + } printf("Socket closed!\n"); delete(ep->queue); pico_free(ep);