Sese Framework  2.3.0
A cross-platform framework
Loading...
Searching...
No Matches
IOBuf.h
Go to the documentation of this file.
1// Copyright 2024 libsese
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
22#pragma once
23
24#include <sese/Config.h>
25#include <sese/io/InputStream.h>
27
28#include <list>
29
30namespace sese::iocp {
31
33struct IOBufNode {
35 void *buffer{nullptr};
37 size_t read{0};
39 size_t size{0};
41 const size_t CAPACITY;
42
47 explicit IOBufNode(size_t capacity);
48
49 ~IOBufNode();
50
55 [[nodiscard]] size_t getReadableSize() const noexcept;
56
61 [[nodiscard]] size_t getWriteableSize() const noexcept;
62};
63
65class IOBuf final : public io::InputStream, public io::PeekableStream {
66public:
68 using Node = std::unique_ptr<IOBufNode>;
69 using ListType = std::list<Node>;
70
73 void push(Node node);
74
76 void clear();
77
79 [[nodiscard]] size_t getReadableSize() const noexcept;
80
82 [[nodiscard]] size_t getTotalSize() const noexcept;
83
88 int64_t read(void *buffer, size_t length) override;
89
94 int64_t peek(void *buffer, size_t length) override;
95
99 int64_t trunc(size_t length) override;
100
101private:
103 ListType::iterator cur;
104
105 size_t total{0};
106 size_t readed{0};
107};
108
109} // namespace sese::iocp