From 05f97898588a94255ed9d3c0ecaf585546fac3d6 Mon Sep 17 00:00:00 2001 From: torikizi <51085972+torikizi@users.noreply.github.com> Date: Mon, 16 Dec 2024 15:28:53 +0900 Subject: [PATCH] =?UTF-8?q?deadline=5Ftimer=20=E3=81=AE=E9=9D=9E=E6=8E=A8?= =?UTF-8?q?=E5=A5=A8=E3=81=AB=E5=AF=BE=E5=BF=9C=E3=81=97=20steady=5Ftimer?= =?UTF-8?q?=20=E3=81=B8=E5=88=87=E3=82=8A=E6=9B=BF=E3=81=88=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/sora/data_channel.h | 2 +- include/sora/sora_signaling.h | 4 ++-- include/sora/websocket.h | 2 +- src/data_channel.cpp | 4 ++-- src/sora_signaling.cpp | 21 ++++++++++----------- src/websocket.cpp | 5 ++--- test/connect_disconnect.cpp | 6 +++--- test/datachannel.cpp | 6 +++--- test/e2e.cpp | 6 +++--- 9 files changed, 27 insertions(+), 29 deletions(-) diff --git a/include/sora/data_channel.h b/include/sora/data_channel.h index ab711de2..6349dcc9 100644 --- a/include/sora/data_channel.h +++ b/include/sora/data_channel.h @@ -65,7 +65,7 @@ class DataChannel : public std::enable_shared_from_this { labels_; std::weak_ptr observer_; std::function on_close_; - boost::asio::deadline_timer timer_; + boost::asio::steady_timer timer_; }; } // namespace sora diff --git a/include/sora/sora_signaling.h b/include/sora/sora_signaling.h index 06b58d45..6c403128 100644 --- a/include/sora/sora_signaling.h +++ b/include/sora/sora_signaling.h @@ -314,8 +314,8 @@ class SoraSignaling : public std::enable_shared_from_this, std::string video_mid_; std::string audio_mid_; - boost::asio::deadline_timer connection_timeout_timer_; - boost::asio::deadline_timer closing_timeout_timer_; + boost::asio::steady_timer connection_timeout_timer_; + boost::asio::steady_timer closing_timeout_timer_; std::function on_ws_close_; webrtc::PeerConnectionInterface::IceConnectionState ice_state_ = webrtc::PeerConnectionInterface::kIceConnectionNew; diff --git a/include/sora/websocket.h b/include/sora/websocket.h index 759e5851..ca1a4f2e 100644 --- a/include/sora/websocket.h +++ b/include/sora/websocket.h @@ -150,7 +150,7 @@ class Websocket { }; std::vector> write_data_; - boost::asio::deadline_timer close_timeout_timer_; + boost::asio::steady_timer close_timeout_timer_; http_header_value user_agent_; diff --git a/src/data_channel.cpp b/src/data_channel.cpp index 9b5b1951..5bf894ca 100644 --- a/src/data_channel.cpp +++ b/src/data_channel.cpp @@ -55,8 +55,8 @@ void DataChannel::Close(const webrtc::DataBuffer& disconnect_message, return; } - timer_.expires_from_now( - boost::posix_time::milliseconds((int)(disconnect_wait_timeout * 1000))); + timer_.expires_after( + std::chrono::milliseconds((int)(disconnect_wait_timeout * 1000))); timer_.async_wait([on_close](boost::system::error_code ec) { if (ec == boost::asio::error::operation_aborted) { return; diff --git a/src/sora_signaling.cpp b/src/sora_signaling.cpp index 59f83a3d..b3484d3e 100644 --- a/src/sora_signaling.cpp +++ b/src/sora_signaling.cpp @@ -147,9 +147,8 @@ void SoraSignaling::Redirect(std::string url) { } // 接続タイムアウト用の処理 - self->connection_timeout_timer_.expires_from_now( - boost::posix_time::seconds( - self->config_.websocket_connection_timeout)); + self->connection_timeout_timer_.expires_after( + std::chrono::seconds(self->config_.websocket_connection_timeout)); self->connection_timeout_timer_.async_wait( [self](boost::system::error_code ec) { if (ec) { @@ -217,7 +216,7 @@ void SoraSignaling::OnRedirect(boost::system::error_code ec, } boost::system::error_code tec; - connection_timeout_timer_.cancel(tec); + connection_timeout_timer_.cancel(); state_ = State::Connected; ws_ = ws; @@ -692,8 +691,8 @@ void SoraSignaling::DoInternalDisconnect( SendOnSignalingMessage(SoraSignalingType::DATACHANNEL, SoraSignalingDirection::SENT, std::move(text)); } else if (!using_datachannel_ && ws_connected_) { - closing_timeout_timer_.expires_from_now( - boost::posix_time::seconds(config_.websocket_close_timeout)); + closing_timeout_timer_.expires_after( + std::chrono::seconds(config_.websocket_close_timeout)); closing_timeout_timer_.async_wait( [self = shared_from_this()](boost::system::error_code ec) { if (ec) { @@ -704,7 +703,7 @@ void SoraSignaling::DoInternalDisconnect( on_ws_close_ = [self = shared_from_this(), on_close](boost::system::error_code ec) { boost::system::error_code tec; - self->closing_timeout_timer_.cancel(tec); + self->closing_timeout_timer_.cancel(); auto reason = self->ws_->reason(); if (ec == boost::asio::error::operation_aborted) { // タイムアウトによる切断なので 4999 をコールバックする @@ -798,7 +797,7 @@ void SoraSignaling::OnConnect(boost::system::error_code ec, } boost::system::error_code tec; - connection_timeout_timer_.cancel(tec); + connection_timeout_timer_.cancel(); RTC_LOG(LS_INFO) << "Signaling Websocket is connected: url=" << url; state_ = State::Connected; @@ -1173,7 +1172,7 @@ void SoraSignaling::DoConnect() { dc_.reset(new DataChannel(*config_.io_context, shared_from_this())); // 接続タイムアウト用の処理 - connection_timeout_timer_.expires_from_now(boost::posix_time::seconds(30)); + connection_timeout_timer_.expires_after(std::chrono::seconds(30)); connection_timeout_timer_.async_wait( [self = shared_from_this()](boost::system::error_code ec) { if (ec) { @@ -1409,8 +1408,8 @@ bool SoraSignaling::SendDataChannel(const std::string& label, void SoraSignaling::Clear() { boost::system::error_code tec; - connection_timeout_timer_.cancel(tec); - closing_timeout_timer_.cancel(tec); + connection_timeout_timer_.cancel(); + closing_timeout_timer_.cancel(); connecting_wss_.clear(); selected_signaling_url_.store(""); connected_signaling_url_.store(""); diff --git a/src/websocket.cpp b/src/websocket.cpp index 00cb2a0b..655a8b1f 100644 --- a/src/websocket.cpp +++ b/src/websocket.cpp @@ -547,8 +547,7 @@ void Websocket::DoClose(close_callback_t on_close, int timeout_seconds) { std::bind(&Websocket::OnClose, this, on_close, std::placeholders::_1)); } - close_timeout_timer_.expires_from_now( - boost::posix_time::seconds(timeout_seconds)); + close_timeout_timer_.expires_after(std::chrono::seconds(timeout_seconds)); close_timeout_timer_.async_wait( [on_close, timeout_seconds, this](boost::system::error_code ec) { if (ec) { @@ -566,7 +565,7 @@ void Websocket::OnClose(close_callback_t on_close, << " ec=" << ec.message() << " code=" << reason().code << " reason=" << reason().reason; boost::system::error_code tec; - close_timeout_timer_.cancel(tec); + close_timeout_timer_.cancel(); on_close(ec); } diff --git a/test/connect_disconnect.cpp b/test/connect_disconnect.cpp index a20fee6b..81cb1b1c 100644 --- a/test/connect_disconnect.cpp +++ b/test/connect_disconnect.cpp @@ -73,8 +73,8 @@ class SoraClient : public std::enable_shared_from_this, signals.async_wait( [this](const boost::system::error_code&, int) { conn_->Disconnect(); }); - timer_.reset(new boost::asio::deadline_timer(*ioc_)); - timer_->expires_from_now(boost::posix_time::seconds(1)); + timer_.reset(new boost::asio::steady_timer(*ioc_)); + timer_->expires_after(std::chrono::seconds(1)); timer_->async_wait([this](boost::system::error_code ec) { if (ec) { return; @@ -124,7 +124,7 @@ class SoraClient : public std::enable_shared_from_this, rtc::scoped_refptr video_track_; std::shared_ptr conn_; std::unique_ptr ioc_; - std::unique_ptr timer_; + std::unique_ptr timer_; }; int main(int argc, char* argv[]) { diff --git a/test/datachannel.cpp b/test/datachannel.cpp index ec6cbbec..3c632063 100644 --- a/test/datachannel.cpp +++ b/test/datachannel.cpp @@ -64,8 +64,8 @@ class SoraClient : public std::enable_shared_from_this, signals.async_wait( [this](const boost::system::error_code&, int) { conn_->Disconnect(); }); - timer_.reset(new boost::asio::deadline_timer(*ioc_)); - timer_->expires_from_now(boost::posix_time::seconds(3)); + timer_.reset(new boost::asio::steady_timer(*ioc_)); + timer_->expires_after(std::chrono::seconds(3)); timer_->async_wait([this, labels](boost::system::error_code ec) { if (ec) { return; @@ -133,7 +133,7 @@ class SoraClient : public std::enable_shared_from_this, SoraClientConfig config_; std::shared_ptr conn_; std::unique_ptr ioc_; - std::unique_ptr timer_; + std::unique_ptr timer_; std::set opened_; bool ok_ = false; }; diff --git a/test/e2e.cpp b/test/e2e.cpp index caaade17..cebd586a 100644 --- a/test/e2e.cpp +++ b/test/e2e.cpp @@ -99,8 +99,8 @@ class SoraClient : public std::enable_shared_from_this, signals.async_wait( [this](const boost::system::error_code&, int) { conn_->Disconnect(); }); - timer_.reset(new boost::asio::deadline_timer(*ioc_)); - timer_->expires_from_now(boost::posix_time::seconds(5)); + timer_.reset(new boost::asio::steady_timer(*ioc_)); + timer_->expires_after(std::chrono::seconds(5)); timer_->async_wait([this](boost::system::error_code ec) { if (ec) { return; @@ -150,7 +150,7 @@ class SoraClient : public std::enable_shared_from_this, std::shared_ptr context_; std::shared_ptr conn_; std::unique_ptr ioc_; - std::unique_ptr timer_; + std::unique_ptr timer_; rtc::scoped_refptr video_source_; rtc::scoped_refptr video_track_; std::atomic ok_{false};