Async  1.3.1
AsyncTcpServer.h
Go to the documentation of this file.
1 
34 #ifndef ASYNC_TCP_SERVER_INCLUDED
35 #define ASYNC_TCP_SERVER_INCLUDED
36 
37 
38 /****************************************************************************
39  *
40  * System Includes
41  *
42  ****************************************************************************/
43 
44 #include <string>
45 #include <vector>
46 #include <sigc++/sigc++.h>
47 
48 
49 /****************************************************************************
50  *
51  * Project Includes
52  *
53  ****************************************************************************/
54 
55 #include <AsyncTcpConnection.h>
56 
57 
58 /****************************************************************************
59  *
60  * Local Includes
61  *
62  ****************************************************************************/
63 
64 
65 
66 /****************************************************************************
67  *
68  * Forward declarations
69  *
70  ****************************************************************************/
71 
72 
73 
74 /****************************************************************************
75  *
76  * Namespace
77  *
78  ****************************************************************************/
79 
80 namespace Async
81 {
82 
83 /****************************************************************************
84  *
85  * Forward declarations of classes inside of the declared namespace
86  *
87  ****************************************************************************/
88 
89 class FdWatch;
90 
91 
92 /****************************************************************************
93  *
94  * Defines & typedefs
95  *
96  ****************************************************************************/
97 
98 
99 
100 /****************************************************************************
101  *
102  * Exported Global Variables
103  *
104  ****************************************************************************/
105 
106 
107 
108 /****************************************************************************
109  *
110  * Class definitions
111  *
112  ****************************************************************************/
113 
126 class TcpServer : public sigc::trackable
127 {
128  public:
133  TcpServer(const std::string& port_str,
134  const Async::IpAddress &bind_ip=IpAddress());
135 
139  ~TcpServer(void);
140 
145  int numberOfClients(void);
146 
152  TcpConnection *getClient(unsigned int index);
153 
160  int writeAll(const void *buf, int count);
161 
169  int writeOnly(TcpConnection *con, const void *buf, int count);
170 
178  int writeExcept(TcpConnection *con, const void *buf, int count);
179 
184  sigc::signal<void, TcpConnection *> clientConnected;
185 
191  sigc::signal<void, TcpConnection *,TcpConnection::DisconnectReason>
193 
194 
195  protected:
196 
197  private:
198  typedef std::vector<TcpConnection*> TcpConnectionList;
199 
200  int sock;
201  FdWatch *rd_watch;
202  TcpConnectionList tcpConnectionList;
203 
204  void cleanup(void);
205  void onConnection(FdWatch *watch);
206  void onDisconnected(TcpConnection *con,
208 
209 }; /* class TcpServer */
210 
211 
212 } /* namespace */
213 
214 #endif /* ASYNC_TCP_SERVER_INCLUDED */
215 
216 
217 
218 /*
219  * This file has not been truncated
220  */
221 
222 
223 
A class for handling exiting TCP connections.
int writeAll(const void *buf, int count)
Write data to all connected clients.
int writeExcept(TcpConnection *con, const void *buf, int count)
Send data to all connected clients except the given client.
sigc::signal< void, TcpConnection * > clientConnected
A signal that is emitted when a client connect to the server.
A class for creating a TCP server.
~TcpServer(void)
Destructor.
A class for watching file descriptors.
Definition: AsyncFdWatch.h:119
TcpConnection * getClient(unsigned int index)
Get the client object pointer from the server.
Contains a class for handling exiting TCP connections.
int writeOnly(TcpConnection *con, const void *buf, int count)
Send data only to the given client.
DisconnectReason
Reason code for disconnects.
int numberOfClients(void)
Get the number of clients that is connected to the server.
Namespace for the asynchronous programming classes.
TcpServer(const std::string &port_str, const Async::IpAddress &bind_ip=IpAddress())
Default constuctor.
A class for representing an IP address in an OS independent way.
sigc::signal< void, TcpConnection *, TcpConnection::DisconnectReason > clientDisconnected
A signal that is emitted when a client disconnect from the server.