diff options
Diffstat (limited to 'Websocket')
-rw-r--r-- | Websocket/WebSocketService.cpp | 4 | ||||
-rw-r--r-- | Websocket/WebSocketService.h | 1 | ||||
-rw-r--r-- | Websocket/communication-protocol.cpp | 11 | ||||
-rw-r--r-- | Websocket/communication-protocol.h | 4 | ||||
-rw-r--r-- | Websocket/tcp-server.cpp | 48 | ||||
-rw-r--r-- | Websocket/tcp-server.h | 12 | ||||
-rw-r--r-- | Websocket/websocket-server.cpp | 8 |
7 files changed, 44 insertions, 44 deletions
diff --git a/Websocket/WebSocketService.cpp b/Websocket/WebSocketService.cpp index b2fd4e16..c4cc83ab 100644 --- a/Websocket/WebSocketService.cpp +++ b/Websocket/WebSocketService.cpp @@ -65,7 +65,9 @@ void* WebSocketService::listenWebsocket(void *webSocketServiceObject) std::string command((char *) data, size); - boost::trim(command); + std::stringstream trimmer; + trimmer << command; + trimmer >> command; std::cout << command << std::endl; diff --git a/Websocket/WebSocketService.h b/Websocket/WebSocketService.h index 9b084a24..631da4c9 100644 --- a/Websocket/WebSocketService.h +++ b/Websocket/WebSocketService.h @@ -18,7 +18,6 @@ #include "connection-pool.h" #include "query.h" #include "communication-protocol.h" -#include <boost/algorithm/string/trim.hpp> class WebSocketService diff --git a/Websocket/communication-protocol.cpp b/Websocket/communication-protocol.cpp index 99bcfa90..3e5f979c 100644 --- a/Websocket/communication-protocol.cpp +++ b/Websocket/communication-protocol.cpp @@ -16,7 +16,6 @@ #include "websocket-server.h" #include "communication-protocol.h" - /////////////////// //Explanation: A query can select/update 2 objects: // - Coordinates of a node @@ -34,7 +33,7 @@ std::set<std::string> ProtocolDetails::AllowedObjectName = {"stats"}; std::set<std::string> ProtocolDetails::AllowedActions = { "select", "subscribe"}; std::set<std::string> ProtocolDetails::AllowedFields = {"quality", "rate", "all"}; -std::function<void(const boost::system::error_code&)> CommunicationProtocol::timerCallback; +std::function<void(const std::error_code&)> CommunicationProtocol::timerCallback; CommunicationProtocol::CommunicationProtocol(ProtocolVersion version) : version(version) @@ -150,10 +149,10 @@ CommunicationProtocol::processQuery(Server *s, websocketpp::connection_hdl hdl, } else if (action == *ProtocolDetails::AllowedActions.find("subscribe")) { - subscribeTimer = std::shared_ptr<boost::asio::deadline_timer>(new boost::asio::deadline_timer(s->get_io_service(), - boost::posix_time::milliseconds(1000))); + subscribeTimer = std::shared_ptr<asio::steady_timer>(new asio::steady_timer(s->get_io_service(), + std::chrono::milliseconds(1000))); timerCallback = [this, s, hdl, msg, query] - (const boost::system::error_code &ec) { + (const std::error_code &ec) { if (!ec) { Query reply = this->makeReplyQuery(query); @@ -171,7 +170,7 @@ CommunicationProtocol::processQuery(Server *s, websocketpp::connection_hdl hdl, return; } - subscribeTimer->expires_from_now(boost::posix_time::milliseconds(1000)); + subscribeTimer->expires_from_now(std::chrono::milliseconds(1000)); subscribeTimer->async_wait(timerCallback); } }; diff --git a/Websocket/communication-protocol.h b/Websocket/communication-protocol.h index f3c488ef..25b15a6f 100644 --- a/Websocket/communication-protocol.h +++ b/Websocket/communication-protocol.h @@ -71,14 +71,14 @@ public: void setGraphDataSource(GraphDataSource *graphDataSource); - static std::function<void(const boost::system::error_code&)> timerCallback; + static std::function<void(const std::error_code&)> timerCallback; private: GraphDataSource *graphDataSource; ProtocolVersion version; - std::shared_ptr<boost::asio::deadline_timer> subscribeTimer; + std::shared_ptr<asio::steady_timer> subscribeTimer; }; diff --git a/Websocket/tcp-server.cpp b/Websocket/tcp-server.cpp index 4eb5d29d..cffd326b 100644 --- a/Websocket/tcp-server.cpp +++ b/Websocket/tcp-server.cpp @@ -35,11 +35,11 @@ TcpServer::start() if (io_service.stopped()) io_service.reset(); - boost::asio::ip::tcp::endpoint endpoint; - endpoint = boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), port); + asio::ip::tcp::endpoint endpoint; + endpoint = asio::ip::tcp::endpoint(asio::ip::tcp::v4(), port); acceptor.open(endpoint.protocol()); - acceptor.set_option(boost::asio::socket_base::reuse_address(true)); + acceptor.set_option(asio::socket_base::reuse_address(true)); acceptor.bind(endpoint); acceptor.listen(); @@ -47,10 +47,10 @@ TcpServer::start() //Set interrupt callbacks - boost::asio::io_service io_service; - boost::asio::signal_set signals(io_service, SIGINT, SIGQUIT); + asio::io_service io_service; + asio::signal_set signals(io_service, SIGINT, SIGQUIT); - signals.async_wait([this] (const boost::system::error_code &errorCode, int) { + signals.async_wait([this] (const std::error_code &errorCode, int) { std::cout << "Gracefully terminating tcp server" << std::endl; this->io_service.reset(); this->acceptor.cancel(); @@ -64,12 +64,12 @@ TcpServer::accept() { //Create new socket for this connection //Shared_ptr is used to pass temporary objects to the asynchronous functions - std::shared_ptr<boost::asio::ip::tcp::socket> socket(new boost::asio::ip::tcp::socket(io_service)); - acceptor.async_accept(*socket, [this, socket](const boost::system::error_code &ec) { + std::shared_ptr<asio::ip::tcp::socket> socket(new asio::ip::tcp::socket(io_service)); + acceptor.async_accept(*socket, [this, socket](const std::error_code &ec) { accept(); if (ec) { - if (ec == boost::asio::error::operation_aborted) // when the socket is closed by someone + if (ec == asio::error::operation_aborted) // when the socket is closed by someone return; } @@ -78,17 +78,17 @@ TcpServer::accept() } void -TcpServer::processIncomingData(std::shared_ptr<boost::asio::ip::tcp::socket> socket) +TcpServer::processIncomingData(std::shared_ptr<asio::ip::tcp::socket> socket) { // Set timeout on the following boost::asio::async-read or write function - std::shared_ptr<boost::asio::deadline_timer> timer; + std::shared_ptr<asio::steady_timer> timer; if (read_timeout > 0) timer = set_timeout_on_socket(socket, read_timeout); - std::shared_ptr<boost::asio::streambuf> buffer(new boost::asio::streambuf()); + std::shared_ptr<asio::streambuf> buffer(new asio::streambuf()); - boost::asio::async_read_until(*socket, *buffer, "\r\n\r\n", - [this, timer, buffer, socket](const boost::system::error_code& error, std::size_t bytes_transferred) { + asio::async_read_until(*socket, *buffer, "\r\n\r\n", + [this, timer, buffer, socket](const std::error_code& error, std::size_t bytes_transferred) { if (read_timeout > 0) timer->cancel(); @@ -99,14 +99,14 @@ TcpServer::processIncomingData(std::shared_ptr<boost::asio::ip::tcp::socket> soc std::size_t bufferSize = buffer->size(); buffer->commit(buffer->size()); - const uint8_t *data = boost::asio::buffer_cast<const uint8_t *>(buffer->data()); + const uint8_t *data = asio::buffer_cast<const uint8_t *>(buffer->data()); std::string reply = handler(data, bufferSize); if (reply != "") { - boost::asio::async_write(*socket, boost::asio::buffer(reply.c_str(), reply.size()), [this] - (boost::system::error_code ec, std::size_t /*length*/) + asio::async_write(*socket, asio::buffer(reply.c_str(), reply.size()), [this] + (std::error_code ec, std::size_t /*length*/) { if (!ec) { std::cout << "Reply sent!" << std::endl; @@ -120,16 +120,16 @@ TcpServer::processIncomingData(std::shared_ptr<boost::asio::ip::tcp::socket> soc } -std::shared_ptr<boost::asio::deadline_timer> -TcpServer::set_timeout_on_socket(std::shared_ptr<boost::asio::ip::tcp::socket> socket, long seconds) +std::shared_ptr<asio::steady_timer> +TcpServer::set_timeout_on_socket(std::shared_ptr<asio::ip::tcp::socket> socket, long seconds) { - std::shared_ptr<boost::asio::deadline_timer> timer(new boost::asio::deadline_timer(io_service)); - timer->expires_from_now(boost::posix_time::seconds(seconds)); - timer->async_wait([socket](const boost::system::error_code &ec) { + std::shared_ptr<asio::steady_timer> timer(new asio::steady_timer(io_service)); + timer->expires_from_now(std::chrono::seconds(seconds)); + timer->async_wait([socket](const std::error_code &ec) { if (!ec) { - boost::system::error_code ec; + std::error_code ec; std::cout << "Connection timeout!" << std::endl; - socket->lowest_layer().shutdown(boost::asio::ip::tcp::socket::shutdown_both, ec); + socket->lowest_layer().shutdown(asio::ip::tcp::socket::shutdown_both, ec); socket->lowest_layer().close(); } }); diff --git a/Websocket/tcp-server.h b/Websocket/tcp-server.h index f93d1b43..720d2c7e 100644 --- a/Websocket/tcp-server.h +++ b/Websocket/tcp-server.h @@ -17,8 +17,8 @@ #define TCP_SERVER_H #include <functional> -#include <boost/asio.hpp> #include <iostream> +#include <asio.hpp> typedef std::function<std::string(const uint8_t*, std::size_t)> HandlerFunction; @@ -43,14 +43,14 @@ private: accept(); void - processIncomingData(std::shared_ptr<boost::asio::ip::tcp::socket> socket); + processIncomingData(std::shared_ptr<asio::ip::tcp::socket> socket); - std::shared_ptr<boost::asio::deadline_timer> - set_timeout_on_socket(std::shared_ptr<boost::asio::ip::tcp::socket> socket, long seconds); + std::shared_ptr<asio::steady_timer> + set_timeout_on_socket(std::shared_ptr<asio::ip::tcp::socket> socket, long seconds); unsigned short port; - boost::asio::io_service io_service; - boost::asio::ip::tcp::acceptor acceptor; + asio::io_service io_service; + asio::ip::tcp::acceptor acceptor; long read_timeout; HandlerFunction handler; }; diff --git a/Websocket/websocket-server.cpp b/Websocket/websocket-server.cpp index ee79ccdb..58463caa 100644 --- a/Websocket/websocket-server.cpp +++ b/Websocket/websocket-server.cpp @@ -29,7 +29,7 @@ WebSocketServer::WebSocketServer(unsigned short port) server.set_message_handler(bind(&WebSocketServer::onMessage, this, &server, ::_1, ::_2)); // Listen on port - server.listen(boost::asio::ip::tcp::v4(),port); + server.listen(asio::ip::tcp::v4(),port); } catch (websocketpp::exception const & e) { std::cout << e.what() << std::endl; @@ -58,10 +58,10 @@ WebSocketServer::start() //Set interrupt callbacks - boost::asio::io_service io_service; - boost::asio::signal_set signals(server.get_io_service(), SIGINT, SIGQUIT); + asio::io_service io_service; + asio::signal_set signals(server.get_io_service(), SIGINT, SIGQUIT); - signals.async_wait([this](const boost::system::error_code &errorCode, int) { + signals.async_wait([this](const std::error_code &errorCode, int) { std::cout << "Gracefully terminating websocket server" << std::endl; this->m_isRunning = false; this->server.stop(); |