ipkn / crow

Crow is very fast and easy to use C++ micro web framework (inspired by Python Flask)
BSD 3-Clause "New" or "Revised" License
7.47k stars 889 forks source link

Update websocket.h function "void do_read()" #383

Open nowgoing opened 4 years ago

nowgoing commented 4 years ago

Reason for update:

When state_ == WebSocketReadState::Payload, The function async_read_some() is not guaranteed to read all the data. When remaininglength != 0 , you need to continue reading.

mrozigor commented 4 years ago

Can you write UT to show that problem exists? Because it looks like state isn't changed from WebSocketReadState::Payload, when remaining_length is different than 0. So it looks like staying in mentioned state up to point, when length equals 0.

nowgoing commented 4 years ago

Add test code print log

image

The log output is as follows

image When remaininglength != 0 , websocket will stop reading.

mrozigor commented 4 years ago

But it's weird that moment earlier same amount of data are read at once.

nowgoing commented 4 years ago

So async_read_some() is not guaranteed to read the message data;The above problem occurs when binary audio data is transmitted using WebSocket, with 25 packets per second。

mrozigor commented 4 years ago

That's true. But you can only add else block, without assigning state_ variable.

mrozigor commented 4 years ago

Thanks! I've merged it to my fork :)