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 RTOS
  • generic mbed Ethernet driver
  • high performance NXP LPC1768 specific Ethernet driver
  • Multi-threading support for mbed RTOS
  • Berkeley sockets and integration with the New Socket API
  • Fork of the apps running on top of the New Socket API
  • Scheduling 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.

Committer:
tass
Date:
Wed Jun 12 13:35:01 2013 +0000
Revision:
31:d3b2dfcc358f
Parent:
24:8bff2b51ea3b
updated pico_tcp and pico_socket after the mainline.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
daniele 20:3fa3db9fd4a4 1 /*
daniele 20:3fa3db9fd4a4 2 *
daniele 20:3fa3db9fd4a4 3 * PicoTCP Socket interface for mbed.
daniele 20:3fa3db9fd4a4 4 * Copyright (C) 2013 TASS Belgium NV
daniele 20:3fa3db9fd4a4 5 *
daniele 20:3fa3db9fd4a4 6 * Released under GPL v2
daniele 20:3fa3db9fd4a4 7 *
daniele 20:3fa3db9fd4a4 8 * Other licensing models might apply at the sole discretion of the copyright holders.
daniele 20:3fa3db9fd4a4 9 *
daniele 20:3fa3db9fd4a4 10 *
daniele 20:3fa3db9fd4a4 11 * This software is based on the mbed.org EthernetInterface implementation:
daniele 20:3fa3db9fd4a4 12 * Copyright (C) 2012 mbed.org, MIT License
daniele 20:3fa3db9fd4a4 13 *
daniele 20:3fa3db9fd4a4 14 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
daniele 20:3fa3db9fd4a4 15 * and associated documentation files (the "Software"), to deal in the Software without restriction,
daniele 20:3fa3db9fd4a4 16 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
daniele 20:3fa3db9fd4a4 17 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
daniele 20:3fa3db9fd4a4 18 * furnished to do so, subject to the following conditions:
daniele 20:3fa3db9fd4a4 19 *
daniele 20:3fa3db9fd4a4 20 * The above copyright notice and this permission notice shall be included in all copies or
daniele 20:3fa3db9fd4a4 21 * substantial portions of the Software.
daniele 20:3fa3db9fd4a4 22 *
daniele 20:3fa3db9fd4a4 23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
daniele 20:3fa3db9fd4a4 24 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
daniele 20:3fa3db9fd4a4 25 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
daniele 20:3fa3db9fd4a4 26 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
daniele 20:3fa3db9fd4a4 27 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
daniele 20:3fa3db9fd4a4 28 */
daniele 20:3fa3db9fd4a4 29 #include "Socket/Socket.h"
daniele 20:3fa3db9fd4a4 30 #include "wrapper.h"
daniele 20:3fa3db9fd4a4 31 #include "proxy_endpoint.h"
daniele 20:3fa3db9fd4a4 32 #include <cstring>
daniele 20:3fa3db9fd4a4 33
daniele 20:3fa3db9fd4a4 34 using std::memset;
daniele 20:3fa3db9fd4a4 35
daniele 20:3fa3db9fd4a4 36 Socket::Socket() : _ep(NULL), _blocking(true)
tass 31:d3b2dfcc358f 37 {}
daniele 20:3fa3db9fd4a4 38
daniele 20:3fa3db9fd4a4 39 void Socket::set_blocking(bool blocking, unsigned int timeout) {
daniele 20:3fa3db9fd4a4 40 _blocking = blocking;
daniele 20:3fa3db9fd4a4 41 _timeout = timeout;
daniele 20:3fa3db9fd4a4 42 }
daniele 20:3fa3db9fd4a4 43
daniele 20:3fa3db9fd4a4 44 int Socket::init_socket(int type) {
daniele 20:3fa3db9fd4a4 45 if (_ep != NULL)
daniele 20:3fa3db9fd4a4 46 {
daniele 20:3fa3db9fd4a4 47 printf("Sock open already...\n");
daniele 20:3fa3db9fd4a4 48 return -1;
daniele 20:3fa3db9fd4a4 49 }
daniele 20:3fa3db9fd4a4 50 struct stack_endpoint *ep = picotcp_socket(AF_INET, type, 0);
daniele 20:3fa3db9fd4a4 51 if (!ep)
daniele 20:3fa3db9fd4a4 52 {
daniele 20:3fa3db9fd4a4 53 printf("Error opening socket...\n");
daniele 20:3fa3db9fd4a4 54 return -1;
daniele 20:3fa3db9fd4a4 55 }
daniele 20:3fa3db9fd4a4 56 _ep = ep;
daniele 20:3fa3db9fd4a4 57 return 0;
daniele 20:3fa3db9fd4a4 58 }
daniele 20:3fa3db9fd4a4 59
daniele 20:3fa3db9fd4a4 60 int Socket::set_option(int level, int optname, const void *optval, socklen_t optlen) {
daniele 20:3fa3db9fd4a4 61 return picotcp_setsockopt(_ep, optname, (void *)optval);
daniele 20:3fa3db9fd4a4 62 }
daniele 20:3fa3db9fd4a4 63
daniele 20:3fa3db9fd4a4 64 int Socket::get_option(int level, int optname, void *optval, socklen_t *optlen) {
daniele 20:3fa3db9fd4a4 65 return picotcp_getsockopt(_ep, optname, optval);
daniele 20:3fa3db9fd4a4 66 }
daniele 20:3fa3db9fd4a4 67
daniele 20:3fa3db9fd4a4 68 int Socket::select(struct timeval *timeout, bool read, bool write) {
daniele 20:3fa3db9fd4a4 69 return picotcp_select(_ep, timeout, read, write);
daniele 20:3fa3db9fd4a4 70 }
daniele 20:3fa3db9fd4a4 71
daniele 20:3fa3db9fd4a4 72 int Socket::wait_readable(TimeInterval& timeout) {
daniele 20:3fa3db9fd4a4 73 return (select(&timeout._time, true, false) == 0 ? -1 : 0);
daniele 20:3fa3db9fd4a4 74 }
daniele 20:3fa3db9fd4a4 75
daniele 20:3fa3db9fd4a4 76 int Socket::wait_writable(TimeInterval& timeout) {
daniele 20:3fa3db9fd4a4 77 return (select(&timeout._time, false, true) == 0 ? -1 : 0);
daniele 20:3fa3db9fd4a4 78 }
daniele 20:3fa3db9fd4a4 79
daniele 20:3fa3db9fd4a4 80 int Socket::close() {
daniele 24:8bff2b51ea3b 81 if (_ep == NULL)
daniele 20:3fa3db9fd4a4 82 return -1;
daniele 20:3fa3db9fd4a4 83
daniele 20:3fa3db9fd4a4 84 picotcp_close(_ep);
tass 31:d3b2dfcc358f 85 delete(_ep->CallResponseQueue);
tass 31:d3b2dfcc358f 86 delete(_ep->CallActivateQueue);
daniele 24:8bff2b51ea3b 87 pico_free(_ep);
daniele 20:3fa3db9fd4a4 88 _ep = NULL;
daniele 20:3fa3db9fd4a4 89
daniele 20:3fa3db9fd4a4 90 return 0;
daniele 20:3fa3db9fd4a4 91 }
daniele 20:3fa3db9fd4a4 92
daniele 20:3fa3db9fd4a4 93 Socket::~Socket() {
daniele 24:8bff2b51ea3b 94 if(_ep)
tass 31:d3b2dfcc358f 95 {
tass 31:d3b2dfcc358f 96 delete(_ep->CallResponseQueue);
tass 31:d3b2dfcc358f 97 delete(_ep->CallActivateQueue);
daniele 24:8bff2b51ea3b 98 pico_free(_ep);
tass 31:d3b2dfcc358f 99 _ep = NULL;
tass 31:d3b2dfcc358f 100 }
daniele 20:3fa3db9fd4a4 101 }
daniele 20:3fa3db9fd4a4 102
daniele 20:3fa3db9fd4a4 103 TimeInterval::TimeInterval(unsigned int ms) {
daniele 20:3fa3db9fd4a4 104 _time.tv_sec = ms / 1000;
daniele 20:3fa3db9fd4a4 105 _time.tv_usec = (ms - (_time.tv_sec * 1000)) * 1000;
daniele 20:3fa3db9fd4a4 106 }