Seastar
High performance C++ framework for concurrent servers
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
packet-data-source.hh
1/*
2 * This file is open source software, licensed to you under the terms
3 * of the Apache License, Version 2.0 (the "License"). See the NOTICE file
4 * distributed with this work for additional information regarding copyright
5 * ownership. You may not use this file except in compliance with the License.
6 *
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing,
12 * software distributed under the License is distributed on an
13 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 * KIND, either express or implied. See the License for the
15 * specific language governing permissions and limitations
16 * under the License.
17 */
18#pragma once
19
20#include <seastar/net/packet.hh>
21#include <seastar/core/iostream.hh>
22
23namespace seastar {
24
25namespace net {
26
28 size_t _cur_frag = 0;
29 packet _p;
30public:
32 : _p(std::move(p))
33 {}
34
35 virtual future<temporary_buffer<char>> get() override {
36 if (_cur_frag != _p.nr_frags()) {
37 auto& f = _p.fragments()[_cur_frag++];
38 return make_ready_future<temporary_buffer<char>>(
39 temporary_buffer<char>(f.base, f.size,
40 make_deleter(deleter(), [p = _p.share()] () mutable {})));
41 }
42 return make_ready_future<temporary_buffer<char>>(temporary_buffer<char>());
43 }
44};
45
46static inline
47input_stream<char> as_input_stream(packet&& p) {
48 return input_stream<char>(data_source(std::make_unique<packet_data_source>(std::move(p))));
49}
50
51}
52
53}
Definition: iostream.hh:61
Definition: iostream.hh:69
Definition: deleter.hh:52
A representation of a possibly not-yet-computed value.
Definition: future.hh:1240
Definition: packet-data-source.hh:27
Definition: packet.hh:87
Seastar API namespace.
Definition: abort_on_ebadf.hh:26