Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
pistache
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
pistache
Commits
ae0da38c
Unverified
Commit
ae0da38c
authored
Nov 30, 2020
by
Igor [hyperxor]
Committed by
GitHub
Nov 29, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix issue #798: partially decrease allocated memory during file upload (#849)
parent
f0d853b8
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
32 additions
and
21 deletions
+32
-21
include/pistache/http.h
include/pistache/http.h
+5
-5
include/pistache/peer.h
include/pistache/peer.h
+3
-0
src/common/http.cc
src/common/http.cc
+16
-16
src/common/peer.cc
src/common/peer.cc
+8
-0
No files found.
include/pistache/http.h
View file @
ae0da38c
...
...
@@ -255,7 +255,7 @@ public:
private:
Timeout
(
const
Timeout
&
other
)
=
default
;
Timeout
(
Tcp
::
Transport
*
transport_
,
Handler
*
handler_
,
Request
request_
,
Timeout
(
Tcp
::
Transport
*
transport_
,
Handler
*
handler_
,
std
::
weak_ptr
<
Tcp
::
Peer
>
peer_
);
void
onTimeout
(
uint64_t
numWakeup
);
...
...
@@ -422,8 +422,8 @@ public:
}
private:
ResponseWriter
(
Tcp
::
Transport
*
transport
,
Request
request
,
Handler
*
handler
,
std
::
weak_ptr
<
Tcp
::
Peer
>
peer
);
ResponseWriter
(
Http
::
Version
version
,
Tcp
::
Transport
*
transport
,
Handler
*
handler
,
std
::
weak_ptr
<
Tcp
::
Peer
>
peer
);
ResponseWriter
(
const
ResponseWriter
&
other
);
...
...
@@ -436,9 +436,9 @@ private:
Response
response_
;
std
::
weak_ptr
<
Tcp
::
Peer
>
peer_
;
DynamicStreamBuf
buf_
;
Tcp
::
Transport
*
transport_
;
Tcp
::
Transport
*
transport_
=
nullptr
;
Timeout
timeout_
;
ssize_t
sent_bytes_
;
ssize_t
sent_bytes_
=
0
;
};
Async
::
Promise
<
ssize_t
>
...
...
include/pistache/peer.h
View file @
ae0da38c
...
...
@@ -31,6 +31,7 @@ class Peer {
public:
friend
class
Transport
;
friend
class
Http
::
Handler
;
friend
class
Http
::
Timeout
;
~
Peer
();
...
...
@@ -53,6 +54,8 @@ private:
void
setParser
(
std
::
shared_ptr
<
Http
::
RequestParser
>
parser
);
std
::
shared_ptr
<
Http
::
RequestParser
>
getParser
()
const
;
Http
::
Request
&
request
();
void
associateTransport
(
Transport
*
transport
);
Transport
*
transport
()
const
;
...
...
src/common/http.cc
View file @
ae0da38c
...
...
@@ -656,19 +656,18 @@ void ResponseStream::ends() {
ResponseWriter
::
ResponseWriter
(
ResponseWriter
&&
other
)
:
response_
(
std
::
move
(
other
.
response_
)),
peer_
(
other
.
peer_
),
buf_
(
std
::
move
(
other
.
buf_
)),
transport_
(
other
.
transport_
),
timeout_
(
std
::
move
(
other
.
timeout_
))
,
sent_bytes_
(
0
)
{}
timeout_
(
std
::
move
(
other
.
timeout_
))
{}
ResponseWriter
::
ResponseWriter
(
Tcp
::
Transport
*
transport
,
Request
reques
t
,
ResponseWriter
::
ResponseWriter
(
Http
::
Version
version
,
Tcp
::
Transport
*
transpor
t
,
Handler
*
handler
,
std
::
weak_ptr
<
Tcp
::
Peer
>
peer
)
:
response_
(
request
.
version
()
),
peer_
(
peer
),
:
response_
(
version
),
peer_
(
peer
),
buf_
(
DefaultStreamSize
,
handler
->
getMaxResponseSize
()),
transport_
(
transport
),
timeout_
(
transport
,
handler
,
std
::
move
(
request
),
peer
),
sent_bytes_
(
0
)
{}
transport_
(
transport
),
timeout_
(
transport
,
handler
,
peer
)
{}
ResponseWriter
::
ResponseWriter
(
const
ResponseWriter
&
other
)
:
response_
(
other
.
response_
),
peer_
(
other
.
peer_
),
buf_
(
DefaultStreamSize
,
other
.
buf_
.
maxSize
()),
transport_
(
other
.
transport_
),
timeout_
(
other
.
timeout_
)
,
sent_bytes_
(
0
)
{}
transport_
(
other
.
transport_
),
timeout_
(
other
.
timeout_
)
{}
void
ResponseWriter
::
setMime
(
const
Mime
::
MediaType
&
mime
)
{
auto
ct
=
response_
.
headers
().
tryGet
<
Header
::
ContentType
>
();
...
...
@@ -916,6 +915,7 @@ Private::ParserImpl<Http::Response>::ParserImpl(size_t maxDataSize)
void
Handler
::
onInput
(
const
char
*
buffer
,
size_t
len
,
const
std
::
shared_ptr
<
Tcp
::
Peer
>
&
peer
)
{
auto
parser
=
peer
->
getParser
();
auto
&
request
=
peer
->
request
();
try
{
if
(
!
parser
->
feed
(
buffer
,
len
))
{
parser
->
reset
();
...
...
@@ -924,10 +924,9 @@ void Handler::onInput(const char *buffer, size_t len,
}
auto
state
=
parser
->
parse
();
auto
&
request
=
parser
->
request
;
if
(
state
==
Private
::
State
::
Done
)
{
ResponseWriter
response
(
transport
(),
request
,
this
,
peer
);
ResponseWriter
response
(
request
.
version
(),
transport
()
,
this
,
peer
);
#ifdef LIBSTDCPP_SMARTPTR_LOCK_FIXME
request
.
associatePeer
(
peer
);
...
...
@@ -948,13 +947,13 @@ void Handler::onInput(const char *buffer, size_t len,
}
}
catch
(
const
HttpError
&
err
)
{
ResponseWriter
response
(
transport
(),
parser
->
request
,
this
,
peer
);
ResponseWriter
response
(
request
.
version
(),
transport
()
,
this
,
peer
);
response
.
send
(
static_cast
<
Code
>
(
err
.
code
()),
err
.
reason
());
parser
->
reset
();
}
catch
(
const
std
::
exception
&
e
)
{
ResponseWriter
response
(
transport
(),
parser
->
request
,
this
,
peer
);
ResponseWriter
response
(
request
.
version
(),
transport
()
,
this
,
peer
);
response
.
send
(
Code
::
Internal_Server_Error
,
e
.
what
());
parser
->
reset
();
}
...
...
@@ -978,18 +977,19 @@ void Timeout::disarm() {
bool
Timeout
::
isArmed
()
const
{
return
armed
;
}
Timeout
::
Timeout
(
Tcp
::
Transport
*
transport_
,
Handler
*
handler_
,
Request
request_
,
std
::
weak_ptr
<
Tcp
::
Peer
>
peer_
)
:
handler
(
handler_
),
request
(
std
::
move
(
request_
)),
transport
(
transport_
),
armed
(
false
),
timerFd
(
-
1
),
peer
(
peer_
)
{}
std
::
weak_ptr
<
Tcp
::
Peer
>
peer_
)
:
handler
(
handler_
),
transport
(
transport_
),
armed
(
false
),
timerFd
(
-
1
),
peer
(
peer_
)
{}
void
Timeout
::
onTimeout
(
uint64_t
numWakeup
)
{
UNUSED
(
numWakeup
)
if
(
!
peer
.
lock
())
auto
sp
=
peer
.
lock
();
if
(
!
sp
)
return
;
ResponseWriter
response
(
transport
,
reques
t
,
handler
,
peer
);
ResponseWriter
response
(
sp
->
request
().
version
(),
transpor
t
,
handler
,
peer
);
handler
->
onTimeout
(
request
,
std
::
move
(
response
));
handler
->
onTimeout
(
sp
->
request
()
,
std
::
move
(
response
));
}
void
Handler
::
setMaxRequestSize
(
size_t
value
)
{
maxRequestSize_
=
value
;
}
...
...
src/common/peer.cc
View file @
ae0da38c
...
...
@@ -84,6 +84,14 @@ void Peer::setParser(std::shared_ptr<Http::RequestParser> parser) {
std
::
shared_ptr
<
Http
::
RequestParser
>
Peer
::
getParser
()
const
{
return
parser_
;
}
Http
::
Request
&
Peer
::
request
()
{
if
(
!
parser_
)
{
throw
std
::
runtime_error
(
"The peer has no associated parser"
);
}
return
parser_
->
request
;
}
Async
::
Promise
<
ssize_t
>
Peer
::
send
(
const
RawBuffer
&
buffer
,
int
flags
)
{
return
transport
()
->
asyncWrite
(
fd_
,
buffer
,
flags
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment