Collage  1.7.0
High-performance C++ library for developing object-oriented distributed applications.
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 <boost/noncopyable.hpp>
24 #include <co/api.h>
25 #include <co/types.h>
26 #include <lunchbox/thread.h> // for LB_TS_VAR
27 
28 namespace co
29 {
30 namespace detail
31 {
32 class ConnectionSet;
33 }
34 
36 class ConnectionSet : public boost::noncopyable
37 {
38 public:
39  enum Event
40  {
41  EVENT_NONE = 0,
50  EVENT_ALL
51  };
52 
54  CO_API ConnectionSet();
55 
57  CO_API ~ConnectionSet();
58 
62  CO_API void addConnection(ConnectionPtr connection);
63 
65  CO_API bool removeConnection(ConnectionPtr connection);
66 
68  CO_API size_t getSize() const;
69 
74  CO_API bool isEmpty() const;
75 
77  CO_API const Connections& getConnections() const;
79 
93  CO_API Event select(const uint32_t timeout = LB_TIMEOUT_INDEFINITE);
94 
96  CO_API void interrupt();
97 
102  CO_API int getError() const;
103 
108  CO_API ConnectionPtr getConnection();
109 
111  void setDirty();
113 
114 private:
115  detail::ConnectionSet* const _impl;
116 
117  void _clear();
118  bool _setupFDSet();
119  bool _buildFDSet();
120 
121  Event _getSelectResult(const uint32_t index);
122  Event _parseSelect(const uint32_t index);
123  LB_TS_VAR(_selectThread);
124 };
125 
127 CO_API std::ostream& operator<<(std::ostream&, const ConnectionSet&);
128 
130 CO_API std::ostream& operator<<(std::ostream&, const ConnectionSet::Event);
131 }
132 
133 #endif // CO_CONNECTION_SET_H
Defines export visibility macros for library Collage.
Event
< Event types for select()
Definition: connectionSet.h:39
ConnectionSet::interrupt was called.
Definition: connectionSet.h:46
The selection request timed out.
Definition: connectionSet.h:45
A connection is not select&#39;able.
Definition: connectionSet.h:49
Object-oriented network library.
Definition: barrier.h:27
An error occurred during select()
Definition: connectionSet.h:48
A connection signaled an error.
Definition: connectionSet.h:47
Handles events on a set of connections.
Definition: connectionSet.h:36
lunchbox::RefPtr< Connection > ConnectionPtr
A reference pointer for Connection pointers.
Definition: types.h:93
std::vector< ConnectionPtr > Connections
A vector of ConnectionPtr&#39;s.
Definition: types.h:124