fix potential crash in websocket
This commit is contained in:
parent
08944de151
commit
19e42ac4c4
1 changed files with 8 additions and 3 deletions
|
|
@ -196,7 +196,11 @@ namespace fc { namespace http {
|
||||||
wdump(("server")(msg->get_payload()));
|
wdump(("server")(msg->get_payload()));
|
||||||
//std::cerr<<"recv: "<<msg->get_payload()<<"\n";
|
//std::cerr<<"recv: "<<msg->get_payload()<<"\n";
|
||||||
auto payload = msg->get_payload();
|
auto payload = msg->get_payload();
|
||||||
fc::async([=](){ current_con->second->on_message( payload ); });
|
std::shared_ptr<websocket_connection> con = current_con->second;
|
||||||
|
++_pending_messages;
|
||||||
|
auto f = fc::async([this,con,payload](){ if( _pending_messages ) --_pending_messages; con->on_message( payload ); });
|
||||||
|
if( _pending_messages > 100 ) f.wait();
|
||||||
|
|
||||||
}).wait();
|
}).wait();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -274,6 +278,7 @@ namespace fc { namespace http {
|
||||||
websocket_server_type _server;
|
websocket_server_type _server;
|
||||||
on_connection_handler _on_connection;
|
on_connection_handler _on_connection;
|
||||||
fc::promise<void>::ptr _closed;
|
fc::promise<void>::ptr _closed;
|
||||||
|
uint32_t _pending_messages = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class websocket_tls_server_impl
|
class websocket_tls_server_impl
|
||||||
|
|
@ -315,8 +320,8 @@ namespace fc { namespace http {
|
||||||
auto current_con = _connections.find(hdl);
|
auto current_con = _connections.find(hdl);
|
||||||
assert( current_con != _connections.end() );
|
assert( current_con != _connections.end() );
|
||||||
auto received = msg->get_payload();
|
auto received = msg->get_payload();
|
||||||
wdump((received));
|
std::shared_ptr<websocket_connection> con = current_con->second;
|
||||||
fc::async([=](){ current_con->second->on_message( received ); });
|
fc::async([con,received](){ con->on_message( received ); });
|
||||||
}).wait();
|
}).wait();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue