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:
Sun Jun 16 20:27:04 2013 +0000
Revision:
30:ee825ae4852c
Parent:
28:394d88a116b2
Child:
44:ffd9a11d4f95
fixed return address in accept()

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 "TCPSocketServer.h"
daniele 20:3fa3db9fd4a4 30 #include "wrapper.h"
daniele 20:3fa3db9fd4a4 31
daniele 20:3fa3db9fd4a4 32 #include <cstring>
daniele 20:3fa3db9fd4a4 33
daniele 20:3fa3db9fd4a4 34 using std::memset;
daniele 20:3fa3db9fd4a4 35 using std::memcpy;
daniele 20:3fa3db9fd4a4 36
daniele 20:3fa3db9fd4a4 37 TCPSocketServer::TCPSocketServer() {
daniele 20:3fa3db9fd4a4 38
daniele 20:3fa3db9fd4a4 39 }
daniele 20:3fa3db9fd4a4 40
daniele 20:3fa3db9fd4a4 41 int TCPSocketServer::bind(int port) {
daniele 20:3fa3db9fd4a4 42 if (init_socket(SOCK_STREAM) < 0)
daniele 20:3fa3db9fd4a4 43 return -1;
daniele 20:3fa3db9fd4a4 44
daniele 20:3fa3db9fd4a4 45 struct sockaddr_in localHost;
daniele 20:3fa3db9fd4a4 46 memset(&localHost, 0, sizeof(localHost));
daniele 20:3fa3db9fd4a4 47
daniele 20:3fa3db9fd4a4 48 localHost.sin_family = AF_INET;
daniele 20:3fa3db9fd4a4 49 localHost.sin_port = short_be(port);
daniele 20:3fa3db9fd4a4 50 localHost.sin_addr.s_addr = INADDR_ANY;
daniele 20:3fa3db9fd4a4 51
daniele 20:3fa3db9fd4a4 52 if (picotcp_bind(_ep, (struct sockaddr *) &localHost, sizeof(localHost)) < 0) {
daniele 20:3fa3db9fd4a4 53 close();
daniele 20:3fa3db9fd4a4 54 return -1;
daniele 20:3fa3db9fd4a4 55 }
daniele 20:3fa3db9fd4a4 56
daniele 20:3fa3db9fd4a4 57 return 0;
daniele 20:3fa3db9fd4a4 58 }
daniele 20:3fa3db9fd4a4 59
daniele 20:3fa3db9fd4a4 60 int TCPSocketServer::listen(int max) {
daniele 20:3fa3db9fd4a4 61 if (_ep < 0)
daniele 20:3fa3db9fd4a4 62 return -1;
daniele 20:3fa3db9fd4a4 63
daniele 20:3fa3db9fd4a4 64 if (picotcp_listen(_ep, max) < 0) {
daniele 20:3fa3db9fd4a4 65 close();
daniele 20:3fa3db9fd4a4 66 return -1;
daniele 20:3fa3db9fd4a4 67 }
daniele 20:3fa3db9fd4a4 68
daniele 20:3fa3db9fd4a4 69 return 0;
daniele 20:3fa3db9fd4a4 70 }
daniele 20:3fa3db9fd4a4 71
daniele 20:3fa3db9fd4a4 72 int TCPSocketServer::accept(TCPSocketConnection& connection) {
daniele 30:ee825ae4852c 73 char address[80];
daniele 20:3fa3db9fd4a4 74 if (_ep < 0)
daniele 20:3fa3db9fd4a4 75 return -1;
daniele 20:3fa3db9fd4a4 76
daniele 20:3fa3db9fd4a4 77 if (!_blocking) {
daniele 20:3fa3db9fd4a4 78 printf("Not blocking...\n");
daniele 20:3fa3db9fd4a4 79 TimeInterval timeout(_timeout);
daniele 20:3fa3db9fd4a4 80 if (wait_readable(timeout) != 0)
daniele 20:3fa3db9fd4a4 81 return -1;
daniele 20:3fa3db9fd4a4 82 }
daniele 20:3fa3db9fd4a4 83 connection.reset_address();
daniele 20:3fa3db9fd4a4 84 socklen_t newSockRemoteHostLen = sizeof(connection._remoteHost);
daniele 20:3fa3db9fd4a4 85 connection._ep = picotcp_accept(_ep, (struct sockaddr*) &connection._remoteHost, &newSockRemoteHostLen);
daniele 26:dc3e7f96338f 86 if (!connection._ep) {
daniele 20:3fa3db9fd4a4 87 return -1; //Accept failed
daniele 20:3fa3db9fd4a4 88 }
daniele 20:3fa3db9fd4a4 89 connection.set_blocking(true,1500);
daniele 20:3fa3db9fd4a4 90 connection._is_connected = true;
daniele 28:394d88a116b2 91 pico_ipv4_to_string(address, connection._remoteHost.sin_addr.s_addr);
daniele 28:394d88a116b2 92 connection.set_address(address, connection._remoteHost.sin_port);
daniele 20:3fa3db9fd4a4 93 return 0;
daniele 20:3fa3db9fd4a4 94 }