From f56e7fc50d052d6e6a001e1a4bc87580f57ec7c6 Mon Sep 17 00:00:00 2001 From: loki Date: Sun, 9 Feb 2020 17:30:11 +0100 Subject: [PATCH] Fix incorrect Ping Timeout --- sunshine/stream.cpp | 5 ++--- sunshine/utility.h | 2 ++ sunshine/video.cpp | 19 +++++++++++-------- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/sunshine/stream.cpp b/sunshine/stream.cpp index 0738274b..12c7970f 100644 --- a/sunshine/stream.cpp +++ b/sunshine/stream.cpp @@ -187,6 +187,7 @@ public: } auto &session = it->second; + session->pingTimeout = std::chrono::steady_clock::now() + config::stream.ping_timeout; switch(event.type) { case ENET_EVENT_TYPE_RECEIVE: @@ -396,8 +397,6 @@ void controlBroadcastThread(safe::event_t *shutdown_event, session_queue_t }); server.map(packetTypes[IDX_INPUT_DATA], [&](session_t *session, const std::string_view &payload) { - session->pingTimeout = std::chrono::steady_clock::now() + config::stream.ping_timeout; - BOOST_LOG(debug) << "type [IDX_INPUT_DATA]"sv; int32_t tagged_cipher_length = util::endian::big(*(int32_t*)payload.data()); @@ -707,7 +706,7 @@ int recv_ping(decltype(broadcast)::ptr_t ref, socket_e type, asio::ip::address & messages->stop(); if(!msg_opt) { - BOOST_LOG(error) << "Ping Timeout"sv; + BOOST_LOG(error) << "Initial Ping Timeout"sv; return -1; } diff --git a/sunshine/utility.h b/sunshine/utility.h index 5da18256..0bebdd98 100644 --- a/sunshine/utility.h +++ b/sunshine/utility.h @@ -10,6 +10,8 @@ #include #include #include + +#define KITTY_WHILE_LOOP(x, y, z) { x;while(y) z } #define KITTY_DECL_CONSTR(x)\ x(x&&) noexcept = default;\ x&operator=(x&&) noexcept = default;\ diff --git a/sunshine/video.cpp b/sunshine/video.cpp index 41029004..c305b058 100644 --- a/sunshine/video.cpp +++ b/sunshine/video.cpp @@ -74,14 +74,14 @@ int capture_display(platf::img_t *img, std::unique_ptr &disp) return -1; } - return -1; + return 0; } case platf::capture_e::error: return -1; // Prevent warning during compilation case platf::capture_e::timeout: case platf::capture_e::ok: - return 0; + return 1; default: BOOST_LOG(error) << "Unrecognized capture status ["sv << (int)status << ']'; return -1; @@ -111,16 +111,17 @@ void captureThread(std::shared_ptr> capture_ctx_que } std::shared_ptr img = disp->alloc_img(); - auto has_error = capture_display(img.get(), disp); - if(has_error) { + auto result = capture_display(img.get(), disp); + if(result < 0) { return; } + if(!result) { + continue; + } - auto time_point = std::chrono::steady_clock::now(); - for(auto capture_ctx = std::begin(capture_ctxs); capture_ctx != std::end(capture_ctxs); ++capture_ctx) { + KITTY_WHILE_LOOP(auto time_point = std::chrono::steady_clock::now(); auto capture_ctx = std::begin(capture_ctxs), capture_ctx != std::end(capture_ctxs), { if(!capture_ctx->images->running()) { capture_ctx = capture_ctxs.erase(capture_ctx); - continue; } @@ -128,7 +129,9 @@ void captureThread(std::shared_ptr> capture_ctx_que capture_ctx->images->raise(img); capture_ctx->next_frame = time_point + capture_ctx->delay; } - } + + ++capture_ctx; + }) } }