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
select.hpp
00001 /** 00002 * Copyright (c) 2012, Roy van Dam <roy@vandam-innovations.com> 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions are met: 00007 * 00008 * 1. Redistributions of source code must retain the above copyright notice, this 00009 * list of conditions and the following disclaimer. 00010 * 2. Redistributions in binary form must reproduce the above copyright notice, 00011 * this list of conditions and the following disclaimer in the documentation 00012 * and/or other materials provided with the distribution. 00013 * 00014 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 00015 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00016 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00017 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 00018 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00019 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00020 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00021 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00022 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00023 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00024 */ 00025 00026 #ifndef _NETWORK_SELECT_HPP_ 00027 #define _NETWORK_SELECT_HPP_ 00028 00029 #include <vector> 00030 00031 #include "socket.hpp" 00032 00033 #include "lwip/sockets.h" 00034 #include "lwip/netdb.h" 00035 00036 namespace network 00037 { 00038 class Select 00039 { 00040 public: 00041 typedef std::vector<Socket *> SocketList; 00042 00043 enum Mode { 00044 Read = 0, 00045 Write = 1, 00046 ReadWrite = 2 00047 }; 00048 00049 protected: 00050 SocketList _write_list; 00051 SocketList _read_list; 00052 00053 SocketList::iterator _write_list_iterator; 00054 SocketList::iterator _read_list_iterator; 00055 00056 fd_set _write_set; 00057 fd_set _read_set; 00058 00059 public: 00060 ~Select(); 00061 00062 int wait(int timeout = 0); 00063 void clear(); 00064 00065 void set(Socket *socket, enum Mode mode); 00066 void unset(Socket *socket, enum Mode mode); 00067 00068 Socket *getWritable(); 00069 Socket *getReadable(); 00070 00071 protected: 00072 SocketList::iterator _inWriteList(Socket *socket); 00073 SocketList::iterator _inReadList(Socket *socket); 00074 }; 00075 00076 } // namespace network 00077 00078 #endif // _NETWORK_SELECT_HPP_
Generated on Tue Jul 12 2022 12:58:20 by 1.7.2