ENUt
|
00001 /* 00002 00003 This file is a part of ENUt, a library containing network 00004 programming utilities. 00005 00006 Copyright (C) 2006-2008 Hasselt University - Expertise Centre for 00007 Digital Media (EDM) (http://www.edm.uhasselt.be) 00008 00009 This library is free software; you can redistribute it and/or 00010 modify it under the terms of the GNU Lesser General Public 00011 License as published by the Free Software Foundation; either 00012 version 2.1 of the License, or (at your option) any later version. 00013 00014 This library is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00017 Lesser General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public 00020 License along with this library; if not, write to the Free Software 00021 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 00022 USA 00023 00024 */ 00025 00030 #ifndef NUT_SOCKETWAITER_H 00031 00032 #define NUT_SOCKETWAITER_H 00033 00034 #include "nutconfig.h" 00035 #include <errut/errorbase.h> 00036 #include <list> 00037 00038 #ifdef NUTCONFIG_SUPPORT_POLL 00039 #include <sys/poll.h> 00040 #include <vector> 00041 #endif // NUTCONFIG_SUPPORT_POLL 00042 00043 namespace nut 00044 { 00045 00046 class Socket; 00047 00051 class ENUT_IMPORTEXPORT SocketWaiter : public errut::ErrorBase 00052 { 00053 public: 00054 SocketWaiter(); 00055 SocketWaiter(const std::string &objName); 00056 ~SocketWaiter(); 00057 00059 void addSocket(Socket &s) { m_sockets.push_back(&s); } 00060 00062 void removeSocket(Socket &s) { m_sockets.remove(&s); } 00063 00065 void clear() { m_sockets.clear(); } 00066 00074 bool wait(int seconds = -1, int microSeconds = -1); 00075 private: 00076 // make sure we can't copy a socket waiter 00077 SocketWaiter(const SocketWaiter &s) : errut::ErrorBase(s) { } 00078 SocketWaiter &operator=(const SocketWaiter &s) { return *this; } 00079 00080 std::string getSocketErrorString(); 00081 std::list<Socket *> m_sockets; 00082 #ifdef NUTCONFIG_SUPPORT_POLL 00083 std::vector<struct pollfd> m_pollInfo; 00084 #endif // NUTCONFIG_SUPPORT_POLL 00085 }; 00086 00087 } // end namespace 00088 00089 #endif // NUT_SOCKETWAITER_H 00090