Browse Source
Fix ws (#207)
Signed-off-by: turuslan <turuslan.devbox@gmail.com>
pull/208/head
v0.1.10
Ruslan Tushov
2 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with
14 additions and
5 deletions
-
include/libp2p/layer/websocket/ws_connection.hpp
-
include/libp2p/layer/websocket/ws_connection_config.hpp
-
src/layer/websocket/ws_connection.cpp
|
|
@ -20,11 +20,18 @@ namespace libp2p::layer { |
|
|
|
} // namespace libp2p::layer
|
|
|
|
|
|
|
|
namespace libp2p { |
|
|
|
inline void beast_close_socket(AsAsioReadWrite &stream) {} |
|
|
|
inline void beast_close_socket(AsAsioReadWrite &stream) { |
|
|
|
std::ignore = stream.impl->close(); |
|
|
|
} |
|
|
|
|
|
|
|
template <typename Cb> |
|
|
|
void async_teardown(boost::beast::role_type role, AsAsioReadWrite &stream, |
|
|
|
Cb &&cb) {} |
|
|
|
Cb &&cb) { |
|
|
|
std::ignore = stream.impl->close(); |
|
|
|
boost::asio::post(*stream.io, [cb{std::move(cb)}]() mutable { |
|
|
|
cb(boost::system::error_code{}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} // namespace libp2p
|
|
|
|
|
|
|
|
namespace libp2p::connection { |
|
|
|
|
|
@ -14,6 +14,7 @@ namespace libp2p::layer { |
|
|
|
*/ |
|
|
|
struct WsConnectionConfig { |
|
|
|
std::chrono::milliseconds ping_interval{60'000}; |
|
|
|
std::chrono::milliseconds ping_timeout{10'000}; |
|
|
|
}; |
|
|
|
} // namespace libp2p::layer
|
|
|
|
|
|
|
|
|
|
@ -63,8 +63,8 @@ namespace libp2p::connection { |
|
|
|
[](boost::system::error_code) {}); |
|
|
|
|
|
|
|
// Start timer of pong waiting
|
|
|
|
self->ping_timeout_handle_ = |
|
|
|
self->scheduler_->scheduleWithHandle([wp] { |
|
|
|
self->ping_timeout_handle_ = self->scheduler_->scheduleWithHandle( |
|
|
|
[wp] { |
|
|
|
if (auto self = wp.lock()) { |
|
|
|
self->ws_.async_close( |
|
|
|
{ |
|
|
@ -73,7 +73,8 @@ namespace libp2p::connection { |
|
|
|
}, |
|
|
|
[](boost::system::error_code) {}); |
|
|
|
} |
|
|
|
}); |
|
|
|
}, |
|
|
|
self->config_.ping_timeout); |
|
|
|
} |
|
|
|
}, |
|
|
|
config_.ping_interval); |
|
|
|