skstream
|
00001 /************************************************************************** 00002 FreeSockets - Portable C++ classes for IP(sockets) applications. (v0.3) 00003 Copyright (C) 2000-2001 Rafael Guterres Jeffman 00004 (C) 2003-2006 Alistair Riddoch 00005 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or 00009 (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program; if not, write to the Free Software 00018 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00019 00020 **************************************************************************/ 00021 00029 #ifndef RGJ_FREE_SOCKET_POLL_H_ 00030 #define RGJ_FREE_SOCKET_POLL_H_ 00031 00032 #include <skstream/skstream.h> 00033 00034 #include <map> 00035 00036 class basic_socket_poll 00037 { 00038 public: 00039 basic_socket_poll(); 00040 00041 enum poll_type { 00042 READ = 1 << 0, 00043 WRITE = 1 << 1, 00044 EXCEPT = 1 << 2, 00045 MASK = (1 << 3) - 1 00046 }; 00047 typedef std::map<const basic_socket*,poll_type> socket_map; 00048 00049 int poll(const socket_map& sockets, unsigned long timeout = 0); 00050 00051 poll_type isReady(const basic_socket* soc, poll_type mask = MASK); 00052 poll_type isReady(const socket_map::value_type& val) 00053 {return isReady(val.first, val.second);} 00054 poll_type isReady(const socket_map::iterator& I) 00055 {return isReady(I->first, I->second);} 00056 poll_type isReady(const socket_map::const_iterator& I) 00057 {return isReady(I->first, I->second);} 00058 poll_type isReady(const socket_map::reverse_iterator& I) 00059 {return isReady(I->first, I->second);} 00060 poll_type isReady(const socket_map::const_reverse_iterator& I) 00061 {return isReady(I->first, I->second);} 00062 00063 private: 00064 basic_socket_poll(const basic_socket_poll&); 00065 basic_socket_poll& operator=(const basic_socket_poll&); 00066 00067 fd_set read_, write_, except_; 00068 SOCKET_TYPE maxfd_; 00069 }; 00070 00071 #endif 00072