Loading...
Searching...
No Matches
networking.h
Go to the documentation of this file.
// -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//
#ifndef BALL_SYSTEM_NETWORKING_H
#define BALL_SYSTEM_NETWORKING_H
#ifndef BALL_COMMON_GLOBAL_HH
# include<BALL/COMMON/global.h>
#endif
#ifndef BALL_DATATYPE_STRING_H
# include <BALL/DATATYPE/string.h>
#endif
#include <boost/asio.hpp>
#include <QtCore/QThread>
namespace BALL
{
class BALL_EXPORT TCPIOStream
: public boost::asio::ip::tcp::iostream
{
public:
TCPIOStream()
: boost::asio::ip::tcp::iostream()
{
}
TCPIOStream(const String& hostname, const String& protocol)
: boost::asio::ip::tcp::iostream(static_cast<const std::string&>(hostname),
static_cast<const std::string&>(protocol))
{
}
TCPIOStream(const String& hostname, Position port)
: boost::asio::ip::tcp::iostream(static_cast<const std::string&>(hostname),
std::string(String(port)))
{
}
};
class BALL_EXPORT TCPServer
{
public:
TCPServer(Size port, bool restart = true)
: port_(port),
restart_(restart),
connected_stream_(),
io_service_(),
acceptor_(io_service_)
{};
virtual ~TCPServer();
virtual void activate();
virtual void deactivate();
virtual void startAccepting();
virtual void handleConnection();
virtual void connectionRequested();
void setPort(Size port);
Size getPort() const;
protected:
Size port_;
bool restart_;
TCPIOStream connected_stream_;
boost::asio::io_context io_service_;
boost::asio::ip::tcp::acceptor acceptor_;
};
class BALL_EXPORT TCPServerThread
: public TCPServer,
public virtual QThread
{
public:
TCPServerThread(Size port, bool asynchronous = true, bool restart = true);
virtual void run();
virtual void deactivate();
virtual void activate_async();
virtual void handleAsyncConnection();
virtual void handleClose();
bool isRunning();
protected:
bool use_async_io_;
bool is_running_;
};
} // namespace BALL
#endif // BALL_SYSTEM_NETWORKING_H
global.h
BALL_EXPORT
#define BALL_EXPORT
Definition COMMON/global.h:50
BALL::String
Definition string.h:57
BALL::TCPIOStream
Definition networking.h:31
BALL::TCPIOStream::TCPIOStream
TCPIOStream()
Definition networking.h:33
BALL::TCPIOStream::TCPIOStream
TCPIOStream(const String &hostname, const String &protocol)
Definition networking.h:38
BALL::TCPIOStream::TCPIOStream
TCPIOStream(const String &hostname, Position port)
Definition networking.h:44
BALL::TCPServerThread::isRunning
bool isRunning()
BALL::TCPServerThread::deactivate
virtual void deactivate()
BALL::TCPServerThread::handleAsyncConnection
virtual void handleAsyncConnection()
BALL::TCPServerThread::is_running_
bool is_running_
Definition networking.h:114
BALL::TCPServerThread::run
virtual void run()
BALL::TCPServerThread::activate_async
virtual void activate_async()
BALL::TCPServerThread::use_async_io_
bool use_async_io_
Definition networking.h:113
BALL::TCPServerThread::TCPServerThread
TCPServerThread(Size port, bool asynchronous=true, bool restart=true)
BALL::TCPServerThread::handleClose
virtual void handleClose()
BALL::TCPServer::io_service_
boost::asio::io_context io_service_
Definition networking.h:89
BALL::TCPServer::restart_
bool restart_
Definition networking.h:85
BALL::TCPServer::startAccepting
virtual void startAccepting()
BALL::TCPServer::activate
virtual void activate()
BALL::TCPServer::setPort
void setPort(Size port)
BALL::TCPServer::getPort
Size getPort() const
BALL::TCPServer::connectionRequested
virtual void connectionRequested()
BALL::TCPServer::handleConnection
virtual void handleConnection()
BALL::TCPServer::port_
Size port_
Definition networking.h:84
BALL::TCPServer::TCPServer
TCPServer(Size port, bool restart=true)
Definition networking.h:63
BALL::TCPServer::acceptor_
boost::asio::ip::tcp::acceptor acceptor_
Definition networking.h:91
BALL::TCPServer::~TCPServer
virtual ~TCPServer()
BALL::TCPServer::connected_stream_
TCPIOStream connected_stream_
Definition networking.h:87
BALL::TCPServer::deactivate
virtual void deactivate()
QThread
BALL
Definition constants.h:13
BALL::Size
BALL_SIZE_TYPE Size
Definition COMMON/global.h:114
BALL::Position
BALL_SIZE_TYPE Position
Definition COMMON/global.h:140
boost
Definition graphAlgorithms.h:27
std
STL namespace.
string.h