1 /* 2 * Copyright (c) 2023 Unionman Technology Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef TCP_SERVER_H 17 #define TCP_SERVER_H 18 #include <boost/asio.hpp> 19 #include <boost/asio/ssl.hpp> 20 #include <string> 21 class TcpServer { 22 public: 23 explicit TcpServer(boost::asio::io_context& context); 24 ~TcpServer(); 25 26 protected: 27 boost::asio::ip::tcp::endpoint endpoint; 28 boost::asio::ip::tcp::acceptor accepter; 29 boost::asio::io_context& io_context; 30 boost::asio::ssl::context ssl_context; 31 boost::asio::ssl::stream<boost::asio::ip::tcp::socket>* ssl_socket; 32 void accept_handler(const boost::system::error_code& ec); 33 void handshake_handler(const boost::system::error_code& ec); 34 void write_handler(const boost::system::error_code& ec, std::size_t bytes_transferred); 35 std::string readjsonFile(const std::string path); 36 }; 37 #endif