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:
daniele
Date:
Sat Jun 08 13:48:10 2013 +0000
Revision:
20:3fa3db9fd4a4
Child:
24:8bff2b51ea3b
Refactoring of the socket interface

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)
daniele 20:3fa3db9fd4a4 37 {
daniele 20:3fa3db9fd4a4 38 //set_blocking(true,1500); // ?
daniele 20:3fa3db9fd4a4 39 }
daniele 20:3fa3db9fd4a4 40
daniele 20:3fa3db9fd4a4 41 void Socket::set_blocking(bool blocking, unsigned int timeout) {
daniele 20:3fa3db9fd4a4 42 _blocking = blocking;
daniele 20:3fa3db9fd4a4 43 _timeout = timeout;
daniele 20:3fa3db9fd4a4 44 }
daniele 20:3fa3db9fd4a4 45
daniele 20:3fa3db9fd4a4 46 int Socket::init_socket(int type) {
daniele 20:3fa3db9fd4a4 47 if (_ep != NULL)
daniele 20:3fa3db9fd4a4 48 {
daniele 20:3fa3db9fd4a4 49 printf("Sock open already...\n");
daniele 20:3fa3db9fd4a4 50 return -1;
daniele 20:3fa3db9fd4a4 51 }
daniele 20:3fa3db9fd4a4 52 struct stack_endpoint *ep = picotcp_socket(AF_INET, type, 0);
daniele 20:3fa3db9fd4a4 53 if (!ep)
daniele 20:3fa3db9fd4a4 54 {
daniele 20:3fa3db9fd4a4 55 printf("Error opening socket...\n");
daniele 20:3fa3db9fd4a4 56 return -1;
daniele 20:3fa3db9fd4a4 57 }
daniele 20:3fa3db9fd4a4 58 _ep = ep;
daniele 20:3fa3db9fd4a4 59 return 0;
daniele 20:3fa3db9fd4a4 60 }
daniele 20:3fa3db9fd4a4 61
daniele 20:3fa3db9fd4a4 62 int Socket::set_option(int level, int optname, const void *optval, socklen_t optlen) {
daniele 20:3fa3db9fd4a4 63 return picotcp_setsockopt(_ep, optname, (void *)optval);
daniele 20:3fa3db9fd4a4 64 }
daniele 20:3fa3db9fd4a4 65
daniele 20:3fa3db9fd4a4 66 int Socket::get_option(int level, int optname, void *optval, socklen_t *optlen) {
daniele 20:3fa3db9fd4a4 67 return picotcp_getsockopt(_ep, optname, optval);
daniele 20:3fa3db9fd4a4 68 }
daniele 20:3fa3db9fd4a4 69
daniele 20:3fa3db9fd4a4 70 int Socket::select(struct timeval *timeout, bool read, bool write) {
daniele 20:3fa3db9fd4a4 71 return picotcp_select(_ep, timeout, read, write);
daniele 20:3fa3db9fd4a4 72 }
daniele 20:3fa3db9fd4a4 73
daniele 20:3fa3db9fd4a4 74 int Socket::wait_readable(TimeInterval& timeout) {
daniele 20:3fa3db9fd4a4 75 return (select(&timeout._time, true, false) == 0 ? -1 : 0);
daniele 20:3fa3db9fd4a4 76 }
daniele 20:3fa3db9fd4a4 77
daniele 20:3fa3db9fd4a4 78 int Socket::wait_writable(TimeInterval& timeout) {
daniele 20:3fa3db9fd4a4 79 return (select(&timeout._time, false, true) == 0 ? -1 : 0);
daniele 20:3fa3db9fd4a4 80 }
daniele 20:3fa3db9fd4a4 81
daniele 20:3fa3db9fd4a4 82 int Socket::close() {
daniele 20:3fa3db9fd4a4 83 if (_ep < 0)
daniele 20:3fa3db9fd4a4 84 return -1;
daniele 20:3fa3db9fd4a4 85
daniele 20:3fa3db9fd4a4 86 picotcp_close(_ep);
daniele 20:3fa3db9fd4a4 87 _ep = NULL;
daniele 20:3fa3db9fd4a4 88
daniele 20:3fa3db9fd4a4 89 return 0;
daniele 20:3fa3db9fd4a4 90 }
daniele 20:3fa3db9fd4a4 91
daniele 20:3fa3db9fd4a4 92 Socket::~Socket() {
daniele 20:3fa3db9fd4a4 93 close(); //Don't want to leak
daniele 20:3fa3db9fd4a4 94 }
daniele 20:3fa3db9fd4a4 95
daniele 20:3fa3db9fd4a4 96 TimeInterval::TimeInterval(unsigned int ms) {
daniele 20:3fa3db9fd4a4 97 _time.tv_sec = ms / 1000;
daniele 20:3fa3db9fd4a4 98 _time.tv_usec = (ms - (_time.tv_sec * 1000)) * 1000;
daniele 20:3fa3db9fd4a4 99 }