Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
nghttp2
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
nghttp2
Commits
4f9f181f
Commit
4f9f181f
authored
Mar 22, 2017
by
Tatsuhiro Tsujikawa
Committed by
GitHub
Mar 22, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #848 from nghttp2/asio-client-ping
asio: client: Send PING after 30 seconds idle
parents
c7df6530
b7e7a4bf
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
0 deletions
+33
-0
src/asio_client_session_impl.cc
src/asio_client_session_impl.cc
+29
-0
src/asio_client_session_impl.h
src/asio_client_session_impl.h
+4
-0
No files found.
src/asio_client_session_impl.cc
View file @
4f9f181f
...
@@ -45,6 +45,7 @@ session_impl::session_impl(
...
@@ -45,6 +45,7 @@ session_impl::session_impl(
io_service_
(
io_service
),
io_service_
(
io_service
),
resolver_
(
io_service
),
resolver_
(
io_service
),
deadline_
(
io_service
),
deadline_
(
io_service
),
ping_
(
io_service
),
connect_timeout_
(
connect_timeout
),
connect_timeout_
(
connect_timeout
),
read_timeout_
(
boost
::
posix_time
::
seconds
(
60
)),
read_timeout_
(
boost
::
posix_time
::
seconds
(
60
)),
session_
(
nullptr
),
session_
(
nullptr
),
...
@@ -83,6 +84,7 @@ void session_impl::start_resolve(const std::string &host,
...
@@ -83,6 +84,7 @@ void session_impl::start_resolve(const std::string &host,
});
});
deadline_
.
async_wait
(
std
::
bind
(
&
session_impl
::
handle_deadline
,
self
));
deadline_
.
async_wait
(
std
::
bind
(
&
session_impl
::
handle_deadline
,
self
));
start_ping
();
}
}
void
session_impl
::
handle_deadline
()
{
void
session_impl
::
handle_deadline
()
{
...
@@ -102,6 +104,27 @@ void session_impl::handle_deadline() {
...
@@ -102,6 +104,27 @@ void session_impl::handle_deadline() {
std
::
bind
(
&
session_impl
::
handle_deadline
,
this
->
shared_from_this
()));
std
::
bind
(
&
session_impl
::
handle_deadline
,
this
->
shared_from_this
()));
}
}
void
handle_ping2
(
const
boost
::
system
::
error_code
&
ec
,
int
)
{}
void
session_impl
::
start_ping
()
{
ping_
.
expires_from_now
(
boost
::
posix_time
::
seconds
(
30
));
ping_
.
async_wait
(
std
::
bind
(
&
session_impl
::
handle_ping
,
shared_from_this
(),
std
::
placeholders
::
_1
));
}
void
session_impl
::
handle_ping
(
const
boost
::
system
::
error_code
&
ec
)
{
if
(
stopped_
||
ec
==
boost
::
asio
::
error
::
operation_aborted
||
!
streams_
.
empty
())
{
return
;
}
nghttp2_submit_ping
(
session_
,
NGHTTP2_FLAG_NONE
,
nullptr
);
signal_write
();
start_ping
();
}
void
session_impl
::
connected
(
tcp
::
resolver
::
iterator
endpoint_it
)
{
void
session_impl
::
connected
(
tcp
::
resolver
::
iterator
endpoint_it
)
{
if
(
!
setup_session
())
{
if
(
!
setup_session
())
{
return
;
return
;
...
@@ -433,6 +456,9 @@ std::unique_ptr<stream> session_impl::pop_stream(int32_t stream_id) {
...
@@ -433,6 +456,9 @@ std::unique_ptr<stream> session_impl::pop_stream(int32_t stream_id) {
}
}
auto
strm
=
std
::
move
((
*
it
).
second
);
auto
strm
=
std
::
move
((
*
it
).
second
);
streams_
.
erase
(
it
);
streams_
.
erase
(
it
);
if
(
streams_
.
empty
())
{
start_ping
();
}
return
strm
;
return
strm
;
}
}
...
@@ -441,6 +467,7 @@ stream *session_impl::create_push_stream(int32_t stream_id) {
...
@@ -441,6 +467,7 @@ stream *session_impl::create_push_stream(int32_t stream_id) {
strm
->
stream_id
(
stream_id
);
strm
->
stream_id
(
stream_id
);
auto
p
=
streams_
.
emplace
(
stream_id
,
std
::
move
(
strm
));
auto
p
=
streams_
.
emplace
(
stream_id
,
std
::
move
(
strm
));
assert
(
p
.
second
);
assert
(
p
.
second
);
ping_
.
cancel
();
return
(
*
p
.
first
).
second
.
get
();
return
(
*
p
.
first
).
second
.
get
();
}
}
...
@@ -544,6 +571,7 @@ const request *session_impl::submit(boost::system::error_code &ec,
...
@@ -544,6 +571,7 @@ const request *session_impl::submit(boost::system::error_code &ec,
auto
p
=
streams_
.
emplace
(
stream_id
,
std
::
move
(
strm
));
auto
p
=
streams_
.
emplace
(
stream_id
,
std
::
move
(
strm
));
assert
(
p
.
second
);
assert
(
p
.
second
);
ping_
.
cancel
();
return
&
(
*
p
.
first
).
second
->
request
();
return
&
(
*
p
.
first
).
second
->
request
();
}
}
...
@@ -715,6 +743,7 @@ void session_impl::stop() {
...
@@ -715,6 +743,7 @@ void session_impl::stop() {
shutdown_socket
();
shutdown_socket
();
deadline_
.
cancel
();
deadline_
.
cancel
();
ping_
.
cancel
();
stopped_
=
true
;
stopped_
=
true
;
}
}
...
...
src/asio_client_session_impl.h
View file @
4f9f181f
...
@@ -109,6 +109,8 @@ private:
...
@@ -109,6 +109,8 @@ private:
bool
setup_session
();
bool
setup_session
();
void
call_error_cb
(
const
boost
::
system
::
error_code
&
ec
);
void
call_error_cb
(
const
boost
::
system
::
error_code
&
ec
);
void
handle_deadline
();
void
handle_deadline
();
void
start_ping
();
void
handle_ping
(
const
boost
::
system
::
error_code
&
ec
);
boost
::
asio
::
io_service
&
io_service_
;
boost
::
asio
::
io_service
&
io_service_
;
tcp
::
resolver
resolver_
;
tcp
::
resolver
resolver_
;
...
@@ -122,6 +124,8 @@ private:
...
@@ -122,6 +124,8 @@ private:
boost
::
posix_time
::
time_duration
connect_timeout_
;
boost
::
posix_time
::
time_duration
connect_timeout_
;
boost
::
posix_time
::
time_duration
read_timeout_
;
boost
::
posix_time
::
time_duration
read_timeout_
;
boost
::
asio
::
deadline_timer
ping_
;
nghttp2_session
*
session_
;
nghttp2_session
*
session_
;
const
uint8_t
*
data_pending_
;
const
uint8_t
*
data_pending_
;
...
...
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