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:
Fri May 31 11:34:03 2013 +0000
Revision:
5:445d2fc04784
Child:
18:c6f67fcfc62a
Integrated mbed friendly sockets

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tass 5:445d2fc04784 1 /*
tass 5:445d2fc04784 2 *
tass 5:445d2fc04784 3 * PicoTCP Socket interface for mbed.
tass 5:445d2fc04784 4 * Copyright (C) 2013 TASS Belgium NV
tass 5:445d2fc04784 5 *
tass 5:445d2fc04784 6 * Released under GPL v2
tass 5:445d2fc04784 7 *
tass 5:445d2fc04784 8 * Other licensing models might apply at the sole discretion of the copyright holders.
tass 5:445d2fc04784 9 *
tass 5:445d2fc04784 10 *
tass 5:445d2fc04784 11 * This software is based on the mbed.org EthernetInterface implementation:
tass 5:445d2fc04784 12 * Copyright (C) 2012 mbed.org, MIT License
tass 5:445d2fc04784 13 *
tass 5:445d2fc04784 14 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
tass 5:445d2fc04784 15 * and associated documentation files (the "Software"), to deal in the Software without restriction,
tass 5:445d2fc04784 16 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
tass 5:445d2fc04784 17 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
tass 5:445d2fc04784 18 * furnished to do so, subject to the following conditions:
tass 5:445d2fc04784 19 *
tass 5:445d2fc04784 20 * The above copyright notice and this permission notice shall be included in all copies or
tass 5:445d2fc04784 21 * substantial portions of the Software.
tass 5:445d2fc04784 22 *
tass 5:445d2fc04784 23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
tass 5:445d2fc04784 24 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
tass 5:445d2fc04784 25 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
tass 5:445d2fc04784 26 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
tass 5:445d2fc04784 27 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
tass 5:445d2fc04784 28 */
tass 5:445d2fc04784 29
tass 5:445d2fc04784 30 #ifndef SOCKET_H_
tass 5:445d2fc04784 31 #define SOCKET_H_
tass 5:445d2fc04784 32
tass 5:445d2fc04784 33 #include "pico_bsd_layer.h"
tass 5:445d2fc04784 34
tass 5:445d2fc04784 35 #ifdef __cplusplus
tass 5:445d2fc04784 36 extern "C" {
tass 5:445d2fc04784 37 #endif
tass 5:445d2fc04784 38 #include "pico_dns_client.h"
tass 5:445d2fc04784 39 #ifdef __cplusplus
tass 5:445d2fc04784 40 }
tass 5:445d2fc04784 41 #endif
tass 5:445d2fc04784 42 /* DNS (Keep?)
tass 5:445d2fc04784 43
tass 5:445d2fc04784 44
tass 5:445d2fc04784 45 inline struct hostent *gethostbyname(const char *name) {
tass 5:445d2fc04784 46 return picotcp_gethostbyname(name);
tass 5:445d2fc04784 47 }
tass 5:445d2fc04784 48
tass 5:445d2fc04784 49 inline int gethostbyname_r(const char *name, struct hostent *ret, char *buf, size_t buflen, struct hostent **result, int *h_errnop) {
tass 5:445d2fc04784 50 return picotcp_gethostbyname_r(name, ret, buf, buflen, result, h_errnop);
tass 5:445d2fc04784 51 }
tass 5:445d2fc04784 52 */
tass 5:445d2fc04784 53
tass 5:445d2fc04784 54 class TimeInterval;
tass 5:445d2fc04784 55
tass 5:445d2fc04784 56 /** Socket file descriptor and select wrapper
tass 5:445d2fc04784 57 */
tass 5:445d2fc04784 58 class Socket {
tass 5:445d2fc04784 59 public:
tass 5:445d2fc04784 60 /** Socket
tass 5:445d2fc04784 61 */
tass 5:445d2fc04784 62 Socket();
tass 5:445d2fc04784 63
tass 5:445d2fc04784 64 /** Set blocking or non-blocking mode of the socket and a timeout on
tass 5:445d2fc04784 65 blocking socket operations
tass 5:445d2fc04784 66 \param blocking true for blocking mode, false for non-blocking mode.
tass 5:445d2fc04784 67 \param timeout timeout in ms [Default: (1500)ms].
tass 5:445d2fc04784 68 */
tass 5:445d2fc04784 69 void set_blocking(bool blocking, unsigned int timeout=1500);
tass 5:445d2fc04784 70
tass 5:445d2fc04784 71 /** Set socket options
tass 5:445d2fc04784 72 \param level stack level (see: lwip/sockets.h)
tass 5:445d2fc04784 73 \param optname option ID
tass 5:445d2fc04784 74 \param optval option value
tass 5:445d2fc04784 75 \param socklen_t length of the option value
tass 5:445d2fc04784 76 \return 0 on success, -1 on failure
tass 5:445d2fc04784 77 */
tass 5:445d2fc04784 78 int set_option(int level, int optname, const void *optval, socklen_t optlen);
tass 5:445d2fc04784 79
tass 5:445d2fc04784 80 /** Get socket options
tass 5:445d2fc04784 81 \param level stack level (see: lwip/sockets.h)
tass 5:445d2fc04784 82 \param optname option ID
tass 5:445d2fc04784 83 \param optval buffer pointer where to write the option value
tass 5:445d2fc04784 84 \param socklen_t length of the option value
tass 5:445d2fc04784 85 \return 0 on success, -1 on failure
tass 5:445d2fc04784 86 */
tass 5:445d2fc04784 87 int get_option(int level, int optname, void *optval, socklen_t *optlen);
tass 5:445d2fc04784 88
tass 5:445d2fc04784 89 /** Close the socket file descriptor
tass 5:445d2fc04784 90 */
tass 5:445d2fc04784 91 int close();
tass 5:445d2fc04784 92
tass 5:445d2fc04784 93 ~Socket();
tass 5:445d2fc04784 94
tass 5:445d2fc04784 95 protected:
tass 5:445d2fc04784 96 int _sock_fd;
tass 5:445d2fc04784 97 int init_socket(int type);
tass 5:445d2fc04784 98
tass 5:445d2fc04784 99 int wait_readable(TimeInterval& timeout);
tass 5:445d2fc04784 100 int wait_writable(TimeInterval& timeout);
tass 5:445d2fc04784 101
tass 5:445d2fc04784 102 bool _blocking;
tass 5:445d2fc04784 103 unsigned int _timeout;
tass 5:445d2fc04784 104
tass 5:445d2fc04784 105 private:
tass 5:445d2fc04784 106 int select(struct timeval *timeout, bool read, bool write);
tass 5:445d2fc04784 107 };
tass 5:445d2fc04784 108
tass 5:445d2fc04784 109 /** Time interval class used to specify timeouts
tass 5:445d2fc04784 110 */
tass 5:445d2fc04784 111 class TimeInterval {
tass 5:445d2fc04784 112 friend class Socket;
tass 5:445d2fc04784 113
tass 5:445d2fc04784 114 public:
tass 5:445d2fc04784 115 /** Time Interval
tass 5:445d2fc04784 116 \param ms time interval expressed in milliseconds
tass 5:445d2fc04784 117 */
tass 5:445d2fc04784 118 TimeInterval(unsigned int ms);
tass 5:445d2fc04784 119
tass 5:445d2fc04784 120 private:
tass 5:445d2fc04784 121 struct timeval _time;
tass 5:445d2fc04784 122 };
tass 5:445d2fc04784 123
tass 5:445d2fc04784 124
tass 5:445d2fc04784 125 inline struct hostent *gethostbyname(const char *name) {
tass 5:445d2fc04784 126 return picotcp_gethostbyname(name);
tass 5:445d2fc04784 127
tass 5:445d2fc04784 128 }
tass 5:445d2fc04784 129 /* DNS
tass 5:445d2fc04784 130 inline int gethostbyname_r(const char *name, struct hostent *ret, char *buf, size_t buflen, struct hostent **result, int *h_errnop) {
tass 5:445d2fc04784 131 return picotcp_gethostbyname_r(name, ret, buf, buflen, result, h_errnop);
tass 5:445d2fc04784 132 }*/
tass 5:445d2fc04784 133 #endif /* SOCKET_H_ */