diff options
Diffstat (limited to 'server/include')
-rw-r--r-- | server/include/server.h | 39 | ||||
-rw-r--r-- | server/include/server_session.h | 57 | ||||
-rw-r--r-- | server/include/socket_wraper.h | 86 |
3 files changed, 95 insertions, 87 deletions
diff --git a/server/include/server.h b/server/include/server.h index 812406a..e8fb3ad 100644 --- a/server/include/server.h +++ b/server/include/server.h @@ -1,5 +1,5 @@ /* - Copyright © 2015 Gluzskiy Alexandr (sss) + Copyright © 2015 Gluzskiy Alexandr (sss) This file is part of Unknown Download Manager (UDM). @@ -18,7 +18,6 @@ */ - #ifndef SERVER_H #define SERVER_H @@ -28,32 +27,34 @@ #include "client.h" #include "download_internal.h" -//TODO ssl +// TODO ssl class server_session; - class server { public: - server(boost::asio::io_service& io_service, runtime_config_s &config, std::map<std::string, client*> &clients, std::map<int, download_internal_s> &downloads, short port); - void terminate() - { + server(boost::asio::io_service& io_service, + runtime_config_s& config, + std::map<std::string, client*>& clients, + std::map<int, download_internal_s>& downloads, + short port); + void terminate() + { io_service_.stop(); - } + } private: - void start_accept(); - void handle_accept(server_session* new_session, const boost::system::error_code& error); - - boost::asio::io_service& io_service_; - boost::asio::ip::tcp::acceptor acceptor_; - boost::asio::ssl::context *context_; - runtime_config_s &runtime_config; - std::map<std::string, client*> &clients; - std::map<int, download_internal_s> &downloads; + server(const server&) = delete; + void start_accept(); + void handle_accept(server_session* new_session, const boost::system::error_code& error); + + boost::asio::io_service& io_service_; + boost::asio::ip::tcp::acceptor acceptor_; + boost::asio::ssl::context* context_; + runtime_config_s& runtime_config; + std::map<std::string, client*>& clients; + std::map<int, download_internal_s>& downloads; }; - - #endif // SERVER_H diff --git a/server/include/server_session.h b/server/include/server_session.h index 07e8fcd..436c4ee 100644 --- a/server/include/server_session.h +++ b/server/include/server_session.h @@ -1,5 +1,5 @@ /* - Copyright © 2015 Gluzskiy Alexandr (sss) + Copyright © 2015 Gluzskiy Alexandr (sss) This file is part of Unknown Download Manager (UDM). @@ -18,7 +18,6 @@ */ - #ifndef SERVER_SESSION_H #define SERVER_SESSION_H @@ -34,33 +33,37 @@ class socket_wraper; class server_session { - public: - server_session(boost::asio::io_service &s, runtime_config_s &config, std::map<std::string, client*> &clients_, std::map<int, download_internal_s> &downloads, boost::asio::ssl::context *c = nullptr); - void run(); - void send_message(server_msg *msg); - socket_wraper* socket(); - virtual ~server_session(); - protected: - private: - //net - void handle_read(const boost::system::error_code& error, size_t bytes_transferred); - void handle_write(const boost::system::error_code& error); - void handle_write_no_read(const boost::system::error_code& error); - void handle_handshake(const boost::system::error_code& error); - bool handle_command(client_msg *msg); +public: + server_session(boost::asio::io_service& s, + runtime_config_s& config, + std::map<std::string, client*>& clients_, + std::map<int, download_internal_s>& downloads, + boost::asio::ssl::context* c = nullptr); + void run(); + void send_message(server_msg* msg); + socket_wraper* socket(); + virtual ~server_session(); +protected: +private: + server_session(const server_session&) = delete; + // net + void handle_read(const boost::system::error_code& error, size_t bytes_transferred); + void handle_write(const boost::system::error_code& error); + void handle_write_no_read(const boost::system::error_code& error); + void handle_handshake(const boost::system::error_code& error); + bool handle_command(client_msg* msg); - char *recv_data_; - socket_wraper *socket_; - boost::asio::io_service &io_service_; - boost::asio::ssl::context *context_; - std::string client_auth_token; - runtime_config_s &runtime_config; - std::map<std::string, client*> &clients; - client *client_; - std::map<int, download_internal_s> &downloads; - //TODO: store client ptr + char* recv_data_ = nullptr; + socket_wraper* socket_ = nullptr; + boost::asio::io_service& io_service_; + boost::asio::ssl::context* context_; + std::string client_auth_token; + runtime_config_s& runtime_config; + std::map<std::string, client*>& clients; + client* client_ = nullptr; + std::map<int, download_internal_s>& downloads; + // TODO: store client ptr }; - #endif // SERVER_SESSION_H diff --git a/server/include/socket_wraper.h b/server/include/socket_wraper.h index ed929ca..6e8dd76 100644 --- a/server/include/socket_wraper.h +++ b/server/include/socket_wraper.h @@ -1,5 +1,5 @@ /* - Copyright © 2015 Gluzskiy Alexandr (sss) + Copyright © 2015 Gluzskiy Alexandr (sss) This file is part of Unknown Download Manager (UDM). @@ -27,79 +27,83 @@ class socket_wraper { public: - socket_wraper(boost::asio::ssl::stream<boost::asio::ip::tcp::socket> *s) : is_ssl(true) + socket_wraper(boost::asio::ssl::stream<boost::asio::ip::tcp::socket>* s) + : is_ssl(true) { - socket_ssl_ = s; + socket_ssl_ = s; } - socket_wraper(boost::asio::ip::tcp::socket *s) : is_ssl(false) + socket_wraper(boost::asio::ip::tcp::socket* s) + : is_ssl(false) { - socket_ = s; + socket_ = s; } - void operator=(boost::asio::ssl::stream<boost::asio::ip::tcp::socket> *s) + void operator=(boost::asio::ssl::stream<boost::asio::ip::tcp::socket>* s) { - socket_ssl_ = s; - is_ssl = true; + socket_ssl_ = s; + is_ssl = true; } - void operator=(boost::asio::ip::tcp::socket *s) + void operator=(boost::asio::ip::tcp::socket* s) { - socket_ = s; - is_ssl = false; + socket_ = s; + is_ssl = false; } boost::asio::ip::tcp::socket& get_socket() { - return *socket_; + return *socket_; } boost::asio::ssl::stream<boost::asio::ip::tcp::socket>& get_ssl_socket() { - return *socket_ssl_; + return *socket_ssl_; } - template<typename MutableBufferSequence> std::size_t read_some(const MutableBufferSequence & buffers) + template <typename MutableBufferSequence> std::size_t read_some(const MutableBufferSequence& buffers) { - if(is_ssl) - return socket_ssl_->read_some(buffers); - else - return socket_->read_some(buffers); + if(is_ssl) + return socket_ssl_->read_some(buffers); + else + return socket_->read_some(buffers); } - template<typename MutableBufferSequence> std::size_t read_some(const MutableBufferSequence & buffers, boost::system::error_code & ec) + template <typename MutableBufferSequence> + std::size_t read_some(const MutableBufferSequence& buffers, boost::system::error_code& ec) { - if(is_ssl) - return socket_ssl_->read_some(buffers, ec); - else - return socket_->read_some(buffers, ec); + if(is_ssl) + return socket_ssl_->read_some(buffers, ec); + else + return socket_->read_some(buffers, ec); } - template<typename MutableBufferSequence, typename ReadHandler> void async_read_some(const MutableBufferSequence & buffers, ReadHandler handler) + template <typename MutableBufferSequence, typename ReadHandler> + void async_read_some(const MutableBufferSequence& buffers, ReadHandler handler) { - if(is_ssl) - socket_ssl_->async_read_some(buffers, handler); - else - socket_->async_read_some(buffers, handler); + if(is_ssl) + socket_ssl_->async_read_some(buffers, handler); + else + socket_->async_read_some(buffers, handler); } - template<typename ConstBufferSequence, typename WriteHandler> void async_write_some(const ConstBufferSequence & buffers, WriteHandler handler) + template <typename ConstBufferSequence, typename WriteHandler> + void async_write_some(const ConstBufferSequence& buffers, WriteHandler handler) { - if(is_ssl) - socket_ssl_->async_write_some(buffers, handler); - else - socket_->async_write_some(buffers, handler); + if(is_ssl) + socket_ssl_->async_write_some(buffers, handler); + else + socket_->async_write_some(buffers, handler); } ~socket_wraper() { - if(is_ssl) - delete socket_ssl_; - else - delete socket_; + if(is_ssl) + delete socket_ssl_; + else + delete socket_; } + private: bool is_ssl; - boost::asio::ip::tcp::socket *socket_; - boost::asio::ssl::stream<boost::asio::ip::tcp::socket> *socket_ssl_; - + boost::asio::ip::tcp::socket* socket_ = nullptr; + boost::asio::ssl::stream<boost::asio::ip::tcp::socket>* socket_ssl_ = nullptr; }; - #endif |