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 
73 namespace Async
74 {
75 
76 /****************************************************************************
77  *
78  * Forward declarations of classes inside of the declared namespace
79  *
80  ****************************************************************************/
81 
82 class 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 
112 class 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 
132  int numberOfClients(void);
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;
170  void addConnection(TcpConnection *con);
171  void removeConnection(TcpConnection *con);
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 
A class for handling exiting TCP connections.
int writeOnly(TcpConnection *con, const void *buf, int count)
Send data only to the given client.
int writeExcept(TcpConnection *con, const void *buf, int count)
Send data to all connected clients except the given client.
TcpConnection * getClient(unsigned int index)
Get the client object pointer from the server.
virtual ~TcpServerBase(void)
Destructor.
void removeConnection(TcpConnection *con)
A class for watching file descriptors.
Definition: AsyncFdWatch.h:119
void addConnection(TcpConnection *con)
int writeAll(const void *buf, int count)
Write data to all connected clients.
Contains a class for handling exiting TCP connections.
Namespace for the asynchronous programming classes.
int numberOfClients(void)
Get the number of clients that is connected to the server.
virtual void createConnection(int sock, const IpAddress &remote_addr, uint16_t remote_port)=0
A class for representing an IP address in an OS independent way.
The base class for creating a TCP server.
TcpServerBase(const std::string &port_str, const Async::IpAddress &bind_ip)
Default constuctor.