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:
Wed Jul 18 19:43:12 2012 +0000
Revision:
7:9796742904fa
Parent:
4:d854fa394f85
Child:
8:cdee0f2b6ff0
Small update, added Buffer::flush() method.

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 4:d854fa394f85 30 #include <cstring>
NegativeBlack 3:d30db8752485 31
NegativeBlack 4:d854fa394f85 32 namespace network
NegativeBlack 4:d854fa394f85 33 {
NegativeBlack 3:d30db8752485 34 class Buffer
NegativeBlack 3:d30db8752485 35 {
NegativeBlack 3:d30db8752485 36 protected:
NegativeBlack 4:d854fa394f85 37 void *_memory;
NegativeBlack 4:d854fa394f85 38 size_t _size;
NegativeBlack 4:d854fa394f85 39 size_t _length;
NegativeBlack 3:d30db8752485 40
NegativeBlack 3:d30db8752485 41 public:
NegativeBlack 3:d30db8752485 42 Buffer();
NegativeBlack 4:d854fa394f85 43 explicit Buffer(const Buffer &other);
NegativeBlack 3:d30db8752485 44 explicit Buffer(const size_t size);
NegativeBlack 3:d30db8752485 45
NegativeBlack 3:d30db8752485 46 ~Buffer();
NegativeBlack 3:d30db8752485 47
NegativeBlack 4:d854fa394f85 48 int read(void *data, size_t max_length, size_t offset = 0);
NegativeBlack 4:d854fa394f85 49 int write(const void *data, size_t length, size_t offset = 0);
NegativeBlack 7:9796742904fa 50 int flush();
NegativeBlack 4:d854fa394f85 51
NegativeBlack 4:d854fa394f85 52 void *pointer(size_t offset = 0);
NegativeBlack 4:d854fa394f85 53 void setLength(size_t length);
NegativeBlack 3:d30db8752485 54
NegativeBlack 4:d854fa394f85 55 size_t size();
NegativeBlack 4:d854fa394f85 56 size_t length();
NegativeBlack 4:d854fa394f85 57 size_t free();
NegativeBlack 3:d30db8752485 58
NegativeBlack 4:d854fa394f85 59 Buffer &operator=(const Buffer &other);
NegativeBlack 4:d854fa394f85 60
NegativeBlack 4:d854fa394f85 61 protected:
NegativeBlack 4:d854fa394f85 62 int _memory_allocate(size_t size);
NegativeBlack 4:d854fa394f85 63 void _memory_free();
NegativeBlack 4:d854fa394f85 64
NegativeBlack 3:d30db8752485 65 };
NegativeBlack 3:d30db8752485 66
NegativeBlack 3:d30db8752485 67 } // namespace network
NegativeBlack 3:d30db8752485 68
NegativeBlack 3:d30db8752485 69 #endif // _NETWORK_UDP_SOCKET_HPP_