WIP. Using WIOService to handle Services

This commit is contained in:
emeric
2014-08-05 13:11:31 +02:00
parent f26e6cad7c
commit 9fdc9f41dd
12 changed files with 148 additions and 65 deletions
+8 -3
View File
@@ -9,14 +9,15 @@
namespace Remote {
namespace Server {
Server::Server(boost::asio::io_service& ioService, const endpoint_type& bindEndpoint, boost::filesystem::path dbPath)
Server::Server(const endpoint_type& bindEndpoint, boost::filesystem::path dbPath)
:
_ioService(ioService),
_acceptor(_ioService, bindEndpoint, true /*SO_REUSEADDR*/),
_connectionManager(),
_context(boost::asio::ssl::context::tlsv1_server),
_dbPath(dbPath)
{
_ioService.setThreadCount(1);
_context.set_options( boost::asio::ssl::context::default_workarounds // TODO check this thing
| boost::asio::ssl::context::single_dh_use
| boost::asio::ssl::context::no_sslv2
@@ -29,12 +30,14 @@ _dbPath(dbPath)
}
void
Server::run()
Server::start()
{
// While the server is running, there is always at least one
// asynchronous operation outstanding: the asynchronous accept call waiting
// for new incoming connections.
asyncAccept();
_ioService.start();
}
void
@@ -77,6 +80,8 @@ Server::stop()
// operations.
_acceptor.close();
_connectionManager.stopAll();
_ioService.stop();
}
} // namespace Server
+5 -3
View File
@@ -1,6 +1,8 @@
#ifndef REMOTE_SERVER_HPP
#define REMOTE_SERVER_HPP
#include <Wt/WIOService>
#include <boost/asio.hpp>
#include <boost/asio/ssl.hpp>
@@ -24,10 +26,10 @@ class Server
typedef boost::asio::ip::tcp::endpoint endpoint_type;
// Serve up data from the given database
Server(boost::asio::io_service& ioService, const endpoint_type& bindEndpoint, boost::filesystem::path dbPath);
Server(const endpoint_type& bindEndpoint, boost::filesystem::path dbPath);
// Run the server's io_service loop.
void run();
void start();
void stop();
@@ -36,7 +38,7 @@ class Server
void asyncAccept();
void handleAccept(std::shared_ptr<Connection> newConnection, boost::system::error_code ec);
boost::asio::io_service& _ioService;
Wt::WIOService _ioService;
/// Acceptor used to listen for incoming connections.
boost::asio::ip::tcp::acceptor _acceptor;