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
30
namespace
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
38
Identity
::~
Identity
() {
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;
59
completed
=
contentLengthExpected
==
contentLengthRead
;
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
core::socket::stream::SocketContext
Definition
SocketContext.h:42
web::http::ContentDecoder::error
bool error
Definition
ContentDecoder.h:57
web::http::ContentDecoder::completed
bool completed
Definition
ContentDecoder.h:56
web::http::decoder::Identity
Definition
Identity.h:37
web::http::decoder::Identity::Identity
Identity(const core::socket::stream::SocketContext *socketContext, std::size_t contentLengthExpected)
Definition
Identity.cpp:32
web::http::decoder::Identity::socketContext
const core::socket::stream::SocketContext * socketContext
Definition
Identity.h:51
web::http::decoder::Identity::state
int state
Definition
Identity.h:55
web::http::decoder::Identity::read
std::size_t read() override
Definition
Identity.cpp:41
web::http::decoder::Identity::contentLengthExpected
std::size_t contentLengthExpected
Definition
Identity.h:52
web::http::decoder::Identity::~Identity
~Identity() override
Definition
Identity.cpp:38
web::http::decoder::Identity::contentLengthRead
std::size_t contentLengthRead
Definition
Identity.h:53
core::socket
Definition
EchoSocketContext.h:26
web::http::decoder
Definition
Chunked.cpp:30
web
http
decoder
Identity.cpp
Generated on Mon Feb 10 2025 20:21:59 for SNode.C by
1.11.0