Skip to content

Commit

Permalink
Merge pull request #452 from MichaelSB/ws_no_read_after_close
Browse files Browse the repository at this point in the history
do not try to read from websocket after sending and receiving the clo…
  • Loading branch information
The-EDev authored Jun 4, 2022
2 parents 017c6e3 + efee717 commit ed87c65
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions include/crow/websocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,15 @@ namespace crow
/// Reading the actual payload.<br>
void do_read()
{
if (has_sent_close_ && has_recv_close_)
{
close_connection_ = true;
adaptor_.shutdown_readwrite();
adaptor_.close();
check_destroy();
return;
}

is_reading = true;
switch (state_)
{
Expand Down Expand Up @@ -475,9 +484,11 @@ namespace crow
remaining_length_ -= bytes_transferred;
if (remaining_length_ == 0)
{
handle_fragment();
state_ = WebSocketReadState::MiniHeader;
do_read();
if (handle_fragment())
{
state_ = WebSocketReadState::MiniHeader;
do_read();
}
}
else
do_read();
Expand Down Expand Up @@ -513,7 +524,7 @@ namespace crow

///
/// Unmasks the fragment, checks the opcode, merges fragments into 1 message body, and calls the appropriate handler.
void handle_fragment()
bool handle_fragment()
{
if (has_mask_)
{
Expand Down Expand Up @@ -578,6 +589,7 @@ namespace crow
is_close_handler_called_ = true;
}
check_destroy();
return false;
}
}
break;
Expand All @@ -594,6 +606,7 @@ namespace crow
}

fragment_.clear();
return true;
}

/// Send the buffers' data through the socket.
Expand Down

0 comments on commit ed87c65

Please sign in to comment.