Sese Framework  x.y.z
A cross-platform framework
载入中...
搜索中...
未找到
IOBuf.h
浏览该文件的文档.
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
50 ~IOBufNode();
51
56 [[nodiscard]] size_t getReadableSize() const noexcept;
57
62 [[nodiscard]] size_t getWriteableSize() const noexcept;
63};
64
66class IOBuf final : public io::InputStream, public io::PeekableStream {
67public:
69 using Node = std::unique_ptr<IOBufNode>;
70 using ListType = std::list<Node>;
71
74 void push(Node node);
75
77 void clear();
78
80 [[nodiscard]] size_t getReadableSize() const noexcept;
81
83 [[nodiscard]] size_t getTotalSize() const noexcept;
84
89 int64_t read(void *buffer, size_t length) override;
90
95 int64_t peek(void *buffer, size_t length) override;
96
100 int64_t trunc(size_t length) override;
101
102private:
104 ListType::iterator cur;
105
106 size_t total{0};
107 size_t readed{0};
108};
109
110} // namespace sese::iocp