Loading relayserver/CMakeLists.txt +1 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ add_executable( RelayServer.h RelayServer.cpp TcpProtocol.h TcpProtocol.cpp SpatialMap.h MsgPackProtocol.h WebsocketConnection.h WebsocketConnection.cpp ) target_link_libraries( Loading relayserver/RelayServer.cpp +16 −11 Original line number Diff line number Diff line Loading @@ -31,10 +31,15 @@ RelayServer::RelayServer() } ); msg.SetFrameCompleteCallback( [](uint64_t frame_id) _tcpProtocol.SetFrameCompleteCallback( [this](uint64_t frame_id) { std::cout << "frame " << frame_id << " complete." << std::endl; for (auto& it: _connections) { it.second.FrameComplete(frame_id, _tcpProtocol); } } ); Loading Loading @@ -73,7 +78,7 @@ int RelayServer::Run() { if (ev.data.fd == _clientSocket) { return msg.Read(_clientSocket); return _tcpProtocol.Read(_clientSocket); } else { Loading Loading @@ -112,7 +117,7 @@ bool RelayServer::OnConnectionEstablished(TcpSocket &socket) ); con->start(); _websocketConnections[socket.GetFileDescriptor()] = con; _connections.emplace(socket.GetFileDescriptor(), WebsocketConnection { socket.GetFileDescriptor(), con }); return true; } Loading @@ -120,21 +125,21 @@ bool RelayServer::OnConnectionClosed(TcpSocket &socket) { std::cerr << "connection to " << socket.GetPeer() << " closed." << std::endl; auto it = _websocketConnections.find(socket.GetFileDescriptor()); if (it == _websocketConnections.end()) auto it = _connections.find(socket.GetFileDescriptor()); if (it == _connections.end()) { return false; } it->second->eof(); _websocketConnections.erase(socket.GetFileDescriptor()); it->second.Eof(); _connections.erase(socket.GetFileDescriptor()); return true; } bool RelayServer::OnDataAvailable(TcpSocket &socket) { auto it = _websocketConnections.find(socket.GetFileDescriptor()); if (it == _websocketConnections.end()) auto it = _connections.find(socket.GetFileDescriptor()); if (it == _connections.end()) { return false; } Loading @@ -143,7 +148,7 @@ bool RelayServer::OnDataAvailable(TcpSocket &socket) ssize_t count = socket.Read(data, sizeof(data)); if (count > 0) { it->second->read_some(data, static_cast<size_t>(count)); it->second.DataReceived(data, static_cast<size_t>(count)); } return true; } Loading relayserver/RelayServer.h +3 −3 Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ #include <websocketpp/config/core.hpp> #include <websocketpp/server.hpp> #include "TcpProtocol.h" #include "WebsocketConnection.h" class RelayServer { Loading @@ -15,12 +16,11 @@ class RelayServer private: int _clientSocket; TcpServer _tcpServer; TcpProtocol msg; TcpProtocol _tcpProtocol; typedef websocketpp::server<websocketpp::config::core> WebsocketServer; WebsocketServer _websocketServer; std::map<int, WebsocketServer::connection_ptr> _websocketConnections; std::map<int, WebsocketConnection> _connections; bool OnConnectionEstablished(TcpSocket &socket); bool OnConnectionClosed(TcpSocket &socket); Loading relayserver/WebsocketConnection.cpp 0 → 100644 +21 −0 Original line number Diff line number Diff line #include "WebsocketConnection.h" WebsocketConnection::WebsocketConnection(int socket, WebsocketServer::connection_ptr websocket) : _socket(socket), _websocket(websocket) { } void WebsocketConnection::Eof() { _websocket->eof(); } void WebsocketConnection::DataReceived(const char *data, size_t count) { _websocket->read_some(data, count); } void WebsocketConnection::FrameComplete(uint64_t frame_id, const TcpProtocol &proto) { } relayserver/WebsocketConnection.h 0 → 100644 +23 −0 Original line number Diff line number Diff line #pragma once #include <websocketpp/config/core.hpp> #include <websocketpp/server.hpp> class TcpProtocol; class WebsocketConnection { public: typedef websocketpp::server<websocketpp::config::core> WebsocketServer; WebsocketConnection(int socket, WebsocketServer::connection_ptr websocket); void Eof(); void DataReceived(const char *data, size_t count); void FrameComplete(uint64_t frame_id, const TcpProtocol& proto); private: int _socket; WebsocketServer::connection_ptr _websocket; bool _firstFrameSent = false; }; Loading
relayserver/CMakeLists.txt +1 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ add_executable( RelayServer.h RelayServer.cpp TcpProtocol.h TcpProtocol.cpp SpatialMap.h MsgPackProtocol.h WebsocketConnection.h WebsocketConnection.cpp ) target_link_libraries( Loading
relayserver/RelayServer.cpp +16 −11 Original line number Diff line number Diff line Loading @@ -31,10 +31,15 @@ RelayServer::RelayServer() } ); msg.SetFrameCompleteCallback( [](uint64_t frame_id) _tcpProtocol.SetFrameCompleteCallback( [this](uint64_t frame_id) { std::cout << "frame " << frame_id << " complete." << std::endl; for (auto& it: _connections) { it.second.FrameComplete(frame_id, _tcpProtocol); } } ); Loading Loading @@ -73,7 +78,7 @@ int RelayServer::Run() { if (ev.data.fd == _clientSocket) { return msg.Read(_clientSocket); return _tcpProtocol.Read(_clientSocket); } else { Loading Loading @@ -112,7 +117,7 @@ bool RelayServer::OnConnectionEstablished(TcpSocket &socket) ); con->start(); _websocketConnections[socket.GetFileDescriptor()] = con; _connections.emplace(socket.GetFileDescriptor(), WebsocketConnection { socket.GetFileDescriptor(), con }); return true; } Loading @@ -120,21 +125,21 @@ bool RelayServer::OnConnectionClosed(TcpSocket &socket) { std::cerr << "connection to " << socket.GetPeer() << " closed." << std::endl; auto it = _websocketConnections.find(socket.GetFileDescriptor()); if (it == _websocketConnections.end()) auto it = _connections.find(socket.GetFileDescriptor()); if (it == _connections.end()) { return false; } it->second->eof(); _websocketConnections.erase(socket.GetFileDescriptor()); it->second.Eof(); _connections.erase(socket.GetFileDescriptor()); return true; } bool RelayServer::OnDataAvailable(TcpSocket &socket) { auto it = _websocketConnections.find(socket.GetFileDescriptor()); if (it == _websocketConnections.end()) auto it = _connections.find(socket.GetFileDescriptor()); if (it == _connections.end()) { return false; } Loading @@ -143,7 +148,7 @@ bool RelayServer::OnDataAvailable(TcpSocket &socket) ssize_t count = socket.Read(data, sizeof(data)); if (count > 0) { it->second->read_some(data, static_cast<size_t>(count)); it->second.DataReceived(data, static_cast<size_t>(count)); } return true; } Loading
relayserver/RelayServer.h +3 −3 Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ #include <websocketpp/config/core.hpp> #include <websocketpp/server.hpp> #include "TcpProtocol.h" #include "WebsocketConnection.h" class RelayServer { Loading @@ -15,12 +16,11 @@ class RelayServer private: int _clientSocket; TcpServer _tcpServer; TcpProtocol msg; TcpProtocol _tcpProtocol; typedef websocketpp::server<websocketpp::config::core> WebsocketServer; WebsocketServer _websocketServer; std::map<int, WebsocketServer::connection_ptr> _websocketConnections; std::map<int, WebsocketConnection> _connections; bool OnConnectionEstablished(TcpSocket &socket); bool OnConnectionClosed(TcpSocket &socket); Loading
relayserver/WebsocketConnection.cpp 0 → 100644 +21 −0 Original line number Diff line number Diff line #include "WebsocketConnection.h" WebsocketConnection::WebsocketConnection(int socket, WebsocketServer::connection_ptr websocket) : _socket(socket), _websocket(websocket) { } void WebsocketConnection::Eof() { _websocket->eof(); } void WebsocketConnection::DataReceived(const char *data, size_t count) { _websocket->read_some(data, count); } void WebsocketConnection::FrameComplete(uint64_t frame_id, const TcpProtocol &proto) { }
relayserver/WebsocketConnection.h 0 → 100644 +23 −0 Original line number Diff line number Diff line #pragma once #include <websocketpp/config/core.hpp> #include <websocketpp/server.hpp> class TcpProtocol; class WebsocketConnection { public: typedef websocketpp::server<websocketpp::config::core> WebsocketServer; WebsocketConnection(int socket, WebsocketServer::connection_ptr websocket); void Eof(); void DataReceived(const char *data, size_t count); void FrameComplete(uint64_t frame_id, const TcpProtocol& proto); private: int _socket; WebsocketServer::connection_ptr _websocket; bool _firstFrameSent = false; };