A new object oriented network api that can be used to replace the one provided by the EthernetInterface library.

Dependents:   NetRelais TCP_Client_Example TCP_Server_Example UDP_Server_Example ... more

Object oriented network interface for the mbed platform

Currently implemented:

  • Address
  • Endpoint
  • UDP Socket
  • TCP Socket
  • Databuffer
  • Select API

It depends on the EthernetInterface for the lwip network stack.

Please do not hesitate to contact me with any remarks, improvements or questions.

The API is also available for unix at GitHub: LibNosa

Examples

Committer:
NegativeBlack
Date:
Sat Nov 15 21:35:31 2014 +0000
Revision:
9:7ac7c29fea3d
Parent:
8:cdee0f2b6ff0
Fixed type warnings in address::formString().

Who changed what in which revision?

UserRevisionLine numberNew contents of line
NegativeBlack 3:d30db8752485 1 /**
NegativeBlack 3:d30db8752485 2 * Copyright (c) 2012, Roy van Dam <roy@vandam-innovations.com>
NegativeBlack 3:d30db8752485 3 * All rights reserved.
NegativeBlack 3:d30db8752485 4 *
NegativeBlack 3:d30db8752485 5 * Redistribution and use in source and binary forms, with or without
NegativeBlack 3:d30db8752485 6 * modification, are permitted provided that the following conditions are met:
NegativeBlack 3:d30db8752485 7 *
NegativeBlack 3:d30db8752485 8 * 1. Redistributions of source code must retain the above copyright notice, this
NegativeBlack 3:d30db8752485 9 * list of conditions and the following disclaimer.
NegativeBlack 3:d30db8752485 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
NegativeBlack 3:d30db8752485 11 * this list of conditions and the following disclaimer in the documentation
NegativeBlack 3:d30db8752485 12 * and/or other materials provided with the distribution.
NegativeBlack 3:d30db8752485 13 *
NegativeBlack 3:d30db8752485 14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
NegativeBlack 3:d30db8752485 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
NegativeBlack 3:d30db8752485 16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
NegativeBlack 3:d30db8752485 17 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
NegativeBlack 3:d30db8752485 18 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
NegativeBlack 3:d30db8752485 19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
NegativeBlack 3:d30db8752485 20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
NegativeBlack 3:d30db8752485 21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
NegativeBlack 3:d30db8752485 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
NegativeBlack 3:d30db8752485 23 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
NegativeBlack 3:d30db8752485 24 */
NegativeBlack 3:d30db8752485 25
NegativeBlack 3:d30db8752485 26 #ifndef _NETWORK_BUFFER_HPP_
NegativeBlack 3:d30db8752485 27 #define _NETWORK_BUFFER_HPP_
NegativeBlack 3:d30db8752485 28
NegativeBlack 4:d854fa394f85 29 #include <stdlib.h>
NegativeBlack 8:cdee0f2b6ff0 30 #include <string>
NegativeBlack 4:d854fa394f85 31 #include <cstring>
NegativeBlack 3:d30db8752485 32
NegativeBlack 4:d854fa394f85 33 namespace network
NegativeBlack 4:d854fa394f85 34 {
NegativeBlack 3:d30db8752485 35 class Buffer
NegativeBlack 3:d30db8752485 36 {
NegativeBlack 8:cdee0f2b6ff0 37 // Members
NegativeBlack 3:d30db8752485 38 protected:
NegativeBlack 4:d854fa394f85 39 void *_memory;
NegativeBlack 8:cdee0f2b6ff0 40
NegativeBlack 4:d854fa394f85 41 size_t _size;
NegativeBlack 4:d854fa394f85 42 size_t _length;
NegativeBlack 8:cdee0f2b6ff0 43
NegativeBlack 8:cdee0f2b6ff0 44 // Methods
NegativeBlack 3:d30db8752485 45 public:
NegativeBlack 3:d30db8752485 46 Buffer();
NegativeBlack 4:d854fa394f85 47 explicit Buffer(const Buffer &other);
NegativeBlack 3:d30db8752485 48 explicit Buffer(const size_t size);
NegativeBlack 8:cdee0f2b6ff0 49 explicit Buffer(const std::string &other);
NegativeBlack 3:d30db8752485 50
NegativeBlack 3:d30db8752485 51 ~Buffer();
NegativeBlack 3:d30db8752485 52
NegativeBlack 4:d854fa394f85 53 int read(void *data, size_t max_length, size_t offset = 0);
NegativeBlack 4:d854fa394f85 54 int write(const void *data, size_t length, size_t offset = 0);
NegativeBlack 7:9796742904fa 55 int flush();
NegativeBlack 4:d854fa394f85 56
NegativeBlack 8:cdee0f2b6ff0 57 void *data(size_t offset = 0);
NegativeBlack 8:cdee0f2b6ff0 58
NegativeBlack 8:cdee0f2b6ff0 59 void length(size_t length);
NegativeBlack 8:cdee0f2b6ff0 60 size_t length();
NegativeBlack 3:d30db8752485 61
NegativeBlack 4:d854fa394f85 62 size_t size();
NegativeBlack 4:d854fa394f85 63 size_t free();
NegativeBlack 3:d30db8752485 64
NegativeBlack 4:d854fa394f85 65 Buffer &operator=(const Buffer &other);
NegativeBlack 8:cdee0f2b6ff0 66 Buffer &operator=(const std::string &message);
NegativeBlack 4:d854fa394f85 67
NegativeBlack 4:d854fa394f85 68 protected:
NegativeBlack 4:d854fa394f85 69 int _memory_allocate(size_t size);
NegativeBlack 4:d854fa394f85 70 void _memory_free();
NegativeBlack 4:d854fa394f85 71
NegativeBlack 3:d30db8752485 72 };
NegativeBlack 3:d30db8752485 73
NegativeBlack 3:d30db8752485 74 } // namespace network
NegativeBlack 3:d30db8752485 75
NegativeBlack 3:d30db8752485 76 #endif // _NETWORK_UDP_SOCKET_HPP_