Open Lighting Architecture  0.9.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TCPConnector.h
1 /*
2  * This library is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU Lesser General Public
4  * License as published by the Free Software Foundation; either
5  * version 2.1 of the License, or (at your option) any later version.
6  *
7  * This library is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10  * Lesser General Public License for more details.
11  *
12  * You should have received a copy of the GNU Lesser General Public
13  * License along with this library; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15  *
16  * TCPConnector.h.h
17  * Copyright (C) 2012 Simon Newton
18  */
19 
20 #ifndef INCLUDE_OLA_NETWORK_TCPCONNECTOR_H_
21 #define INCLUDE_OLA_NETWORK_TCPCONNECTOR_H_
22 
23 #include <ola/Callback.h>
24 #include <ola/Clock.h>
25 #include <ola/base/Macro.h>
26 #include <ola/io/Descriptor.h>
27 #include <ola/io/SelectServerInterface.h>
30 #include <ola/network/TCPSocket.h>
31 #include <set>
32 #include <vector>
33 
34 namespace ola {
35 namespace network {
36 
40 class TCPConnector {
41  public:
49 
55  typedef const void* TCPConnectionID;
56 
62 
63  ~TCPConnector();
64 
79  const ola::TimeInterval &timeout,
80  TCPConnectCallback *callback);
81 
91  bool Cancel(TCPConnectionID id);
92 
96  void CancelAll();
97 
101  unsigned int ConnectionsPending() const { return m_connections.size(); }
102 
107  void SocketWritable(class PendingTCPConnection *connection);
108 
109  private:
110  typedef std::set<class PendingTCPConnection*> ConnectionSet;
111 
113  ConnectionSet m_connections;
114 
115  void FreePendingConnection(class PendingTCPConnection *connection);
116  void Timeout(const ConnectionSet::iterator &iter);
117  void TimeoutEvent(class PendingTCPConnection *connection);
118  void CleanUpOrphans();
119 
120  DISALLOW_COPY_AND_ASSIGN(TCPConnector);
121 };
122 } // namespace network
123 } // namespace ola
124 #endif // INCLUDE_OLA_NETWORK_TCPCONNECTOR_H_