Fix incorrect Ping Timeout

This commit is contained in:
loki 2020-02-09 17:30:11 +01:00
parent 5d606bf567
commit f56e7fc50d
3 changed files with 15 additions and 11 deletions

View File

@ -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<bool> *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;
}

View File

@ -10,6 +10,8 @@
#include <mutex>
#include <condition_variable>
#include <string_view>
#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;\

View File

@ -74,14 +74,14 @@ int capture_display(platf::img_t *img, std::unique_ptr<platf::display_t> &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<safe::queue_t<capture_ctx_t>> capture_ctx_que
}
std::shared_ptr<platf::img_t> 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<safe::queue_t<capture_ctx_t>> capture_ctx_que
capture_ctx->images->raise(img);
capture_ctx->next_frame = time_point + capture_ctx->delay;
}
}
++capture_ctx;
})
}
}