skstream
skpoll.h
1 /**************************************************************************
2  FreeSockets - Portable C++ classes for IP(sockets) applications. (v0.3)
3  Copyright (C) 2000-2001 Rafael Guterres Jeffman
4  (C) 2003-2006 Alistair Riddoch
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 
20 **************************************************************************/
21 
29 #ifndef RGJ_FREE_SOCKET_POLL_H_
30 #define RGJ_FREE_SOCKET_POLL_H_
31 
32 #include <skstream/skstream.h>
33 
34 #include <map>
35 
37 {
38 public:
40 
41  enum poll_type {
42  READ = 1 << 0,
43  WRITE = 1 << 1,
44  EXCEPT = 1 << 2,
45  MASK = (1 << 3) - 1
46  };
47  typedef std::map<const basic_socket*,poll_type> socket_map;
48 
49  int poll(const socket_map& sockets, unsigned long timeout = 0);
50 
51  poll_type isReady(const basic_socket* soc, poll_type mask = MASK);
52  poll_type isReady(const socket_map::value_type& val)
53  {return isReady(val.first, val.second);}
54  poll_type isReady(const socket_map::iterator& I)
55  {return isReady(I->first, I->second);}
56  poll_type isReady(const socket_map::const_iterator& I)
57  {return isReady(I->first, I->second);}
58  poll_type isReady(const socket_map::reverse_iterator& I)
59  {return isReady(I->first, I->second);}
60  poll_type isReady(const socket_map::const_reverse_iterator& I)
61  {return isReady(I->first, I->second);}
62 
63 private:
65  basic_socket_poll& operator=(const basic_socket_poll&);
66 
67  fd_set read_, write_, except_;
68  SOCKET_TYPE maxfd_;
69 };
70 
71 #endif
72 
Base class for anything that encapsulates a socket.
Definition: sksocket.h:79
Definition: skpoll.h:36
basic_socket_poll()
Definition: skpoll.cpp:36