Open Lighting Architecture 0.10.9
Loading...
Searching...
No Matches
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
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
34namespace ola {
35namespace network {
36
41 public:
49
55 typedef const void* TCPConnectionID;
56
62
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 TCPConnector(const TCPConnector &) = delete;
121 const TCPConnector &operator=(const TCPConnector &) = delete;
122};
123} // namespace network
124} // namespace ola
125#endif // INCLUDE_OLA_NETWORK_TCPCONNECTOR_H_
Represents an IPv4 Address.
Helper macros.
Represents Socket Addresses.
A 2 argument callback which deletes itself after it's run.
Definition Callback.h:1907
Definition Clock.h:126
The interface for the SelectServer.
Definition SelectServerInterface.h:42
An IPv4 SocketAddress.
Definition SocketAddress.h:78
Definition TCPConnector.cpp:40
An class which manages non-blocking TCP connects.
Definition TCPConnector.h:40
void SocketWritable(class PendingTCPConnection *connection)
Called when the TCP socket connects.
Definition TCPConnector.cpp:212
void CancelAll()
Cancel all pending TCP connections.
Definition TCPConnector.cpp:194
unsigned int ConnectionsPending() const
Return the number of pending connections.
Definition TCPConnector.h:101
ola::SingleUseCallback2< void, int, int > TCPConnectCallback
The callback run when a TCP connection request completes.
Definition TCPConnector.h:48
bool Cancel(TCPConnectionID id)
Cancel a pending TCP connection.
Definition TCPConnector.cpp:176
TCPConnector(ola::io::SelectServerInterface *ss)
Create a new TCPConnector.
Definition TCPConnector.cpp:101
const void * TCPConnectionID
The TCPConnectionID.
Definition TCPConnector.h:55
TCPConnectionID Connect(const IPV4SocketAddress &endpoint, const ola::TimeInterval &timeout, TCPConnectCallback *callback)
Perform a non-blocking TCP connect.
Definition TCPConnector.cpp:110
The namespace containing all OLA symbols.
Definition Credentials.cpp:44