Sese Framework  2.3.0
A cross-platform framework
Loading...
Searching...
No Matches
Requestable.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
19
20#pragma once
21
24#include <sese/io/InputStream.h>
27
28#include <functional>
29
30namespace sese::net::http {
33public:
34 using WriteCallback = std::function<int64_t(const void *, size_t)>;
35 using ReadCallback = std::function<int64_t(void *, size_t)>;
36
37 ~Requestable() override = default;
38
41 virtual bool request() = 0;
42
45 virtual int getLastError() = 0;
46
49 virtual std::string getLastErrorString() = 0;
50
51 int64_t read(void *buf, size_t len) override = 0;
52
53 int64_t write(const void *buf, size_t len) override = 0;
54
58
62
67 this->read_data = read_data;
68 this->expect_total = expect_total;
69 }
70
74 this->write_data = write_data;
75 }
76
81 this->read_callback = read_callback;
82 this->expect_total = expect_total;
83 }
84
88 this->write_callback = write_callback;
89 }
90
92 void reset() {
93 expect_total = 0;
94 read_data = &req->getBody();
95 write_data = &resp->getBody();
96 read_callback = nullptr;
97 write_callback = nullptr;
98 }
99
100protected:
101 Request::Ptr req = nullptr;
103
104 size_t expect_total = 0;
105
108
111};
112} // namespace sese::net::http