/* * Copyright (c) 2017-2023 zhllxt * * author : zhllxt * email : 37792738@qq.com * * Distributed under the Boost Software License, Version 1.0. (See accompanying * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) */ #ifndef __ASIO2_SOCKS5_SERVER_HPP__ #define __ASIO2_SOCKS5_SERVER_HPP__ #if defined(_MSC_VER) && (_MSC_VER >= 1200) #pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include #include #include namespace asio2::detail { ASIO2_CLASS_FORWARD_DECLARE_BASE; ASIO2_CLASS_FORWARD_DECLARE_TCP_BASE; ASIO2_CLASS_FORWARD_DECLARE_TCP_SERVER; template class socks5_server_impl_t : public tcp_server_impl_t { ASIO2_CLASS_FRIEND_DECLARE_BASE; ASIO2_CLASS_FRIEND_DECLARE_TCP_BASE; ASIO2_CLASS_FRIEND_DECLARE_TCP_SERVER; public: using super = tcp_server_impl_t ; using self = socks5_server_impl_t; using session_type = session_t; public: /** * @brief constructor */ template explicit socks5_server_impl_t(Args&&... args) : super(std::forward(args)...) { } /** * @brief destructor */ ~socks5_server_impl_t() { this->stop(); } /** * @brief start the server * @param host - A string identifying a location. May be a descriptive name or * a numeric address string. * @param service - A string identifying the requested service. This may be a * descriptive name or a numeric string corresponding to a port number. */ template inline bool start(String&& host, StrOrInt&& service, Args&&... args) { return this->derived()._do_start( std::forward(host), std::forward(service), ecs_helper::make_ecs(detail::socks5_server_match_role{}, std::forward(args)...)); } public: /** * @brief bind socks5 handshake listener * @param fun - a user defined callback function. * @param obj - a pointer or reference to a class object, this parameter can be none. * if fun is nonmember function, the obj param must be none, otherwise the obj must be the * the class object's pointer or reference. * Function signature : void(std::shared_ptr& session_ptr) */ template inline derived_t& bind_socks5_handshake(F&& fun, C&&... obj) { this->listener_.bind(event_type::upgrade, observer_t&>( std::forward(fun), std::forward(obj)...)); return (this->derived()); } }; } namespace asio2 { template using socks5_server_impl_t = detail::socks5_server_impl_t; /** * @brief socks5 tcp server * @throws constructor maybe throw exception "Too many open files" (exception code : 24) * asio::error::no_descriptors - Too many open files */ template class socks5_server_t : public detail::socks5_server_impl_t, session_t> { public: using detail::socks5_server_impl_t, session_t>::socks5_server_impl_t; }; /** * @brief socks5 tcp server * @throws constructor maybe throw exception "Too many open files" (exception code : 24) * asio::error::no_descriptors - Too many open files */ using socks5_server = socks5_server_t; } #include #endif // !__ASIO2_SOCKS5_SERVER_HPP__