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

| Open Lighting Architecture 0.10.9

Loading...
Searching...
No Matches
TCPSocket.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 * TCPSocket.h
17 * The TCP Socket interfaces
18 * Copyright (C) 2005 Simon Newton
19 *
20 * TCPSocket, this represents a TCP connection to a remote endpoint
21 *
22 * AcceptingSocket is the interface that defines sockets which can spawn new
23 * ConnectedDescriptors. TCPAcceptingSocket is the only subclass and provides
24 * the accept() functionality.
25 */
26
27#ifndef INCLUDE_OLA_NETWORK_TCPSOCKET_H_
28#define INCLUDE_OLA_NETWORK_TCPSOCKET_H_
29
30#include <stdint.h>
31
32#include <ola/base/Macro.h>
33#include <ola/io/Descriptor.h>
34#include <ola/network/IPV4Address.h>
35#include <ola/network/SocketAddress.h>
36
37namespace ola {
38namespace network {
39
40/*
41 * A TCPSocket
42 */
43 class TCPSocket: public ola::io::ConnectedDescriptor {
44 public:
45 explicit TCPSocket(int sd);
46
47 ~TCPSocket() { Close(); }
48
49 ola::io::DescriptorHandle ReadDescriptor() const { return m_handle; }
50 ola::io::DescriptorHandle WriteDescriptor() const { return m_handle; }
51 bool Close();
52
53 GenericSocketAddress GetLocalAddress() const;
54 GenericSocketAddress GetPeerAddress() const;
55
56 static TCPSocket* Connect(const SocketAddress &endpoint);
57
58 bool SetNoDelay();
59
60 protected:
61 bool IsSocket() const { return true; }
62
63 private:
64 ola::io::DescriptorHandle m_handle;
65
66 TCPSocket(const TCPSocket &) = delete;
67 const TCPSocket &operator=(const TCPSocket &) = delete;
68};
69
70
71/*
72 * A TCP accepting socket
73 */
74 class TCPAcceptingSocket: public ola::io::ReadFileDescriptor {
75 public:
76 explicit TCPAcceptingSocket(class TCPSocketFactoryInterface *factory);
77 ~TCPAcceptingSocket();
78 bool Listen(const SocketAddress &endpoint, int backlog = 10);
79 ola::io::DescriptorHandle ReadDescriptor() const { return m_handle; }
80 bool Close();
81 void PerformRead();
82
83 void SetFactory(class TCPSocketFactoryInterface *factory) {
84 m_factory = factory;
85 }
86
87 GenericSocketAddress GetLocalAddress() const;
88
89 private:
90 ola::io::DescriptorHandle m_handle;
91 class TCPSocketFactoryInterface *m_factory;
92
93 TCPAcceptingSocket(const TCPAcceptingSocket &) = delete;
94 const TCPAcceptingSocket &operator=(const TCPAcceptingSocket &) = delete;
95};
96} // namespace network
97} // namespace ola
98#endif // INCLUDE_OLA_NETWORK_TCPSOCKET_H_
IPV4Address.h
Represents an IPv4 Address.
Macro.h
Helper macros.
SocketAddress.h
Represents Socket Addresses.
ola::io::ConnectedDescriptor
A BidirectionalFileDescriptor that also generates notifications when closed.
Definition Descriptor.h:283
ola::io::ReadFileDescriptor
Represents a file descriptor that supports reading data.
Definition Descriptor.h:140
ola::network::GenericSocketAddress
a Generic Socket Address
Definition SocketAddress.h:166
ola::network::SocketAddress
The base SocketAddress.
Definition SocketAddress.h:58
ola::network::TCPAcceptingSocket
Definition TCPSocket.h:74
ola::network::TCPAcceptingSocket::ReadDescriptor
ola::io::DescriptorHandle ReadDescriptor() const
Returns the read descriptor for this socket.
Definition TCPSocket.h:79
ola::network::TCPAcceptingSocket::GetLocalAddress
GenericSocketAddress GetLocalAddress() const
Definition TCPSocket.cpp:323
ola::network::TCPAcceptingSocket::PerformRead
void PerformRead()
Called when there is data available on the descriptor.
Definition TCPSocket.cpp:278
ola::network::TCPAcceptingSocket::~TCPAcceptingSocket
~TCPAcceptingSocket()
Definition TCPSocket.cpp:183
ola::network::TCPSocketFactoryInterface
Definition TCPSocketFactory.h:34
ola::network::TCPSocket
Definition TCPSocket.h:43
ola::network::TCPSocket::WriteDescriptor
ola::io::DescriptorHandle WriteDescriptor() const
Returns the write descriptor for this socket.
Definition TCPSocket.h:50
ola::network::TCPSocket::GetPeerAddress
GenericSocketAddress GetPeerAddress() const
Definition TCPSocket.cpp:72
ola::network::TCPSocket::ReadDescriptor
ola::io::DescriptorHandle ReadDescriptor() const
Returns the read descriptor for this socket.
Definition TCPSocket.h:49
Descriptor.h
ola::network
Code for network communication.
Definition AdvancedTCPConnector.cpp:28
ola::network::GetLocalAddress
GenericSocketAddress GetLocalAddress(int sd)
Definition SocketHelper.cpp:39
ola
The namespace containing all OLA symbols.
Definition Credentials.cpp:44