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
parent
commit
47331081bc
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      include/libp2p/layer/websocket/ws_connection.hpp
  2. 1
      include/libp2p/layer/websocket/ws_connection_config.hpp
  3. 7
      src/layer/websocket/ws_connection.cpp

11
include/libp2p/layer/websocket/ws_connection.hpp

@ -20,11 +20,18 @@ namespace libp2p::layer {
} // namespace libp2p::layer } // namespace libp2p::layer
namespace libp2p { namespace libp2p {
inline void beast_close_socket(AsAsioReadWrite &stream) {} inline void beast_close_socket(AsAsioReadWrite &stream) {
std::ignore = stream.impl->close();
}
template <typename Cb> template <typename Cb>
void async_teardown(boost::beast::role_type role, AsAsioReadWrite &stream, 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
namespace libp2p::connection { namespace libp2p::connection {

1
include/libp2p/layer/websocket/ws_connection_config.hpp

@ -14,6 +14,7 @@ namespace libp2p::layer {
*/ */
struct WsConnectionConfig { struct WsConnectionConfig {
std::chrono::milliseconds ping_interval{60'000}; std::chrono::milliseconds ping_interval{60'000};
std::chrono::milliseconds ping_timeout{10'000};
}; };
} // namespace libp2p::layer } // namespace libp2p::layer

7
src/layer/websocket/ws_connection.cpp

@ -63,8 +63,8 @@ namespace libp2p::connection {
[](boost::system::error_code) {}); [](boost::system::error_code) {});
// Start timer of pong waiting // Start timer of pong waiting
self->ping_timeout_handle_ = self->ping_timeout_handle_ = self->scheduler_->scheduleWithHandle(
self->scheduler_->scheduleWithHandle([wp] { [wp] {
if (auto self = wp.lock()) { if (auto self = wp.lock()) {
self->ws_.async_close( self->ws_.async_close(
{ {
@ -73,7 +73,8 @@ namespace libp2p::connection {
}, },
[](boost::system::error_code) {}); [](boost::system::error_code) {});
} }
}); },
self->config_.ping_timeout);
} }
}, },
config_.ping_interval); config_.ping_interval);

Loading…
Cancel
Save