23#include <seastar/core/format.hh>
24#include <seastar/core/function_traits.hh>
25#include <seastar/core/shared_ptr.hh>
26#include <seastar/core/sstring.hh>
27#include <seastar/core/when_all.hh>
28#include <seastar/util/is_smart_ptr.hh>
29#include <seastar/core/simple-stream.hh>
30#include <seastar/net/packet-data-source.hh>
32#include <boost/type.hpp>
38enum class exception_type : uint32_t {
64template <
typename Ret,
typename... In>
67 using arg_types = std::tuple<In...>;
74template <
typename Ret,
typename... In>
77 using arg_types = std::tuple<In...>;
83template <
typename Ret,
typename... In>
86 using arg_types = std::tuple<In...>;
93template <
typename Ret,
typename... In>
96 using arg_types = std::tuple<In...>;
102template <
typename Ret,
typename... In>
104 using ret_type = Ret;
105 using arg_types = std::tuple<In...>;
112template <
typename Ret,
typename... In>
114 using ret_type = Ret;
115 using arg_types = std::tuple<In...>;
124 using cleaned_type = T;
127template <
typename... T>
136 using cleaned_type = void;
148template <
typename... In>
152 return std::move(args);
155template <
typename... In>
157std::tuple<std::reference_wrapper<client_info>, In...>
158maybe_add_client_info(do_want_client_info, client_info& ci, std::tuple<In...>&& args) {
159 return std::tuple_cat(std::make_tuple(
std::ref(ci)), std::move(args));
162template <
typename... In>
165maybe_add_time_point(dont_want_time_point, opt_time_point&, std::tuple<In...>&& args) {
166 return std::move(args);
169template <
typename... In>
171std::tuple<opt_time_point, In...>
172maybe_add_time_point(do_want_time_point, opt_time_point& otp, std::tuple<In...>&& args) {
173 return std::tuple_cat(std::make_tuple(otp), std::move(args));
176inline sstring serialize_connection_id(
const connection_id&
id) {
177 sstring p = uninitialized_string(
sizeof(
id));
179 write_le(c,
id.
id());
183inline connection_id deserialize_connection_id(
const sstring& s) {
184 using id_type =
decltype(connection_id{0}.id());
186 auto id = read_le<id_type>(p);
187 return connection_id{
id};
190template <
bool IsSmartPtr>
195 template <
typename Serializer,
typename Output,
typename T>
196 static inline void serialize(Serializer& serializer, Output& out,
const T& t) {
197 return write(serializer, out, t);
203 template <
typename Serializer,
typename Output,
typename T>
204 static inline void serialize(Serializer& serializer, Output& out,
const T& t) {
205 return write(serializer, out, *t);
209template <
typename Serializer,
typename Output,
typename... T>
210inline void do_marshall(Serializer& serializer, Output& out,
const T&... args);
212template <
typename Serializer,
typename Output>
215 static void doit(Serializer& serializer, Output& out,
const T& arg) {
217 serialize_helper_type::serialize(serializer, out, arg);
221 static void doit(Serializer& serializer, Output& out,
const std::reference_wrapper<const T>& arg) {
225 static void put_connection_id(
const connection_id& cid, Output& out) {
226 sstring
id = serialize_connection_id(cid);
227 out.write(
id.c_str(),
id.size());
230 static void doit(Serializer&, Output& out,
const sink<T...>& arg) {
231 put_connection_id(arg.get_id(), out);
235 static void doit(Serializer&, Output& out,
const source<T...>& arg) {
236 put_connection_id(arg.get_id(), out);
240 static void doit(Serializer& serializer, Output& out,
const tuple<T...>& arg) {
241 auto do_do_marshall = [&serializer, &out] (
const auto&... args) {
242 do_marshall(serializer, out, args...);
248 std::apply(do_do_marshall,
static_cast<const std::tuple<T...
>&>(arg));
253template <
typename Serializer,
typename Output,
typename... T>
254inline void do_marshall(Serializer& serializer, Output& out,
const T&... args) {
259static inline memory_output_stream<snd_buf::iterator> make_serializer_stream(snd_buf& output) {
260 auto* b = std::get_if<temporary_buffer<char>>(&output.bufs);
262 return memory_output_stream<snd_buf::iterator>(memory_output_stream<snd_buf::iterator>::simple(b->get_write(), b->size()));
264 auto& ar = std::get<std::vector<temporary_buffer<char>>>(output.bufs);
265 return memory_output_stream<snd_buf::iterator>(memory_output_stream<snd_buf::iterator>::fragmented(ar.begin(), output.size));
269template <
typename Serializer,
typename... T>
270inline snd_buf marshall(Serializer& serializer,
size_t head_space,
const T&... args) {
271 measuring_output_stream measure;
272 do_marshall(serializer, measure, args...);
273 snd_buf ret(measure.size() + head_space);
274 auto out = make_serializer_stream(ret);
275 out.skip(head_space);
276 do_marshall(serializer, out, args...);
280template <
typename Serializer,
typename Input,
typename... T>
281std::tuple<T...> do_unmarshall(connection& c, Input& in);
290template <
typename T,
typename... Args>
291requires requires (Args... args, type<T> t) { read(std::forward<Args>(args)..., t); }
293read_via_type_marker(Args&&... args) {
294 return read(std::forward<Args>(args)..., type<T>());
297template <
typename T,
typename... Args>
298requires requires (Args... args, boost::type<T> t) { read(std::forward<Args>(args)..., t); }
299[[deprecated(
"Use rpc::type<> instead of boost::type<>")]]
301read_via_type_marker(Args&&... args) {
302 return read(std::forward<Args>(args)..., boost::type<T>());
305template<
typename Serializer,
typename Input>
309 return read_via_type_marker<T>(c.serializer<Serializer>(), in);
315 return optional<T>(read_via_type_marker<
typename remove_optional<T>::type>(c.serializer<Serializer>(), in));
329 return deserialize_connection_id(
id);
333 return sink<T...>(make_shared<
sink_impl<Serializer, T...>>(c.get_stream(get_connection_id(in))));
338 return source<T...>(make_shared<
source_impl<Serializer, T...>>(c.get_stream(get_connection_id(in))));
343 return do_unmarshall<Serializer, Input, T...>(c, in);
348template <
typename... T>
353 using type = std::tuple<>;
356template <
typename T0,
typename... T>
358 using type = std::tuple<
361 std::is_default_constructible_v<T>,
368template <
typename... T>
372template <
typename... Tout,
typename... Tin>
374unwrap_optional_if_needed(std::tuple<Tin...>&& tuple_in) {
375 using tuple_in_t = std::tuple<Tin...>;
376 using tuple_out_t = std::tuple<Tout...>;
377 return std::invoke([&] <
size_t... Idx> (std::index_sequence<Idx...>) {
380 if constexpr (std::same_as<std::tuple_element_t<Idx, tuple_in_t>, std::tuple_element_t<Idx, tuple_out_t>>) {
381 return std::move(std::get<Idx>(tuple_in));
383 return std::move(std::get<Idx>(tuple_in).value());
386 }, std::make_index_sequence<
sizeof...(Tout)>());
389template <
typename Serializer,
typename Input,
typename... T>
390inline std::tuple<T...> do_unmarshall(connection& c, Input& in) {
403 using ret_type = std::tuple<T...>;
404 using temporary_type = default_constructible_tuple_except_first_t<T...>;
405 return std::invoke([&] <
size_t... Idx> (std::index_sequence<Idx...>) {
406 auto tmp = temporary_type(
407 std::invoke([&] () -> std::tuple_element_t<Idx, temporary_type> {
408 if constexpr (Idx == 0) {
410 return unmarshal_one<Serializer, Input>::template helper<std::tuple_element_t<Idx, ret_type>>::doit(c, in);
418 (void)(..., ((Idx == 0
420 : ((std::get<Idx>(tmp) = unmarshal_one<Serializer, Input>::template helper<std::tuple_element_t<Idx, ret_type>>::doit(c, in), 0)))));
421 if constexpr (std::same_as<ret_type, temporary_type>) {
425 return unwrap_optional_if_needed<T...>(std::move(tmp));
427 }, std::index_sequence_for<T...>());
430template <
typename Serializer,
typename... T>
431inline std::tuple<T...> unmarshall(connection& c, rcv_buf input) {
432 auto in = make_deserializer_stream(input);
433 return do_unmarshall<Serializer,
decltype(in), T...>(c, in);
436inline std::exception_ptr unmarshal_exception(rcv_buf& d) {
437 std::exception_ptr ex;
438 auto data = make_deserializer_stream(d);
441 data.read(
reinterpret_cast<char*
>(&v32), 4);
442 exception_type ex_type = exception_type(le_to_cpu(v32));
443 data.read(
reinterpret_cast<char*
>(&v32), 4);
444 uint32_t ex_len = le_to_cpu(v32);
447 case exception_type::USER: {
448 std::string s(ex_len,
'\0');
449 data.read(&*s.begin(), ex_len);
450 ex = std::make_exception_ptr(remote_verb_error(std::move(s)));
453 case exception_type::UNKNOWN_VERB: {
455 data.read(
reinterpret_cast<char*
>(&v64), 8);
456 ex = std::make_exception_ptr(unknown_verb_error(le_to_cpu(v64)));
460 ex = std::make_exception_ptr(unknown_exception_error());
466template <
typename Payload,
typename... T>
470 template<
typename... V>
471 void set_value(V&&... v) {
473 p.
set_value(internal::untuple(std::forward<V>(v))...);
482template<
typename Serializer,
typename T>
485 this->set_value(unmarshall<Serializer, T>(dst, std::move(input)));
489template<
typename Serializer,
typename... T>
492 this->set_value(unmarshall<Serializer, T...>(dst, std::move(input)));
496template<
typename Serializer>
503template<
typename Serializer>
506template <
typename Serializer,
typename Ret,
typename... InArgs>
507inline auto wait_for_reply(
wait_type, std::optional<rpc_clock_type::time_point> timeout, rpc_clock_type::time_point start,
cancellable* cancel,
rpc::client& dst, id_type msg_id,
510 auto lambda = [] (reply_type& r,
rpc::client& dst, id_type msg_id,
rcv_buf data)
mutable {
512 dst.get_stats_internal().replied++;
513 return r.get_reply(dst, std::move(data));
515 dst.get_stats_internal().exception_received++;
517 r.p.set_exception(unmarshal_exception(data));
520 using handler_type =
typename rpc::client::template reply_handler<reply_type,
decltype(lambda)>;
521 auto r = std::make_unique<handler_type>(std::move(lambda));
523 auto fut = r->reply.p.get_future();
524 dst.wait_for_reply(msg_id, std::move(r), timeout, cancel);
528template<
typename Serializer,
typename... InArgs>
529inline auto wait_for_reply(no_wait_type, std::optional<rpc_clock_type::time_point>, rpc_clock_type::time_point start, cancellable*, rpc::client&, id_type,
530 signature<no_wait_type (InArgs...)>) {
531 return make_ready_future<>();
534template<
typename Serializer,
typename... InArgs>
535inline auto wait_for_reply(no_wait_type, std::optional<rpc_clock_type::time_point>, rpc_clock_type::time_point, cancellable*, rpc::client&, id_type,
536 signature<future<no_wait_type> (InArgs...)>) {
537 return make_ready_future<>();
543inline rpc_clock_type::time_point
544relative_timeout_to_absolute(rpc_clock_type::duration relative) {
546 return now + std::min(relative, rpc_clock_type::time_point::max() -
now);
550static constexpr size_t request_frame_headroom = 28;
556template<
typename Serializer,
typename MsgType,
typename Ret,
typename... InArgs>
557auto send_helper(MsgType xt, signature<Ret (InArgs...)> xsig) {
560 signature<Ret (InArgs...)> sig;
561 auto send(rpc::client& dst, std::optional<rpc_clock_type::time_point> timeout, cancellable* cancel,
const InArgs&... args) {
563 using cleaned_ret_type =
typename wait_signature<Ret>::cleaned_type;
564 return futurize<cleaned_ret_type>::make_exception_future(closed_error());
569 auto msg_id = dst.next_message_id();
570 snd_buf data = marshall(dst.template serializer<Serializer>(), request_frame_headroom, args...);
573 using wait = wait_signature_t<Ret>;
574 return when_all(dst.request(uint64_t(t), msg_id, std::move(data), timeout, cancel), wait_for_reply<Serializer>(wait(), timeout, start, cancel, dst, msg_id, sig)).then([] (
auto r) {
575 std::get<0>(r).ignore_ready_future();
576 return std::move(std::get<1>(r));
579 auto operator()(rpc::client& dst,
const InArgs&... args) {
580 return send(dst, {},
nullptr, args...);
582 auto operator()(rpc::client& dst, rpc_clock_type::time_point timeout,
const InArgs&... args) {
583 return send(dst, timeout,
nullptr, args...);
585 auto operator()(rpc::client& dst, rpc_clock_type::duration timeout,
const InArgs&... args) {
586 return send(dst, relative_timeout_to_absolute(timeout),
nullptr, args...);
588 auto operator()(rpc::client& dst, cancellable& cancel,
const InArgs&... args) {
589 return send(dst, {}, &cancel, args...);
593 return shelper{xt, xsig};
597static constexpr size_t response_frame_headroom = 16;
599template<
typename Serializer,
typename RetTypes>
600inline future<> reply(wait_type, future<RetTypes>&& ret, int64_t msg_id, shared_ptr<server::connection> client,
601 std::optional<rpc_clock_type::time_point> timeout, std::optional<rpc_clock_type::duration> handler_duration) {
602 if (!client->error()) {
605 if constexpr (std::is_void_v<RetTypes>) {
607 data = std::invoke(marshall<Serializer>,
std::ref(client->template serializer<Serializer>()), response_frame_headroom);
609 data = std::invoke(marshall<Serializer, const RetTypes&>,
std::ref(client->template serializer<Serializer>()), response_frame_headroom, std::move(ret.get()));
611 }
catch (std::exception& ex) {
612 uint32_t len = std::strlen(ex.what());
613 data = snd_buf(response_frame_headroom + 2 *
sizeof(uint32_t) + len);
614 auto os = make_serializer_stream(data);
615 os.skip(response_frame_headroom);
616 uint32_t v32 = cpu_to_le(uint32_t(exception_type::USER));
617 os.write(
reinterpret_cast<char*
>(&v32),
sizeof(v32));
618 v32 = cpu_to_le(len);
619 os.write(
reinterpret_cast<char*
>(&v32),
sizeof(v32));
620 os.write(ex.what(), len);
624 return client->respond(msg_id, std::move(data), timeout, handler_duration);
626 ret.ignore_ready_future();
627 return make_ready_future<>();
632template<
typename Serializer>
633inline future<> reply(no_wait_type, future<no_wait_type>&& r, int64_t msgid, shared_ptr<server::connection> client,
634 std::optional<rpc_clock_type::time_point>, std::optional<rpc_clock_type::duration>) {
637 }
catch (std::exception& ex) {
638 client->get_logger()(client->info(), msgid, to_sstring(
"exception \"") + ex.what() +
"\" in no_wait handler ignored");
640 return make_ready_future<>();
643template<
typename Ret,
typename... InArgs,
typename WantClientInfo,
typename WantTimePoint,
typename Func,
typename ArgsTuple>
644inline futurize_t<Ret> apply(Func& func, client_info& info, opt_time_point time_point, WantClientInfo wci, WantTimePoint wtp, signature<Ret (InArgs...)>, ArgsTuple&& args) {
645 using futurator = futurize<Ret>;
646 return futurator::apply(func, maybe_add_client_info(wci, info, maybe_add_time_point(wtp, time_point, std::forward<ArgsTuple>(args))));
651auto lref_to_cref(T&& x) {
656auto lref_to_cref(T& x) {
662template <
typename Serializer,
typename Func,
typename Ret,
typename... InArgs,
typename WantClientInfo,
typename WantTimePoint>
663auto recv_helper(signature<Ret (InArgs...)> sig, Func&& func, WantClientInfo, WantTimePoint) {
664 using signature =
decltype(sig);
665 using wait_style = wait_signature_t<Ret>;
666 return [func = lref_to_cref(std::forward<Func>(func))](shared_ptr<server::connection> client,
667 std::optional<rpc_clock_type::time_point> timeout,
670 gate::holder guard)
mutable {
671 auto memory_consumed = client->estimate_request_size(data.size);
672 if (memory_consumed > client->max_request_size()) {
673 auto err =
format(
"request size {:d} large than memory limit {:d}", memory_consumed, client->max_request_size());
674 client->get_logger()(client->peer_address(), err);
676 (void)try_with_gate(client->get_server().reply_gate(), [client, timeout, msg_id, err = std::move(err)] {
677 return reply<Serializer>(wait_style(), futurize<Ret>::make_exception_future(std::runtime_error(err.c_str())), msg_id, client, timeout, std::nullopt).handle_exception([client, msg_id] (std::exception_ptr eptr) {
678 client->get_logger()(client->info(), msg_id,
format(
"got exception while processing an oversized message: {}", eptr));
680 }).handle_exception_type([] (gate_closed_exception&) {});
684 auto f = client->wait_for_resources(memory_consumed, timeout).then([client, timeout, msg_id, data = std::move(data), &func, g = std::move(guard)] (
auto permit)
mutable {
686 (void)try_with_gate(client->get_server().reply_gate(), [client, timeout, msg_id, data = std::move(data), permit = std::move(permit), &func] ()
mutable {
688 auto args = unmarshall<Serializer, InArgs...>(*client, std::move(data));
689 auto start = rpc_clock_type::now();
690 return apply(func, client->info(), timeout, WantClientInfo(), WantTimePoint(), signature(), std::move(args)).then_wrapped([client, timeout, msg_id, permit = std::move(permit), start] (futurize_t<Ret> ret) mutable {
691 return reply<Serializer>(wait_style(), std::move(ret), msg_id, client, timeout, rpc_clock_type::now() - start).handle_exception([permit = std::move(permit), client, msg_id] (std::exception_ptr eptr) {
692 client->get_logger()(client->info(), msg_id, format(
"got exception while processing a message: {}", eptr));
696 client->get_logger()(client->info(), msg_id,
format(
"caught exception while processing a message: {}", std::current_exception()));
699 }).handle_exception_type([g = std::move(g)] (gate_closed_exception&) {});
703 f = f.handle_exception_type([] (semaphore_timed_out&) { });
711template<
typename Func>
712auto make_copyable_function(Func&& func, std::enable_if_t<!std::is_copy_constructible_v<std::decay_t<Func>>,
void*> =
nullptr) {
713 auto p = make_lw_shared<typename std::decay_t<Func>>(std::forward<Func>(func));
714 return [p] (
auto&&... args) {
return (*p)( std::forward<decltype(args)>(args)... ); };
717template<
typename Func>
718auto make_copyable_function(Func&& func, std::enable_if_t<std::is_copy_constructible_v<std::decay_t<Func>>,
void*> =
nullptr) {
719 return std::forward<Func>(func);
729template<
typename Ret,
typename... In>
731 template<
typename T,
bool IsSmartPtr>
732 struct drop_smart_ptr_impl;
734 struct drop_smart_ptr_impl<T, true> {
735 using type =
typename T::element_type;
738 struct drop_smart_ptr_impl<T, false> {
742 using drop_smart_ptr = drop_smart_ptr_impl<T, is_smart_ptr<T>::value>;
745 using return_type =
typename drop_smart_ptr<Ret>::type;
747 using type = return_type(
typename remove_optional<In>::type...);
750template<
typename Serializer,
typename MsgType>
751template<
typename Ret,
typename... In>
754 return send_helper<Serializer>(t, sig_type());
757template<
typename Serializer,
typename MsgType>
758template<
typename Func>
763template<
typename Serializer,
typename MsgType>
764template<
typename Func>
767 using clean_sig_type =
typename sig_type::clean;
768 using want_client_info =
typename sig_type::want_client_info;
769 using want_time_point =
typename sig_type::want_time_point;
770 auto recv = recv_helper<Serializer>(clean_sig_type(), std::forward<Func>(func),
771 want_client_info(), want_time_point());
772 register_receiver(t,
rpc_handler{sg, make_copyable_function(std::move(recv)), {}});
773 return make_client(clean_sig_type(), t);
776template<
typename Serializer,
typename MsgType>
777template<
typename Func>
782template<
typename Serializer,
typename MsgType>
784 auto it = _handlers.find(t);
785 if (it != _handlers.end()) {
786 return it->second.use_gate.close().finally([
this, t] {
790 return make_ready_future<>();
793template<
typename Serializer,
typename MsgType>
795 auto it = _handlers.find(msg_id);
796 if (it == _handlers.end()) {
799 return !it->second.use_gate.is_closed();
802template<
typename Serializer,
typename MsgType>
803std::optional<protocol_base::handler_with_holder> protocol<Serializer, MsgType>::get_handler(uint64_t msg_id) {
804 const auto it = _handlers.find(MsgType(msg_id));
805 if (it != _handlers.end()) {
807 return handler_with_holder{it->second, it->second.use_gate.hold()};
808 }
catch (gate_closed_exception&) {
815template<
typename T> T make_shard_local_buffer_copy(foreign_ptr<std::unique_ptr<T>> org);
817template<
typename Serializer,
typename... Out>
818future<> sink_impl<Serializer, Out...>::operator()(
const Out&... args) {
821 snd_buf data = marshall(this->_con->get()->template serializer<Serializer>(), 4, args...);
822 static_assert(snd_buf::chunk_size >= 4,
"send buffer chunk size is too small");
823 auto p = data.front().get_write();
824 write_le<uint32_t>(p, data.size - 4);
827 auto size = std::min(
size_t(data.size), max_stream_buffers_memory);
828 const auto seq_num = _next_seq_num++;
829 return get_units(this->_sem, size).then([
this, data = make_foreign(std::make_unique<snd_buf>(std::move(data))), seq_num] (semaphore_units<> su)
mutable {
835 (void)
smp::submit_to(this->_con->get_owner_shard(), [
this, data = std::move(data), seq_num] ()
mutable {
836 connection* con = this->_con->get();
840 if(con->sink_closed()) {
844 auto& last_seq_num = _remote_state.last_seq_num;
845 auto& out_of_order_bufs = _remote_state.out_of_order_bufs;
847 auto local_data = make_shard_local_buffer_copy(std::move(data));
848 const auto seq_num_diff = seq_num - last_seq_num;
849 if (seq_num_diff > 1) {
850 auto [it, _] = out_of_order_bufs.emplace(seq_num, deferred_snd_buf{
promise<>{}, std::move(local_data)});
851 return it->second.pr.get_future();
854 last_seq_num = seq_num;
855 auto ret_fut = con->send(std::move(local_data), {},
nullptr);
856 while (!out_of_order_bufs.empty() && out_of_order_bufs.begin()->first == (last_seq_num + 1)) {
857 auto it = out_of_order_bufs.begin();
858 last_seq_num = it->first;
859 auto fut = con->send(std::move(it->second.data), {},
nullptr);
860 fut.forward_to(std::move(it->second.pr));
861 out_of_order_bufs.erase(it);
864 }).then_wrapped([su = std::move(su),
this] (future<> f) {
865 if (f.failed() && !this->_ex) {
866 this->_ex = f.get_exception();
868 f.ignore_ready_future();
871 return make_ready_future<>();
875template<
typename Serializer,
typename... Out>
876future<> sink_impl<Serializer, Out...>::flush() {
878 return with_semaphore(this->_sem, max_stream_buffers_memory, [
this] {
886template<
typename Serializer,
typename... Out>
887future<> sink_impl<Serializer, Out...>::close() {
888 return with_semaphore(this->_sem, max_stream_buffers_memory, [
this] {
890 connection* con = this->_con->get();
891 if (con->sink_closed()) {
892 return make_exception_future(stream_closed());
894 future<> f = make_ready_future<>();
895 if (!con->error() && !this->_ex) {
896 snd_buf data = marshall(con->template serializer<Serializer>(), 4);
897 static_assert(snd_buf::chunk_size >= 4,
"send buffer chunk size is too small");
898 auto p = data.front().get_write();
899 write_le<uint32_t>(p, -1U);
900 f = con->send(std::move(data), {},
nullptr);
904 return f.finally([con] {
return con->close_sink(); });
909template<
typename Serializer,
typename... Out>
910sink_impl<Serializer, Out...>::~sink_impl() {
913 assert(this->_con->get()->sink_closed());
916template<
typename Serializer,
typename... In>
917future<std::optional<std::tuple<In...>>> source_impl<Serializer, In...>::operator()() {
918 auto process_one_buffer = [
this] {
919 foreign_ptr<std::unique_ptr<rcv_buf>> buf = std::move(this->_bufs.front());
920 this->_bufs.pop_front();
921 return std::apply([] (In&&... args) {
922 auto ret = std::make_optional(std::make_tuple(std::move(args)...));
924 }, unmarshall<Serializer, In...>(*this->_con->get(), make_shard_local_buffer_copy(std::move(buf))));
927 if (!this->_bufs.empty()) {
928 return process_one_buffer();
932 return smp::submit_to(this->_con->get_owner_shard(), [
this] () -> future<> {
933 connection* con = this->_con->get();
934 if (con->_source_closed) {
935 return make_exception_future<>(stream_closed());
937 return con->stream_receive(this->_bufs).then_wrapped([
this, con] (future<>&& f) {
939 return con->close_source().then_wrapped([ex = f.get_exception()] (future<> f){
940 f.ignore_ready_future();
941 return make_exception_future<>(ex);
944 if (this->_bufs.empty()) {
945 return con->close_source().then_wrapped([] (future<> f) {
946 f.ignore_ready_future();
947 return make_ready_future<>();
950 return make_ready_future<>();
952 }).then([
this, process_one_buffer] () {
953 if (this->_bufs.empty()) {
956 return process_one_buffer();
961template<
typename... Out>
962connection_id sink<Out...>::get_id()
const {
963 return _impl->_con->get()->get_connection_id();
966template<
typename... In>
967connection_id source<In...>::get_id()
const {
968 return _impl->_con->get()->get_connection_id();
971template<
typename... In>
972template<
typename Serializer,
typename... Out>
973sink<Out...> source<In...>::make_sink() {
974 return sink<Out...>(make_shared<sink_impl<Serializer, Out...>>(_impl->_con));
983struct hash<
seastar::rpc::streaming_domain_type> {
986 boost::hash_combine(h, std::hash<uint64_t>{}(domain._id));
A representation of a possibly not-yet-computed value.
Definition: future.hh:1240
static time_point now() noexcept
Definition: lowres_clock.hh:74
promise - allows a future value to be made available at a later time.
Definition: future.hh:934
void set_value(A &&... a) noexcept
Sets the promises value.
Definition: future.hh:990
Definition: reference_wrapper.hh:43
Definition: rpc_impl.hh:730
Definition: rpc_types.hh:139
Definition: rpc_types.hh:66
Definition: rpc_types.hh:193
Definition: rpc_types.hh:188
Definition: rpc_types.hh:317
Definition: rpc_types.hh:356
Definition: rpc_types.hh:397
Identifies function calls that are accounted as a group.
Definition: scheduling.hh:285
static futurize_t< std::invoke_result_t< Func > > submit_to(unsigned t, smp_submit_to_options options, Func &&func) noexcept
Definition: smp.hh:354
future< T > make_ready_future(A &&... value) noexcept
Creates a future in an available, value state.
Definition: future.hh:1943
future< T > make_exception_future(std::exception_ptr &&value) noexcept
Creates a future in an available, failed state.
Definition: future.hh:1949
auto when_all(FutOrFuncs &&... fut_or_funcs) noexcept
Definition: when_all.hh:252
future now()
Returns a ready future.
Definition: later.hh:35
reference_wrapper< T > ref(T &object) noexcept
Wraps reference in a reference_wrapper.
Definition: reference_wrapper.hh:62
std::future< T > submit_to(instance &instance, unsigned shard, Func func)
Definition: alien.hh:204
Seastar API namespace.
Definition: abort_on_ebadf.hh:26
sstring format(fmt::format_string< A... > fmt, A &&... a)
Definition: format.hh:42
Definition: function_traits.hh:62
Definition: rpc_types.hh:203
Definition: rpc_types.hh:97
Definition: rpc_impl.hh:349
Definition: rpc_impl.hh:56
Definition: rpc_impl.hh:60
Definition: rpc_impl.hh:57
Definition: rpc_impl.hh:61
Definition: rpc_impl.hh:214
Definition: rpc_impl.hh:213
Definition: rpc_types.hh:179
Definition: rpc_types.hh:239
Definition: rpc_impl.hh:467
Definition: rpc_impl.hh:483
Definition: rpc_impl.hh:44
Definition: rpc_impl.hh:191
Definition: rpc_impl.hh:65
Definition: rpc_impl.hh:307
Definition: rpc_impl.hh:306
Definition: rpc_impl.hh:122
Definition: rpc_impl.hh:53