BALL  1.4.79
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
networking.h
Go to the documentation of this file.
1 // -*- Mode: C++; tab-width: 2; -*-
2 // vi: set ts=2:
3 //
4 
5 #ifndef BALL_SYSTEM_NETWORKING_H
6 #define BALL_SYSTEM_NETWORKING_H
7 
8 #ifndef BALL_COMMON_GLOBAL_HH
9 # include<BALL/COMMON/global.h>
10 #endif
11 
12 #ifndef BALL_DATATYPE_STRING_H
13 # include <BALL/DATATYPE/string.h>
14 #endif
15 
16 #ifdef BALL_HAS_BOOST_ASIO
17 # include <boost/asio.hpp>
18 #else
19 #define BOOST_DATE_TIME_NO_LIB
20 #define BOOST_REGEX_NO_LIB
21 # include <asio.hpp>
22 #endif
23 
24 #include <QtCore/QThread>
25 
26 namespace BALL
27 {
36  : public BALL_ASIO_NAMESPACE::ip::tcp::iostream
37  {
38  public:
40  : BALL_ASIO_NAMESPACE::ip::tcp::iostream()
41  {
42  }
43 
44  TCPIOStream(const String& hostname, const String& protocol)
45  : BALL_ASIO_NAMESPACE::ip::tcp::iostream(hostname, protocol)
46  {
47  }
48 
49  TCPIOStream(const String& hostname, Position port)
50  : BALL_ASIO_NAMESPACE::ip::tcp::iostream(hostname, String(port))
51  {
52  }
53  };
54 
65  {
66  public:
67  TCPServer(Size port, bool restart = true)
68  : port_(port),
69  restart_(restart),
70  connected_stream_(),
71  io_service_(),
72  acceptor_(io_service_)
73  {};
74 
75  virtual ~TCPServer();
76 
77  virtual void activate();
78  virtual void deactivate();
79 
80  virtual void startAccepting();
81  virtual void handleConnection();
82  virtual void connectionRequested();
83 
84  void setPort(Size port);
85  Size getPort() const;
86 
87  protected:
89  bool restart_;
90 
92 
93  BALL_ASIO_NAMESPACE::io_service io_service_;
94 
95  BALL_ASIO_NAMESPACE::ip::tcp::acceptor acceptor_;
96  };
97 
101  : public TCPServer,
102  public virtual QThread
103  {
104  public:
105  TCPServerThread(Size port, bool asynchronous = true, bool restart = true);
106 
107  virtual void run();
108  virtual void deactivate();
109  virtual void activate_async();
110  virtual void handleAsyncConnection();
111  virtual void handleClose();
112 
114  bool isRunning();
115 
116  protected:
119  };
120 } // namespace BALL
121 
122 #endif // BALL_SYSTEM_NETWORKING_H
TCPIOStream(const String &hostname, Position port)
Definition: networking.h:49
TCPIOStream connected_stream_
Definition: networking.h:91
BALL_ASIO_NAMESPACE::io_service io_service_
Definition: networking.h:93
TCPIOStream(const String &hostname, const String &protocol)
Definition: networking.h:44
BALL_ASIO_NAMESPACE::ip::tcp::acceptor acceptor_
Definition: networking.h:95
#define BALL_EXPORT
Definition: COMMON/global.h:50
TCPServer(Size port, bool restart=true)
Definition: networking.h:67