summaryrefslogtreecommitdiffhomepage
path: root/websocket.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'websocket.cpp')
-rw-r--r--websocket.cpp30
1 files changed, 24 insertions, 6 deletions
diff --git a/websocket.cpp b/websocket.cpp
index 68ff194..d361ec1 100644
--- a/websocket.cpp
+++ b/websocket.cpp
@@ -65,6 +65,20 @@ public:
relative_target_ = websocket_address.substr(slash_pos);
}
+ void fail(boost::beast::error_code ec, char const* what)
+ {
+ if (ec == websocket::error::closed)
+ return;
+
+ boost::beast::error_code ec2;
+ if (auto& ws_in{derived().ws_in()}; ws_in.is_open())
+ ws_in.close(beast::websocket::close_code::going_away, ec2);
+ if (auto& ws_app{ws_app_}; ws_app.is_open())
+ ws_app.close(beast::websocket::close_code::going_away, ec2);
+
+ std::cerr << what << ": " << ec.message() << "\n";
+ }
+
//
// The initial setup path
//
@@ -181,8 +195,10 @@ private:
if (ec == websocket::error::closed)
return;
- if (ec)
- fail(ec, "read in");
+ if (ec) {
+ // not error::closed as above, but no other strategy known
+ return fail(ec, "read in");
+ }
ws_app_.text(derived().ws_in().got_text());
@@ -202,7 +218,7 @@ private:
boost::ignore_unused(bytes_transferred);
if (ec)
- fail(ec, "write app");
+ return fail(ec, "write app");
buffer_in_.consume(buffer_in_.size());
@@ -231,8 +247,10 @@ private:
if (ec == websocket::error::closed)
return;
- if (ec)
- fail(ec, "read app");
+ if (ec) {
+ // not error::closed as above, but no other strategy known
+ return fail(ec, "read app");
+ }
do_write_out();
}
@@ -251,7 +269,7 @@ private:
{
boost::ignore_unused(bytes_transferred);
- if(ec)
+ if (ec)
return fail(ec, "write out");
// Clear the buffer