Skip to content

Commit

Permalink
Fix for RPC deadlock.
Browse files Browse the repository at this point in the history
  • Loading branch information
patcarter883 committed Nov 26, 2023
1 parent 09843c5 commit 4516f8c
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions source/ndi-rist-encoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <chrono>
#include <thread>
#include <future>

#include <FL/Fl.H>
#include <RISTNet.h>
Expand Down Expand Up @@ -227,10 +228,28 @@ void stopStream()

if (config.use_rpc_control) {
try {
Url url {fmt::format("rist://{}", config.rist_output_address)};


std::future<void> future = std::async(std::launch::async, []()
{
Url url {fmt::format("rist://{}", config.rist_output_address)};
rpc::client client(url.getHost(), app.rpc_port);
client.call("stop");
});

std::future_status status;

using namespace std::chrono_literals;
switch (status = future.wait_for(1s); status)
{
case std::future_status::timeout:
logAppend("Server stop timed out.");
break;
case std::future_status::ready:
logAppend("Server pipeline stopped.");
break;
}

rpc::client client(url.getHost(), app.rpc_port);
auto result = client.call("stop");
} catch (const std::exception& e) {
logAppend(e.what());
}
Expand Down

0 comments on commit 4516f8c

Please sign in to comment.