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>
36
37namespace ola {
38namespace network {
39
40/*
41 * A TCPSocket
42 */
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;
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 */
75 public:
76 explicit TCPAcceptingSocket(class TCPSocketFactoryInterface *factory);
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_
Represents an IPv4 Address.
Helper macros.
Represents Socket Addresses.
A BidirectionalFileDescriptor that also generates notifications when closed.
Definition Descriptor.h:283
Represents a file descriptor that supports reading data.
Definition Descriptor.h:140
a Generic Socket Address
Definition SocketAddress.h:166
The base SocketAddress.
Definition SocketAddress.h:58
Definition TCPSocket.h:74
ola::io::DescriptorHandle ReadDescriptor() const
Returns the read descriptor for this socket.
Definition TCPSocket.h:79
GenericSocketAddress GetLocalAddress() const
Definition TCPSocket.cpp:323
void PerformRead()
Called when there is data available on the descriptor.
Definition TCPSocket.cpp:278
~TCPAcceptingSocket()
Definition TCPSocket.cpp:183
Definition TCPSocketFactory.h:34
Definition TCPSocket.h:43
ola::io::DescriptorHandle WriteDescriptor() const
Returns the write descriptor for this socket.
Definition TCPSocket.h:50
GenericSocketAddress GetPeerAddress() const
Definition TCPSocket.cpp:72
ola::io::DescriptorHandle ReadDescriptor() const
Returns the read descriptor for this socket.
Definition TCPSocket.h:49
The namespace containing all OLA symbols.
Definition Credentials.cpp:44