Skip to content

Commit

Permalink
Merge pull request #1 from xmh0511/master
Browse files Browse the repository at this point in the history
fix a bug that empty data caused webosocket to throw an exception
  • Loading branch information
fawdlstty authored Apr 22, 2021
2 parents 67bf876 + 7143fe1 commit 5931855
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion asio
Submodule asio updated 1272 files
19 changes: 19 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,25 @@ int main()

std::shared_ptr<websocket> other_socket;


//websocket_event event;
//event.on("message", [](websocket& ws) {
// std::cout << view2str(ws.messages()) << std::endl;
// std::cout << (int)ws.message_code() << std::endl;
// std::string message;
// for (auto i = 0; i <= 18000; ++i) {
// message.append(std::to_string(i) + ",");
// }
// ws.write_string(message);
// }).on("open", [&other_socket](websocket& ws) {
// //auto data = ws.get_user_data<std::shared_ptr<std::string>>("tag");
// //other_socket = ws.shared_from_this();
// std::cout << ws.uuid() << " open " << std::endl;
// }).on("close", [](websocket& ws) {
// std::cout << ws.uuid() << " close" << std::endl;
// });
// server.router("/ws", event);

websocket_event event;
event.on("message", [](websocket& ws) {
std::cout << view2str(ws.messages()) << std::endl;
Expand Down
11 changes: 11 additions & 0 deletions xfinal/websokcet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,17 @@ namespace xfinal {
}
}
void read_data() {
if (frame_info_.payload_length == 0) { //没有数据需要读取
if (frame_info_.eof) {
message_ = std::string();
buffers_.resize(0);
data_current_pos_ = 0;
//数据帧都处理完整 回调
websocket_event_manager.trigger(url_, "message", *this);
}
start_read();
return;
}
expand_buffer(frame_info_.payload_length);
auto handler = this->shared_from_this();
start_read_timeout();
Expand Down

0 comments on commit 5931855

Please sign in to comment.