aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorroxma <roxma@qq.com>2017-12-22 17:50:41 +0800
committerroxma <roxma@qq.com>2017-12-22 17:53:51 +0800
commitf0eb73ce8cc111a11473f346b640decce5e76aa5 (patch)
treec7d192a09f059725cd70a9cc64ea32570609b3d7
parent7f3f72441c242836d00ab2109a83baef89c08aaa (diff)
downloadcrow-f0eb73ce8cc111a11473f346b640decce5e76aa5.tar.gz
crow-f0eb73ce8cc111a11473f346b640decce5e76aa5.zip
Fix ws read failure when using 16bit payload
Also should use ntohs instead of htons when read from socket.
-rw-r--r--include/crow/websocket.h7
1 files changed, 4 insertions, 3 deletions
diff --git a/include/crow/websocket.h b/include/crow/websocket.h
index ee0885f..58b9a7e 100644
--- a/include/crow/websocket.h
+++ b/include/crow/websocket.h
@@ -191,7 +191,7 @@ namespace crow
{
is_reading = false;
- mini_header_ = htons(mini_header_);
+ mini_header_ = ntohs(mini_header_);
#ifdef CROW_ENABLE_DEBUG
if (!ec && bytes_transferred != 2)
@@ -231,9 +231,9 @@ namespace crow
case WebSocketReadState::Len16:
{
remaining_length_ = 0;
- uint16_t remaining_length16_ = 0;
+ remaining_length16_ = 0;
boost::asio::async_read(adaptor_.socket(), boost::asio::buffer(&remaining_length16_, 2),
- [this,&remaining_length16_](const boost::system::error_code& ec, std::size_t
+ [this](const boost::system::error_code& ec, std::size_t
#ifdef CROW_ENABLE_DEBUG
bytes_transferred
#endif
@@ -502,6 +502,7 @@ namespace crow
std::string message_;
std::string fragment_;
WebSocketReadState state_{WebSocketReadState::MiniHeader};
+ uint16_t remaining_length16_{0};
uint64_t remaining_length_{0};
bool close_connection_{false};
bool is_reading{false};