Open Lighting Architecture: include/ola/network/TCPConnector.h Source File

| 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>
28#include <ola/network/IPV4Address.h>
29#include <ola/network/SocketAddress.h>
30#include <ola/network/TCPSocket.h>
31#include <set>
32#include <vector>
33
34namespace ola {
35namespace network {
36
40 class TCPConnector {
41 public:
48 typedef ola::SingleUseCallback2<void, int, int> TCPConnectCallback;
49
55 typedef const void* TCPConnectionID;
56
61 explicit TCPConnector(ola::io::SelectServerInterface *ss);
62
63 ~TCPConnector();
64
78 TCPConnectionID Connect(const IPV4SocketAddress &endpoint,
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
112 ola::io::SelectServerInterface *m_ss;
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_
Callback.h
IPV4Address.h
Represents an IPv4 Address.
Macro.h
Helper macros.
SocketAddress.h
Represents Socket Addresses.
ola::SingleUseCallback2
A 2 argument callback which deletes itself after it's run.
Definition Callback.h:1907
ola::TimeInterval
Definition Clock.h:126
ola::io::SelectServerInterface
The interface for the SelectServer.
Definition SelectServerInterface.h:42
ola::network::IPV4SocketAddress
An IPv4 SocketAddress.
Definition SocketAddress.h:78
ola::network::PendingTCPConnection
Definition TCPConnector.cpp:40
ola::network::TCPConnector
An class which manages non-blocking TCP connects.
Definition TCPConnector.h:40
ola::network::TCPConnector::SocketWritable
void SocketWritable(class PendingTCPConnection *connection)
Called when the TCP socket connects.
Definition TCPConnector.cpp:212
ola::network::TCPConnector::CancelAll
void CancelAll()
Cancel all pending TCP connections.
Definition TCPConnector.cpp:194
ola::network::TCPConnector::ConnectionsPending
unsigned int ConnectionsPending() const
Return the number of pending connections.
Definition TCPConnector.h:101
ola::network::TCPConnector::TCPConnectCallback
ola::SingleUseCallback2< void, int, int > TCPConnectCallback
The callback run when a TCP connection request completes.
Definition TCPConnector.h:48
ola::network::TCPConnector::Cancel
bool Cancel(TCPConnectionID id)
Cancel a pending TCP connection.
Definition TCPConnector.cpp:176
ola::network::TCPConnector::TCPConnector
TCPConnector(ola::io::SelectServerInterface *ss)
Create a new TCPConnector.
Definition TCPConnector.cpp:101
ola::network::TCPConnector::TCPConnectionID
const void * TCPConnectionID
The TCPConnectionID.
Definition TCPConnector.h:55
ola::network::TCPConnector::Connect
TCPConnectionID Connect(const IPV4SocketAddress &endpoint, const ola::TimeInterval &timeout, TCPConnectCallback *callback)
Perform a non-blocking TCP connect.
Definition TCPConnector.cpp:110
Descriptor.h
ola::network
Code for network communication.
Definition AdvancedTCPConnector.cpp:28
ola
The namespace containing all OLA symbols.
Definition Credentials.cpp:44