Skip to content

Commit

Permalink
fix close frame (#576)
Browse files Browse the repository at this point in the history
  • Loading branch information
qicosmos authored May 3, 2024
1 parent 837a79a commit 5745cbb
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions include/cinatra/websocket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,12 @@ class websocket {

std::string format_close_payload(uint16_t code, char *message,
size_t length) {
if (length == 0) {
return "";
}
std::string close_payload;
if (code) {
close_payload.resize(length + 2);
code = htons(code);
std::memcpy(close_payload.data(), &code, 2);
close_payload.resize(length + 2);
code = htons(code);
std::memcpy(close_payload.data(), &code, 2);

if (length > 0) {
std::memcpy(close_payload.data() + 2, message, length);
}
return close_payload;
Expand Down

0 comments on commit 5745cbb

Please sign in to comment.