Collage  1.0.1
Object-Oriented C++ Network Library
connectionSet.h
1 
2 /* Copyright (c) 2005-2012, Stefan Eilemann <eile@equalizergraphics.com>
3  *
4  * This file is part of Collage <https://github.com/Eyescale/Collage>
5  *
6  * This library is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Lesser General Public License version 2.1 as published
8  * by the Free Software Foundation.
9  *
10  * This library is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13  * details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with this library; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 #ifndef CO_CONNECTION_SET_H
21 #define CO_CONNECTION_SET_H
22 
23 #include <co/api.h>
24 #include <co/types.h>
25 #include <lunchbox/thread.h> // for LB_TS_VAR
26 
27 namespace co
28 {
29 namespace detail { class ConnectionSet; }
30 
33  {
34  public:
35  enum Event
36  {
37  EVENT_NONE = 0,
46  EVENT_ALL
47  };
48 
50  CO_API ConnectionSet();
51 
53  CO_API ~ConnectionSet();
54 
58  CO_API void addConnection( ConnectionPtr connection );
59 
61  CO_API bool removeConnection( ConnectionPtr connection );
62 
64  CO_API size_t getSize() const;
65 
70  CO_API bool isEmpty() const;
71 
73  CO_API const Connections& getConnections() const;
75 
90  CO_API Event select( const uint32_t timeout = LB_TIMEOUT_INDEFINITE );
91 
93  CO_API void interrupt();
94 
99  CO_API int getError() const;
100 
105  CO_API ConnectionPtr getConnection();
106 
108  void setDirty();
110 
111  private:
112  detail::ConnectionSet* const _impl;
113 
114  void _clear();
115  bool _setupFDSet();
116  bool _buildFDSet();
117 
118  Event _getSelectResult( const uint32_t index );
119  LB_TS_VAR( _selectThread );
120  };
121 
123  CO_API std::ostream& operator << ( std::ostream&, const ConnectionSet& );
124 
126  CO_API std::ostream& operator << (std::ostream&,const ConnectionSet::Event);
127 }
128 
129 #endif // CO_CONNECTION_SET_H
The selection request timed out.
Definition: connectionSet.h:41
No event has occurred.
Definition: connectionSet.h:37
std::vector< ConnectionPtr > Connections
A vector of ConnectionPtr&#39;s.
Definition: types.h:116
CO_API bool isEmpty() const
CO_API int getError() const
CO_API void addConnection(ConnectionPtr connection)
Add the connection to this set.
CO_API void interrupt()
Interrupt the current or next select call.
CO_API ConnectionSet()
Create a new connection set.
CO_API bool removeConnection(ConnectionPtr connection)
Remove the connection from this set.
Event
&lt; Event types for select()
Definition: connectionSet.h:35
An error occurred during select()
Definition: connectionSet.h:44
CO_API ConnectionPtr getConnection()
Handles events on a set of connections.
Definition: connectionSet.h:32
ConnectionSet::interrupt was called.
Definition: connectionSet.h:42
CO_API ~ConnectionSet()
Destruct this connection set.
A connection is not select&#39;able.
Definition: connectionSet.h:45
CO_API Event select(const uint32_t timeout=LB_TIMEOUT_INDEFINITE)
Select a Connection which is ready for I/O.
A connection signaled an error.
Definition: connectionSet.h:43
CO_API size_t getSize() const
Remove all connections from this set.
lunchbox::RefPtr< Connection > ConnectionPtr
A reference pointer for Connection pointers.
Definition: types.h:88