From 36bfc0f42938453a24eb527f94fc210116ae7000 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Sun, 6 Sep 2020 18:32:44 +0800 Subject: [PATCH] crimson/net: move implementation into .cc file for faster compilation. Signed-off-by: Kefu Chai --- src/crimson/net/Socket.cc | 66 +++++++++++++++++++++++++++++++++++++++ src/crimson/net/Socket.h | 64 +++---------------------------------- 2 files changed, 70 insertions(+), 60 deletions(-) diff --git a/src/crimson/net/Socket.cc b/src/crimson/net/Socket.cc index 1aabd4ced42..5fa41e646bc 100644 --- a/src/crimson/net/Socket.cc +++ b/src/crimson/net/Socket.cc @@ -196,4 +196,70 @@ void Socket::set_trap(bp_type_t type, bp_action_t action, socket_blocker* blocke } #endif +seastar::future<> FixedCPUServerSocket::listen(entity_addr_t addr) +{ + assert(seastar::this_shard_id() == cpu); + logger().trace("FixedCPUServerSocket::listen({})...", addr); + return container().invoke_on_all([addr] (auto& ss) { + ss.addr = addr; + seastar::socket_address s_addr(addr.in4_addr()); + seastar::listen_options lo; + lo.reuse_address = true; + lo.set_fixed_cpu(ss.cpu); + ss.listener = seastar::listen(s_addr, lo); + }).handle_exception_type([addr] (const std::system_error& e) { + if (e.code() == std::errc::address_in_use) { + logger().trace("FixedCPUServerSocket::listen({}): address in use", addr); + throw; + } else { + logger().error("FixedCPUServerSocket::listen({}): " + "got unexpeted error {}", addr, e); + ceph_abort(); + } + }); +} + +seastar::future<> FixedCPUServerSocket::shutdown() +{ + assert(seastar::this_shard_id() == cpu); + logger().trace("FixedCPUServerSocket({})::shutdown()...", addr); + return container().invoke_on_all([] (auto& ss) { + if (ss.listener) { + ss.listener->abort_accept(); + } + return ss.shutdown_gate.close(); + }).then([this] { + return reset(); + }); +} + +seastar::future<> FixedCPUServerSocket::destroy() +{ + assert(seastar::this_shard_id() == cpu); + return shutdown().then([this] { + // we should only construct/stop shards on #0 + return container().invoke_on(0, [] (auto& ss) { + assert(ss.service); + return ss.service->stop().finally([cleanup = std::move(ss.service)] {}); + }); + }); +} + +seastar::future FixedCPUServerSocket::create() +{ + auto cpu = seastar::this_shard_id(); + // we should only construct/stop shards on #0 + return seastar::smp::submit_to(0, [cpu] { + auto service = std::make_unique(); + return service->start(cpu, construct_tag{} + ).then([service = std::move(service)] () mutable { + auto p_shard = service.get(); + p_shard->local().service = std::move(service); + return p_shard; + }); + }).then([] (auto p_shard) { + return &p_shard->local(); + }); +} + } // namespace crimson::net diff --git a/src/crimson/net/Socket.h b/src/crimson/net/Socket.h index f3d8bd8b6d7..8b05a884896 100644 --- a/src/crimson/net/Socket.h +++ b/src/crimson/net/Socket.h @@ -197,27 +197,7 @@ public: FixedCPUServerSocket(const FixedCPUServerSocket&) = delete; FixedCPUServerSocket& operator=(const FixedCPUServerSocket&) = delete; - seastar::future<> listen(entity_addr_t addr) { - assert(seastar::this_shard_id() == cpu); - logger().trace("FixedCPUServerSocket::listen({})...", addr); - return container().invoke_on_all([addr] (auto& ss) { - ss.addr = addr; - seastar::socket_address s_addr(addr.in4_addr()); - seastar::listen_options lo; - lo.reuse_address = true; - lo.set_fixed_cpu(ss.cpu); - ss.listener = seastar::listen(s_addr, lo); - }).handle_exception_type([addr] (const std::system_error& e) { - if (e.code() == std::errc::address_in_use) { - logger().trace("FixedCPUServerSocket::listen({}): address in use", addr); - throw; - } else { - logger().error("FixedCPUServerSocket::listen({}): " - "got unexpeted error {}", addr, e); - ceph_abort(); - } - }); - } + seastar::future<> listen(entity_addr_t addr); // fn_accept should be a nothrow function of type // seastar::future<>(SocketRef, entity_addr_t) @@ -277,45 +257,9 @@ public: }); } - seastar::future<> shutdown() { - assert(seastar::this_shard_id() == cpu); - logger().trace("FixedCPUServerSocket({})::shutdown()...", addr); - return container().invoke_on_all([] (auto& ss) { - if (ss.listener) { - ss.listener->abort_accept(); - } - return ss.shutdown_gate.close(); - }).then([this] { - return reset(); - }); - } - - seastar::future<> destroy() { - assert(seastar::this_shard_id() == cpu); - return shutdown().then([this] { - // we should only construct/stop shards on #0 - return container().invoke_on(0, [] (auto& ss) { - assert(ss.service); - return ss.service->stop().finally([cleanup = std::move(ss.service)] {}); - }); - }); - } - - static seastar::future create() { - auto cpu = seastar::this_shard_id(); - // we should only construct/stop shards on #0 - return seastar::smp::submit_to(0, [cpu] { - auto service = std::make_unique(); - return service->start(cpu, construct_tag{} - ).then([service = std::move(service)] () mutable { - auto p_shard = service.get(); - p_shard->local().service = std::move(service); - return p_shard; - }); - }).then([] (auto p_shard) { - return &p_shard->local(); - }); - } + seastar::future<> shutdown(); + seastar::future<> destroy(); + static seastar::future create(); }; } // namespace crimson::net -- 2.39.5