Async 1.5.0
AsyncTcpServerBase.h
Go to the documentation of this file.
1
27#ifndef ASYNC_TCP_SERVER_BASE_INCLUDED
28#define ASYNC_TCP_SERVER_BASE_INCLUDED
29
30
31/****************************************************************************
32 *
33 * System Includes
34 *
35 ****************************************************************************/
36
37#include <string>
38#include <vector>
39#include <sigc++/sigc++.h>
40
41
42/****************************************************************************
43 *
44 * Project Includes
45 *
46 ****************************************************************************/
47
48#include <AsyncTcpConnection.h>
49
50
51/****************************************************************************
52 *
53 * Local Includes
54 *
55 ****************************************************************************/
56
57
58
59/****************************************************************************
60 *
61 * Forward declarations
62 *
63 ****************************************************************************/
64
65
66
67/****************************************************************************
68 *
69 * Namespace
70 *
71 ****************************************************************************/
72
73namespace Async
74{
75
76/****************************************************************************
77 *
78 * Forward declarations of classes inside of the declared namespace
79 *
80 ****************************************************************************/
81
82class FdWatch;
83
84
85/****************************************************************************
86 *
87 * Defines & typedefs
88 *
89 ****************************************************************************/
90
91
92
93/****************************************************************************
94 *
95 * Exported Global Variables
96 *
97 ****************************************************************************/
98
99
100
101/****************************************************************************
102 *
103 * Class definitions
104 *
105 ****************************************************************************/
106
112class TcpServerBase : public sigc::trackable
113{
114 public:
120 TcpServerBase(const std::string& port_str,
121 const Async::IpAddress &bind_ip);
122
126 virtual ~TcpServerBase(void);
127
133
139 TcpConnection *getClient(unsigned int index);
140
147 int writeAll(const void *buf, int count);
148
156 int writeOnly(TcpConnection *con, const void *buf, int count);
157
165 int writeExcept(TcpConnection *con, const void *buf, int count);
166
167 protected:
168 virtual void createConnection(int sock, const IpAddress& remote_addr,
169 uint16_t remote_port) = 0;
172
173 private:
174 typedef std::vector<TcpConnection*> TcpConnectionList;
175
176 int sock;
177 FdWatch *rd_watch;
178 TcpConnectionList tcpConnectionList;
179
180 void cleanup(void);
181 void onConnection(FdWatch *watch);
182
183}; /* class TcpServerBase */
184
185
186} /* namespace */
187
188#endif /* ASYNC_TCP_SERVER_BASE_INCLUDED */
189
190
191
192/*
193 * This file has not been truncated
194 */
195
196
197
Contains a class for handling exiting TCP connections.
A class for watching file descriptors.
Definition: AsyncFdWatch.h:120
A class for representing an IP address in an OS independent way.
A class for handling exiting TCP connections.
The base class for creating a TCP server.
int writeAll(const void *buf, int count)
Write data to all connected clients.
virtual void createConnection(int sock, const IpAddress &remote_addr, uint16_t remote_port)=0
int numberOfClients(void)
Get the number of clients that is connected to the server.
TcpConnection * getClient(unsigned int index)
Get the client object pointer from the server.
void removeConnection(TcpConnection *con)
int writeExcept(TcpConnection *con, const void *buf, int count)
Send data to all connected clients except the given client.
int writeOnly(TcpConnection *con, const void *buf, int count)
Send data only to the given client.
void addConnection(TcpConnection *con)
virtual ~TcpServerBase(void)
Destructor.
TcpServerBase(const std::string &port_str, const Async::IpAddress &bind_ip)
Default constuctor.
Namespace for the asynchronous programming classes.