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:
Thu Jan 28 15:12:00 2016 +0100
Revision:
155:a70f34550c34
Parent:
120:0035e9b2fec7
Adding TCP flag for FIN.

Who changed what in which revision?

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