fix potential crash in websocket

This commit is contained in:
Daniel Larimer 2015-09-07 17:46:08 -04:00
parent 08944de151
commit 19e42ac4c4

View file

@ -196,7 +196,11 @@ namespace fc { namespace http {
wdump(("server")(msg->get_payload()));
//std::cerr<<"recv: "<<msg->get_payload()<<"\n";
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();
});
@ -274,6 +278,7 @@ namespace fc { namespace http {
websocket_server_type _server;
on_connection_handler _on_connection;
fc::promise<void>::ptr _closed;
uint32_t _pending_messages = 0;
};
class websocket_tls_server_impl
@ -315,8 +320,8 @@ namespace fc { namespace http {
auto current_con = _connections.find(hdl);
assert( current_con != _connections.end() );
auto received = msg->get_payload();
wdump((received));
fc::async([=](){ current_con->second->on_message( received ); });
std::shared_ptr<websocket_connection> con = current_con->second;
fc::async([con,received](){ con->on_message( received ); });
}).wait();
});