Last change
on this file since 35 was
22,
checked in by rings, 14 years ago
|
|
-
Property svn:executable set to
*
|
File size:
1.4 KB
|
Line | |
---|
1 | /** |
---|
2 | * @file TcpipServer.h |
---|
3 | * This header file defines the TcpipServer class. |
---|
4 | * @author Tomas Urban |
---|
5 | * @version 0.3 |
---|
6 | * @date 23/07/2009 |
---|
7 | */ |
---|
8 | #ifndef TCPIP_SERVER_H |
---|
9 | #define TCPIP_SERVER_H |
---|
10 | |
---|
11 | #include "TcpipDefs.h" |
---|
12 | #include "Helper/Singleton.h" |
---|
13 | #include "ConnectionController.h" |
---|
14 | #include <list> |
---|
15 | #include <boost/thread/mutex.hpp> |
---|
16 | #include <boost/thread/condition.hpp> |
---|
17 | |
---|
18 | /** |
---|
19 | * Simple class for creating a listening socket on a certain port and handling incoming connection requests |
---|
20 | * from clients. |
---|
21 | */ |
---|
22 | class TcpipServer : public Singleton<TcpipServer> |
---|
23 | { |
---|
24 | private: |
---|
25 | SOCKET_TYPE m_hListeningSocket; |
---|
26 | boost::mutex m_mutex; |
---|
27 | boost::condition m_operationEnded; |
---|
28 | std::list<ConnectionController *> m_lActiveControllers; |
---|
29 | |
---|
30 | class ConnectionHandler |
---|
31 | { |
---|
32 | private: |
---|
33 | SOCKET_TYPE m_hSocket; |
---|
34 | public: |
---|
35 | ConnectionHandler(SOCKET_TYPE hSocket); |
---|
36 | void operator()(); |
---|
37 | }; |
---|
38 | |
---|
39 | friend class Singleton<TcpipServer>; |
---|
40 | TcpipServer(void); |
---|
41 | void OnExit(); |
---|
42 | static void OnExit(int nSig); |
---|
43 | public: |
---|
44 | /** |
---|
45 | * Default port number |
---|
46 | */ |
---|
47 | static int const DEFAULT_PORT = 5501; |
---|
48 | ~TcpipServer(void); |
---|
49 | /** |
---|
50 | * The method opens a TCP/IP socket on a specified port and start listening on it. When a connection |
---|
51 | * request is accepted, a new thread is created for handling the communication with the client. |
---|
52 | * The method is designed as blocking and it returns only if an error occurs or on a client |
---|
53 | * (i.e. lower tester) request. |
---|
54 | * @param nPort Port on which the instance should listen |
---|
55 | */ |
---|
56 | void Run(int nPort); |
---|
57 | }; |
---|
58 | |
---|
59 | #endif |
---|
Note: See
TracBrowser
for help on using the repository browser.