Skip to content

Commit

Permalink
Handle WebSockets errors while sending messages
Browse files Browse the repository at this point in the history
(cherry picked from commit 9015d412d2f2051eb6766d402ecf329d34adb0c0)
  • Loading branch information
garethsb committed Jun 8, 2018
1 parent b6c85bc commit 91cb17d
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion Development/nmos/query_ws_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,21 @@ namespace nmos
web::websockets::experimental::listener::websocket_outgoing_message message;
message.set_utf8_message(serialized);

listener.send(websocket.second, message);
// hmmm, no way to cancel this currently...
auto send = listener.send(websocket.second, message).then([&](pplx::task<void> finally)
{
try
{
finally.get();
}
catch (const web::websockets::experimental::listener::websocket_exception& e)
{
slog::log<slog::severities::error>(gate, SLOG_FLF) << "WebSockets error: " << e.what() << " [" << e.error_code() << "]";
}
});
// current websocket_listener implementation is synchronous in any case, but just to make clear...
// for now, wait for the message to be sent
send.wait();

// reset the grain for next time
model.resources.modify(grain, [&model](nmos::resource& grain)
Expand Down

0 comments on commit 91cb17d

Please sign in to comment.