| 171 | public: |
| 172 | template <typename FuncC, typename FuncS> |
| 173 | static future<> dispatch_sockets( |
| 174 | bool is_fixed_cpu, |
| 175 | FuncC&& cb_client, |
| 176 | FuncS&& cb_server) { |
| 177 | ceph_assert_always(seastar::this_shard_id() == CLIENT_CPU); |
| 178 | auto owner = std::make_unique<SocketFactory>(); |
| 179 | auto psf = owner.get(); |
| 180 | auto saddr = get_server_addr(); |
| 181 | return seastar::smp::submit_to(SERVER_CPU, [psf, saddr, is_fixed_cpu] { |
| 182 | return ShardedServerSocket::create(is_fixed_cpu |
| 183 | ).then([psf, saddr](auto pss) { |
| 184 | psf->pss = pss; |
| 185 | return pss->listen(saddr |
| 186 | ).safe_then([] { |
| 187 | }, listen_ertr::assert_all_func( |
| 188 | [saddr](const std::error_code& e) { |
| 189 | logger().error("dispatch_sockets(): there is another instance running at {}", |
| 190 | saddr); |
| 191 | })); |
| 192 | }); |
| 193 | }).then([psf, saddr] { |
| 194 | return seastar::when_all_succeed( |
| 195 | seastar::smp::submit_to(CLIENT_CPU, [psf, saddr] { |
| 196 | return socket_connect(saddr).then([psf](auto socket) { |
| 197 | ceph_assert_always(seastar::this_shard_id() == CLIENT_CPU); |
| 198 | psf->client_socket = std::move(socket); |
| 199 | }); |
| 200 | }), |
| 201 | seastar::smp::submit_to(SERVER_CPU, [psf] { |
| 202 | return psf->pss->accept([psf](auto _socket, auto paddr) { |
| 203 | logger().info("dispatch_sockets(): accepted at shard {}", |
| 204 | seastar::this_shard_id()); |
| 205 | psf->server_socket_CPU = seastar::this_shard_id(); |
| 206 | if (psf->pss->is_fixed_shard_dispatching()) { |
| 207 | ceph_assert_always(SERVER_CPU == seastar::this_shard_id()); |
| 208 | } |
| 209 | SocketFRef socket = seastar::make_foreign(std::move(_socket)); |
| 210 | psf->server_socket = std::move(socket); |
| 211 | return seastar::smp::submit_to(CLIENT_CPU, [psf] { |
| 212 | psf->server_connected.set_value(); |
| 213 | }); |
| 214 | }); |
| 215 | }) |
| 216 | ); |
| 217 | }).then_unpack([] { |
| 218 | return seastar::now(); |
| 219 | }).then([psf] { |
| 220 | return psf->server_connected.get_future(); |
| 221 | }).then([psf] { |
| 222 | if (psf->pss) { |
| 223 | return seastar::smp::submit_to(SERVER_CPU, [psf] { |
| 224 | return psf->pss->shutdown_destroy(); |
| 225 | }); |
| 226 | } |
| 227 | return seastar::now(); |
| 228 | }).then([psf, |
| 229 | cb_client = std::move(cb_client), |
| 230 | cb_server = std::move(cb_server)]() mutable { |
nothing calls this directly
no test coverage detected