BALL 1.5.0
Loading...
Searching...
No Matches
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(static_cast<const std::string&>(hostname),
40 static_cast<const std::string&>(protocol))
41 {
42 }
43
44 TCPIOStream(const String& hostname, Position port)
45 : boost::asio::ip::tcp::iostream(static_cast<const std::string&>(hostname),
46 std::string(String(port)))
47 {
48 }
49 };
50
61 {
62 public:
63 TCPServer(Size port, bool restart = true)
64 : port_(port),
65 restart_(restart),
69 {};
70
71 virtual ~TCPServer();
72
73 virtual void activate();
74 virtual void deactivate();
75
76 virtual void startAccepting();
77 virtual void handleConnection();
78 virtual void connectionRequested();
79
80 void setPort(Size port);
81 Size getPort() const;
82
83 protected:
86
88
89 boost::asio::io_context io_service_;
90
91 boost::asio::ip::tcp::acceptor acceptor_;
92 };
93
97 : public TCPServer,
98 public virtual QThread
99 {
100 public:
101 TCPServerThread(Size port, bool asynchronous = true, bool restart = true);
102
103 virtual void run();
104 virtual void deactivate();
105 virtual void activate_async();
106 virtual void handleAsyncConnection();
107 virtual void handleClose();
108
110 bool isRunning();
111
112 protected:
115 };
116} // namespace BALL
117
118#endif // BALL_SYSTEM_NETWORKING_H
#define BALL_EXPORT
TCPIOStream(const String &hostname, const String &protocol)
Definition networking.h:38
TCPIOStream(const String &hostname, Position port)
Definition networking.h:44
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()
boost::asio::io_context io_service_
Definition networking.h:89
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:63
boost::asio::ip::tcp::acceptor acceptor_
Definition networking.h:91
virtual ~TCPServer()
TCPIOStream connected_stream_
Definition networking.h:87
virtual void deactivate()
BALL_SIZE_TYPE Size
BALL_SIZE_TYPE Position
STL namespace.