BALL 1.5.0
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
10#endif
11
12#ifndef BALL_DATATYPE_STRING_H
13# include <BALL/DATATYPE/string.h>
14#endif
15
16#include <boost/asio.hpp>
17
18#include <QtCore/QThread>
19
20namespace BALL
21{
30 : public boost::asio::ip::tcp::iostream
31 {
32 public:
34 : boost::asio::ip::tcp::iostream()
35 {
36 }
37
38 TCPIOStream(const String& hostname, const String& protocol)
39 : boost::asio::ip::tcp::iostream(hostname, protocol)
40 {
41 }
42
43 TCPIOStream(const String& hostname, Position port)
44 : boost::asio::ip::tcp::iostream(hostname, String(port))
45 {
46 }
47 };
48
59 {
60 public:
61 TCPServer(Size port, bool restart = true)
62 : port_(port),
63 restart_(restart),
64 connected_stream_(),
65 io_service_(),
66 acceptor_(io_service_)
67 {};
68
69 virtual ~TCPServer();
70
71 virtual void activate();
72 virtual void deactivate();
73
74 virtual void startAccepting();
75 virtual void handleConnection();
76 virtual void connectionRequested();
77
78 void setPort(Size port);
79 Size getPort() const;
80
81 protected:
84
86
87 boost::asio::io_service io_service_;
88
89 boost::asio::ip::tcp::acceptor acceptor_;
90 };
91
95 : public TCPServer,
96 public virtual QThread
97 {
98 public:
99 TCPServerThread(Size port, bool asynchronous = true, bool restart = true);
100
101 virtual void run();
102 virtual void deactivate();
103 virtual void activate_async();
104 virtual void handleAsyncConnection();
105 virtual void handleClose();
106
108 bool isRunning();
109
110 protected:
113 };
114} // namespace BALL
115
116#endif // BALL_SYSTEM_NETWORKING_H
Definition: constants.h:13
TCPIOStream(const String &hostname, const String &protocol)
Definition: networking.h:38
TCPIOStream(const String &hostname, Position port)
Definition: networking.h:43
virtual void startAccepting()
virtual void activate()
void setPort(Size port)
Size getPort() const
virtual void connectionRequested()
virtual void handleConnection()
TCPServer(Size port, bool restart=true)
Definition: networking.h:61
boost::asio::ip::tcp::acceptor acceptor_
Definition: networking.h:89
virtual ~TCPServer()
TCPIOStream connected_stream_
Definition: networking.h:85
virtual void deactivate()
boost::asio::io_service io_service_
Definition: networking.h:87
virtual void deactivate()
virtual void handleAsyncConnection()
virtual void run()
virtual void activate_async()
TCPServerThread(Size port, bool asynchronous=true, bool restart=true)
virtual void handleClose()
#define BALL_EXPORT
Definition: COMMON/global.h:50