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:
Thu Sep 27 09:31:40 2012 +0000
Revision:
8:cdee0f2b6ff0
Parent:
5:4b6bc10437cb
Fixed binding to the new Ethernet LWIP api

Who changed what in which revision?

UserRevisionLine numberNew contents of line
NegativeBlack 5:4b6bc10437cb 1 /**
NegativeBlack 5:4b6bc10437cb 2 * Copyright (c) 2012, Roy van Dam <roy@vandam-innovations.com>
NegativeBlack 5:4b6bc10437cb 3 * All rights reserved.
NegativeBlack 5:4b6bc10437cb 4 *
NegativeBlack 5:4b6bc10437cb 5 * Redistribution and use in source and binary forms, with or without
NegativeBlack 5:4b6bc10437cb 6 * modification, are permitted provided that the following conditions are met:
NegativeBlack 5:4b6bc10437cb 7 *
NegativeBlack 5:4b6bc10437cb 8 * 1. Redistributions of source code must retain the above copyright notice, this
NegativeBlack 5:4b6bc10437cb 9 * list of conditions and the following disclaimer.
NegativeBlack 5:4b6bc10437cb 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
NegativeBlack 5:4b6bc10437cb 11 * this list of conditions and the following disclaimer in the documentation
NegativeBlack 5:4b6bc10437cb 12 * and/or other materials provided with the distribution.
NegativeBlack 5:4b6bc10437cb 13 *
NegativeBlack 5:4b6bc10437cb 14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
NegativeBlack 5:4b6bc10437cb 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
NegativeBlack 5:4b6bc10437cb 16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
NegativeBlack 5:4b6bc10437cb 17 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
NegativeBlack 5:4b6bc10437cb 18 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
NegativeBlack 5:4b6bc10437cb 19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
NegativeBlack 5:4b6bc10437cb 20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
NegativeBlack 5:4b6bc10437cb 21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
NegativeBlack 5:4b6bc10437cb 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
NegativeBlack 5:4b6bc10437cb 23 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
NegativeBlack 5:4b6bc10437cb 24 */
NegativeBlack 5:4b6bc10437cb 25
NegativeBlack 5:4b6bc10437cb 26 #ifndef _NETWORK_SELECT_HPP_
NegativeBlack 5:4b6bc10437cb 27 #define _NETWORK_SELECT_HPP_
NegativeBlack 5:4b6bc10437cb 28
NegativeBlack 5:4b6bc10437cb 29 #include <vector>
NegativeBlack 5:4b6bc10437cb 30
NegativeBlack 5:4b6bc10437cb 31 #include "socket.hpp"
NegativeBlack 5:4b6bc10437cb 32
NegativeBlack 8:cdee0f2b6ff0 33 #include "lwip/sockets.h"
NegativeBlack 8:cdee0f2b6ff0 34 #include "lwip/netdb.h"
NegativeBlack 8:cdee0f2b6ff0 35
NegativeBlack 5:4b6bc10437cb 36 namespace network
NegativeBlack 5:4b6bc10437cb 37 {
NegativeBlack 5:4b6bc10437cb 38 class Select
NegativeBlack 5:4b6bc10437cb 39 {
NegativeBlack 5:4b6bc10437cb 40 public:
NegativeBlack 5:4b6bc10437cb 41 typedef std::vector<Socket *> SocketList;
NegativeBlack 5:4b6bc10437cb 42
NegativeBlack 5:4b6bc10437cb 43 enum Mode {
NegativeBlack 5:4b6bc10437cb 44 Read = 0,
NegativeBlack 5:4b6bc10437cb 45 Write = 1,
NegativeBlack 5:4b6bc10437cb 46 ReadWrite = 2
NegativeBlack 5:4b6bc10437cb 47 };
NegativeBlack 5:4b6bc10437cb 48
NegativeBlack 5:4b6bc10437cb 49 protected:
NegativeBlack 5:4b6bc10437cb 50 SocketList _write_list;
NegativeBlack 5:4b6bc10437cb 51 SocketList _read_list;
NegativeBlack 5:4b6bc10437cb 52
NegativeBlack 5:4b6bc10437cb 53 SocketList::iterator _write_list_iterator;
NegativeBlack 5:4b6bc10437cb 54 SocketList::iterator _read_list_iterator;
NegativeBlack 5:4b6bc10437cb 55
NegativeBlack 5:4b6bc10437cb 56 fd_set _write_set;
NegativeBlack 5:4b6bc10437cb 57 fd_set _read_set;
NegativeBlack 5:4b6bc10437cb 58
NegativeBlack 5:4b6bc10437cb 59 public:
NegativeBlack 5:4b6bc10437cb 60 ~Select();
NegativeBlack 5:4b6bc10437cb 61
NegativeBlack 5:4b6bc10437cb 62 int wait(int timeout = 0);
NegativeBlack 5:4b6bc10437cb 63 void clear();
NegativeBlack 5:4b6bc10437cb 64
NegativeBlack 5:4b6bc10437cb 65 void set(Socket *socket, enum Mode mode);
NegativeBlack 5:4b6bc10437cb 66 void unset(Socket *socket, enum Mode mode);
NegativeBlack 5:4b6bc10437cb 67
NegativeBlack 5:4b6bc10437cb 68 Socket *getWritable();
NegativeBlack 5:4b6bc10437cb 69 Socket *getReadable();
NegativeBlack 5:4b6bc10437cb 70
NegativeBlack 5:4b6bc10437cb 71 protected:
NegativeBlack 5:4b6bc10437cb 72 SocketList::iterator _inWriteList(Socket *socket);
NegativeBlack 5:4b6bc10437cb 73 SocketList::iterator _inReadList(Socket *socket);
NegativeBlack 5:4b6bc10437cb 74 };
NegativeBlack 5:4b6bc10437cb 75
NegativeBlack 5:4b6bc10437cb 76 } // namespace network
NegativeBlack 5:4b6bc10437cb 77
NegativeBlack 5:4b6bc10437cb 78 #endif // _NETWORK_SELECT_HPP_