Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/marian-nmt/Simple-WebSocket-Server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreidheim <eidheim@gmail.com>2014-08-02 13:38:13 +0400
committereidheim <eidheim@gmail.com>2014-08-02 13:38:13 +0400
commit28ece529bf5a171f8ee96fa3e09799eb5b1c996c (patch)
tree9f4011b5ca1bfd3ab56b64c6c40de8e2ed2f8d73 /server_wss.hpp
parent4b0ad7ae76e4be4fa13bb3d51b87c9db09f78d40 (diff)
Initial commitv1.0
Diffstat (limited to 'server_wss.hpp')
-rw-r--r--server_wss.hpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/server_wss.hpp b/server_wss.hpp
new file mode 100644
index 0000000..ca1ca0a
--- /dev/null
+++ b/server_wss.hpp
@@ -0,0 +1,45 @@
+#ifndef SERVER_WSS_HPP
+#define SERVER_WSS_HPP
+
+#include "server_ws.hpp"
+#include <boost/asio/ssl.hpp>
+
+namespace SimpleWeb {
+ typedef boost::asio::ssl::stream<boost::asio::ip::tcp::socket> WSS;
+
+ template<>
+ class Server<WSS> : public SocketServerBase<WSS> {
+ public:
+ Server(unsigned short port, size_t num_threads, const std::string& cert_file, const std::string& private_key_file) :
+ SocketServerBase<WSS>::SocketServerBase(port, num_threads), context(boost::asio::ssl::context::sslv23) {
+ context.use_certificate_chain_file(cert_file);
+ context.use_private_key_file(private_key_file, boost::asio::ssl::context::pem);
+ }
+
+ private:
+ boost::asio::ssl::context context;
+
+ void accept() {
+ //Create new socket for this connection
+ //Shared_ptr is used to pass temporary objects to the asynchronous functions
+ std::shared_ptr<WSS> socket(new WSS(m_io_service, context));
+
+ acceptor.async_accept((*socket).lowest_layer(), [this, socket](const boost::system::error_code& ec) {
+ //Immediately start accepting a new connection
+ accept();
+
+ if(!ec) {
+ (*socket).async_handshake(boost::asio::ssl::stream_base::server, [this, socket](const boost::system::error_code& ec) {
+ if(!ec) {
+ process_request_and_start_connection(socket);
+ }
+ });
+ }
+ });
+ }
+ };
+}
+
+
+#endif /* SERVER_WSS_HPP */
+