SNode.C
Loading...
Searching...
No Matches
Identity.cpp
Go to the documentation of this file.
1/*
2 * snode.c - a slim toolkit for network communication
3 * Copyright (C) Volker Christian <me@vchrist.at>
4 * 2020, 2021, 2022, 2023, 2024, 2025
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published
8 * by the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include "web/http/decoder/Identity.h"
21
22#include "core/socket/stream/SocketContext.h"
23
24#ifndef DOXYGEN_SHOULD_SKIP_THIS
25
26#include <vector>
27
28#endif // DOXYGEN_SHOULD_SKIP_THIS
29
30namespace web::http::decoder {
31
32 Identity::Identity(const core::socket::stream::SocketContext* socketContext, std::size_t contentLengthExpected)
33 : socketContext(socketContext)
34 , contentLengthExpected(contentLengthExpected) {
35 content.resize(contentLengthExpected);
36 }
37
39 }
40
41 std::size_t Identity::read() {
42 std::size_t consumed = 0;
43
44 switch (state) {
45 case -1:
46 content.clear();
47 completed = false;
48 error = false;
49
50 state = 0;
51
52 [[fallthrough]];
53 case 0:
54 std::size_t ret = 0;
55 do {
56 ret = socketContext->readFromPeer(content.data() + contentLengthRead, contentLengthExpected - contentLengthRead);
57 contentLengthRead += ret;
58 consumed += ret;
60 } while (ret > 0 && !completed);
61
62 if (completed) {
63 state = -1;
64 }
65
66 break;
67 }
68 return consumed;
69 }
70
71} // namespace web::http::decoder
Identity(const core::socket::stream::SocketContext *socketContext, std::size_t contentLengthExpected)
Definition Identity.cpp:32
const core::socket::stream::SocketContext * socketContext
Definition Identity.h:51
std::size_t read() override
Definition Identity.cpp:41
std::size_t contentLengthExpected
Definition Identity.h:52
std::size_t contentLengthRead
Definition Identity.h:53