Skip to content

Instantly share code, notes, and snippets.

@doug65536
Created July 23, 2024 23:44
Show Gist options
  • Save doug65536/cb875825e651b2355b5ae520c1d7a785 to your computer and use it in GitHub Desktop.
Save doug65536/cb875825e651b2355b5ae520c1d7a785 to your computer and use it in GitHub Desktop.
std::tuple<std::optional<websocket_client::message>, int>
websocket_client::recv_until(
std::chrono::steady_clock::time_point const& deadline)
noexcept
{
std::tuple<std::optional<
websocket_client::message>, int> result;
std::get<1>(result) = recv_until(
std::get<0>(result), deadline);
return result;
}
int websocket_client::recv_until(
std::optional<websocket_client::message>& result,
std::chrono::steady_clock::time_point const& deadline)
noexcept
{
scoped_lock lock(state_lock);
while (stopping || rx_queue.empty()) {
if (stopping || cv.wait_until(lock, deadline) ==
std::cv_status::timeout)
{
result = std::nullopt;
return ERROR_TIMEOUT;
}
}
result = std::move(rx_queue.front());
rx_queue.pop();
return ERROR_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment