Collage  1.1.2
High-performance C++ library for developing object-oriented distributed applications.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
connectionSet.h
1 
2 /* Copyright (c) 2005-2014, 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 #include <boost/noncopyable.hpp>
27 
28 namespace co
29 {
30 namespace detail { class ConnectionSet; }
31 
33 class ConnectionSet : public boost::noncopyable
34 {
35 public:
36  enum Event
37  {
38  EVENT_NONE = 0,
47  EVENT_ALL
48  };
49 
51  CO_API ConnectionSet();
52 
54  CO_API ~ConnectionSet();
55 
59  CO_API void addConnection( ConnectionPtr connection );
60 
62  CO_API bool removeConnection( ConnectionPtr connection );
63 
65  CO_API size_t getSize() const;
66 
71  CO_API bool isEmpty() const;
72 
74  CO_API const Connections& getConnections() const;
76 
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  Event _parseSelect( const uint32_t index );
120  LB_TS_VAR( _selectThread );
121 };
122 
124 CO_API std::ostream& operator << ( std::ostream&, const ConnectionSet& );
125 
127 CO_API std::ostream& operator << (std::ostream&,const ConnectionSet::Event);
128 }
129 
130 #endif // CO_CONNECTION_SET_H
Defines export visibility macros for Collage.
CO_API ~ConnectionSet()
Destruct this connection set.
std::vector< ConnectionPtr > Connections
A vector of ConnectionPtr's.
Definition: types.h:125
Event
< Event types for select()
Definition: connectionSet.h:36
CO_API int getError() const
ConnectionSet::interrupt was called.
Definition: connectionSet.h:43
CO_API size_t getSize() const
CO_API bool isEmpty() const
The selection request timed out.
Definition: connectionSet.h:42
A connection is not select'able.
Definition: connectionSet.h:46
CO_API void interrupt()
Interrupt the current or next select call.
CO_API ConnectionPtr getConnection()
CO_API bool removeConnection(ConnectionPtr connection)
Remove the connection from this set.
No event has occurred.
Definition: connectionSet.h:38
An error occurred during select()
Definition: connectionSet.h:45
A connection signaled an error.
Definition: connectionSet.h:44
CO_API Event select(const uint32_t timeout=LB_TIMEOUT_INDEFINITE)
Select a Connection which is ready for I/O.
CO_API void addConnection(ConnectionPtr connection)
Add the connection to this set.
CO_API ConnectionSet()
Create a new connection set.
Handles events on a set of connections.
Definition: connectionSet.h:33
lunchbox::RefPtr< Connection > ConnectionPtr
A reference pointer for Connection pointers.
Definition: types.h:94