Skip to content

Commit 0f99a95

Browse files
committed
Enhance error handling in websocket write and read functions
1 parent e439e60 commit 0f99a95

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/websocket.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,12 @@ class Websocket : public std::enable_shared_from_this<Websocket>
264264
{
265265
if(ec)
266266
{
267-
return fail(ec, "write", nullptr, true);
267+
if (status_.load(std::memory_order_relaxed) != Status::DISCONNECTED &&
268+
ec != beast::websocket::error::closed && ec != asio::error::eof &&
269+
ec != asio::error::operation_aborted) {
270+
fail(ec, "write", nullptr, true);
271+
}
272+
return;
268273
}
269274
// LOG_TRACE("{}: {}({}) bytes written", id_, bytes_transferred, w_buffer_.size());
270275
w_buffer_.consume(bytes_transferred);
@@ -274,7 +279,12 @@ class Websocket : public std::enable_shared_from_this<Websocket>
274279
{
275280
if(ec)
276281
{
277-
return fail(ec, "read", nullptr, true);
282+
if (status_.load(std::memory_order_relaxed) != Status::DISCONNECTED &&
283+
ec != beast::websocket::error::closed && ec != asio::error::eof &&
284+
ec != asio::error::operation_aborted) {
285+
fail(ec, "read", nullptr, true);
286+
}
287+
return;
278288
}
279289

280290
LOG_TRACE("<-- {}", std::string((const char*)r_buffer_.data().data(), bytes_transferred));

0 commit comments

Comments
 (0)