6 #include <absl/types/optional.h> 8 #include <boost/asio/ip/tcp.hpp> 9 #include <boost/intrusive/list.hpp> 10 #include <boost/intrusive/slist_hook.hpp> 11 #include <boost/smart_ptr/intrusive_ptr.hpp> 13 #include "util/asio/fiber_socket.h" 22 using namespace ::boost::intrusive;
27 typedef slist_member_hook<link_mode<auto_unlink>> connection_hook;
37 using connection_hook_t = detail::connection_hook;
39 connection_hook_t hook_;
40 connection_hook_t flush_hook_;
43 using ptr_t = ::boost::intrusive_ptr<ConnectionHandler>;
44 using io_context = ::boost::asio::io_context;
47 detail::member_hook<ConnectionHandler, detail::connection_hook, &ConnectionHandler::hook_>;
49 using flush_hook_t = detail::member_hook<
ConnectionHandler, detail::connection_hook,
50 &ConnectionHandler::flush_hook_>;
56 void Init(::boost::asio::ip::tcp::socket&& sock);
65 ctx->use_count_.fetch_add(1, std::memory_order_relaxed);
69 if (1 == ctx->use_count_.fetch_sub(1, std::memory_order_release)) {
79 std::atomic_thread_fence(std::memory_order_acquire);
105 virtual boost::system::error_code HandleRequest() = 0;
107 absl::optional<FiberSyncSocket> socket_;
116 void RunInIOThread();
118 std::atomic<std::uint32_t> use_count_{0};
136 virtual void PreShutdown() {
140 virtual void PostShutdown() {
virtual void OnCloseSocket()
Called before ConnectionHandler destroyed but after the socket was signalled to stop and shutdown.
Abstracts away connections implementation and their life-cycle.
A pool of IoContext objects, representing and managing CPU resources of the system.
virtual void OnOpenSocket()
Called once after connection was initialized. Will run in io context thread of this handler.
virtual bool FlushWrites()
Called to flush pending writes to the socket. Returns true if flush took place,.