Deactivate connection on socket error

This commit is contained in:
Patrick Nicolas
2024-06-03 20:59:06 +02:00
parent 5d9d39eee5
commit 1266a46947
4 changed files with 33 additions and 9 deletions
+24 -8
View File
@@ -39,25 +39,41 @@ public:
wivrn_connection(const wivrn_connection &) = delete;
wivrn_connection & operator=(const wivrn_connection &) = delete;
void deactivate()
bool is_active()
{
active = false;
return active;
}
void reset(TCP && tcp);
template <typename T>
void send_control(T && packet)
{
if (active)
control.send(std::forward<T>(packet));
try
{
if (active)
control.send(std::forward<T>(packet));
}
catch (...)
{
active = false;
throw;
}
}
template <typename T>
void send_stream(T && packet)
{
if (active and stream)
stream.send(std::forward<T>(packet));
else
control.send(std::forward<T>(packet));
try
{
if (active and stream)
stream.send(std::forward<T>(packet));
else
control.send(std::forward<T>(packet));
}
catch (...)
{
active = false;
throw;
}
}
std::optional<from_headset::packets> poll_control(int timeout);