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
e0c17cfb
Unverified
Commit
e0c17cfb
authored
Feb 14, 2020
by
Dennis Jenkins
Committed by
GitHub
Feb 14, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #706 from hyperxor/code_simplification_and_improvement_in_http
Code simplification + add pointer check
parents
de643616
fe9ec3d9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
33 deletions
+27
-33
include/pistache/http.h
include/pistache/http.h
+8
-18
src/common/http.cc
src/common/http.cc
+19
-15
No files found.
include/pistache/http.h
View file @
e0c17cfb
...
...
@@ -220,8 +220,6 @@ public:
other
.
timerFd
=
-
1
;
}
~
Timeout
()
{
disarm
();
}
Timeout
&
operator
=
(
Timeout
&&
other
)
{
handler
=
other
.
handler
;
transport
=
other
.
transport
;
...
...
@@ -233,6 +231,8 @@ public:
return
*
this
;
}
~
Timeout
();
template
<
typename
Duration
>
void
arm
(
Duration
duration
)
{
Async
::
Promise
<
uint64_t
>
p
([
=
](
Async
::
Deferred
<
uint64_t
>
deferred
)
{
timerFd
=
TRY_RET
(
timerfd_create
(
CLOCK_MONOTONIC
,
TFD_NONBLOCK
));
...
...
@@ -250,25 +250,15 @@ public:
armed
=
true
;
}
void
disarm
()
{
if
(
armed
)
{
transport
->
disarmTimer
(
timerFd
);
}
}
void
disarm
();
bool
isArmed
()
const
{
return
armed
;
}
bool
isArmed
()
const
;
private:
Timeout
(
const
Timeout
&
other
)
:
handler
(
other
.
handler
),
request
(
other
.
request
),
transport
(
other
.
transport
),
armed
(
other
.
armed
),
timerFd
(
other
.
timerFd
),
peer
()
{}
Timeout
(
Tcp
::
Transport
*
transport_
,
Handler
*
handler_
,
Request
request_
)
:
handler
(
handler_
),
request
(
std
::
move
(
request_
)),
transport
(
transport_
),
armed
(
false
),
timerFd
(
-
1
),
peer
()
{}
Timeout
(
const
Timeout
&
other
)
=
default
;
template
<
typename
Ptr
>
void
associatePeer
(
const
Ptr
&
ptr
)
{
peer
=
ptr
;
}
Timeout
(
Tcp
::
Transport
*
transport_
,
Handler
*
handler_
,
Request
request_
,
std
::
weak_ptr
<
Tcp
::
Peer
>
peer_
);
void
onTimeout
(
uint64_t
numWakeup
);
...
...
@@ -371,7 +361,7 @@ public:
// have to define it ourself
ResponseWriter
(
ResponseWriter
&&
other
);
ResponseWriter
&
operator
=
(
ResponseWriter
&&
other
);
ResponseWriter
&
operator
=
(
ResponseWriter
&&
other
)
=
default
;
void
setMime
(
const
Mime
::
MediaType
&
mime
);
...
...
src/common/http.cc
View file @
e0c17cfb
...
...
@@ -658,23 +658,13 @@ ResponseWriter::ResponseWriter(ResponseWriter &&other)
ResponseWriter
::
ResponseWriter
(
Tcp
::
Transport
*
transport
,
Request
request
,
Handler
*
handler
,
std
::
weak_ptr
<
Tcp
::
Peer
>
peer
)
:
response_
(
request
.
version
()),
peer_
(
peer
),
buf_
(
DefaultStreamSize
),
transport_
(
transport
),
timeout_
(
transport
,
handler
,
std
::
move
(
request
))
{
timeout_
.
associatePeer
(
peer
);
}
transport_
(
transport
),
timeout_
(
transport
,
handler
,
std
::
move
(
request
),
peer
)
{}
ResponseWriter
::
ResponseWriter
(
const
ResponseWriter
&
other
)
:
response_
(
other
.
response_
),
peer_
(
other
.
peer_
),
buf_
(
DefaultStreamSize
),
transport_
(
other
.
transport_
),
timeout_
(
other
.
timeout_
)
{}
ResponseWriter
&
ResponseWriter
::
operator
=
(
ResponseWriter
&&
other
)
{
response_
=
std
::
move
(
other
.
response_
);
peer_
=
std
::
move
(
other
.
peer_
);
transport_
=
other
.
transport_
;
buf_
=
std
::
move
(
other
.
buf_
);
timeout_
=
std
::
move
(
other
.
timeout_
);
return
*
this
;
}
void
ResponseWriter
::
setMime
(
const
Mime
::
MediaType
&
mime
)
{
auto
ct
=
response_
.
headers
().
tryGet
<
Header
::
ContentType
>
();
if
(
ct
)
{
...
...
@@ -950,11 +940,25 @@ void Handler::onConnection(const std::shared_ptr<Tcp::Peer> &peer) {
void
Handler
::
onDisconnection
(
const
std
::
shared_ptr
<
Tcp
::
Peer
>
&
/*peer*/
)
{}
void
Handler
::
onTimeout
(
const
Request
&
request
,
ResponseWriter
response
)
{
UNUSED
(
request
)
UNUSED
(
response
)
void
Handler
::
onTimeout
(
const
Request
&
/*request*/
,
ResponseWriter
/*response*/
)
{}
Timeout
::~
Timeout
()
{
disarm
();
}
void
Timeout
::
disarm
()
{
if
(
transport
&&
armed
)
{
transport
->
disarmTimer
(
timerFd
);
}
}
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_
)
{}
void
Timeout
::
onTimeout
(
uint64_t
numWakeup
)
{
UNUSED
(
numWakeup
)
if
(
!
peer
.
lock
())
...
...
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