Merge branch 'master' of github.com:BitShares/fc
This commit is contained in:
commit
cf4ed08d4b
5 changed files with 38 additions and 9 deletions
|
|
@ -21,6 +21,7 @@ class sha256
|
||||||
|
|
||||||
static sha256 hash( const char* d, uint32_t dlen );
|
static sha256 hash( const char* d, uint32_t dlen );
|
||||||
static sha256 hash( const string& );
|
static sha256 hash( const string& );
|
||||||
|
static sha256 hash( const sha256& );
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
static sha256 hash( const T& t )
|
static sha256 hash( const T& t )
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,11 @@ namespace fc { namespace rpc {
|
||||||
*/
|
*/
|
||||||
future<void> exec();
|
future<void> exec();
|
||||||
|
|
||||||
|
bool is_open();
|
||||||
|
void close();
|
||||||
|
|
||||||
|
void set_on_disconnected_callback(std::function<void(fc::exception_ptr)> callback);
|
||||||
|
|
||||||
logger get_logger()const;
|
logger get_logger()const;
|
||||||
void set_logger( const logger& l );
|
void set_logger( const logger& l );
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -40,10 +40,16 @@ namespace fc {
|
||||||
e.write(d,dlen);
|
e.write(d,dlen);
|
||||||
return e.result();
|
return e.result();
|
||||||
}
|
}
|
||||||
|
|
||||||
sha256 sha256::hash( const string& s ) {
|
sha256 sha256::hash( const string& s ) {
|
||||||
return hash( s.c_str(), s.size() );
|
return hash( s.c_str(), s.size() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sha256 sha256::hash( const sha256& s )
|
||||||
|
{
|
||||||
|
return hash( s.data(), sizeof( s._hash ) );
|
||||||
|
}
|
||||||
|
|
||||||
void sha256::encoder::write( const char* d, uint32_t dlen ) {
|
void sha256::encoder::write( const char* d, uint32_t dlen ) {
|
||||||
SHA256_Update( &my->ctx, d, dlen);
|
SHA256_Update( &my->ctx, d, dlen);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,12 @@ namespace fc {
|
||||||
~impl()
|
~impl()
|
||||||
{
|
{
|
||||||
if( _sock.is_open() )
|
if( _sock.is_open() )
|
||||||
_sock.close();
|
try
|
||||||
|
{
|
||||||
|
_sock.close();
|
||||||
|
}
|
||||||
|
catch( ... )
|
||||||
|
{}
|
||||||
if( _read_in_progress.valid() )
|
if( _read_in_progress.valid() )
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ namespace fc { namespace rpc {
|
||||||
boost::unordered_map<std::string, json_connection::named_param_method> _named_param_methods;
|
boost::unordered_map<std::string, json_connection::named_param_method> _named_param_methods;
|
||||||
|
|
||||||
fc::mutex _write_mutex;
|
fc::mutex _write_mutex;
|
||||||
//std::function<void(fc::exception_ptr)> _on_close;
|
std::function<void(fc::exception_ptr)> _on_close;
|
||||||
|
|
||||||
logger _logger;
|
logger _logger;
|
||||||
|
|
||||||
|
|
@ -226,6 +226,8 @@ namespace fc { namespace rpc {
|
||||||
void close( fc::exception_ptr e )
|
void close( fc::exception_ptr e )
|
||||||
{
|
{
|
||||||
wlog( "close ${reason}", ("reason", e->to_detail_string() ) );
|
wlog( "close ${reason}", ("reason", e->to_detail_string() ) );
|
||||||
|
if( _on_close )
|
||||||
|
_on_close(e);
|
||||||
for( auto itr = _awaiting.begin(); itr != _awaiting.end(); ++itr )
|
for( auto itr = _awaiting.begin(); itr != _awaiting.end(); ++itr )
|
||||||
{
|
{
|
||||||
itr->second->set_exception( e->dynamic_copy_exception() );
|
itr->second->set_exception( e->dynamic_copy_exception() );
|
||||||
|
|
@ -239,6 +241,20 @@ namespace fc { namespace rpc {
|
||||||
{}
|
{}
|
||||||
|
|
||||||
json_connection::~json_connection()
|
json_connection::~json_connection()
|
||||||
|
{
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
|
||||||
|
fc::future<void> json_connection::exec()
|
||||||
|
{
|
||||||
|
if( my->_done.valid() )
|
||||||
|
{
|
||||||
|
FC_THROW_EXCEPTION( assert_exception, "start should only be called once" );
|
||||||
|
}
|
||||||
|
return my->_done = fc::async( [=](){ my->read_loop(); }, "json_connection read_loop" );
|
||||||
|
}
|
||||||
|
|
||||||
|
void json_connection::close()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
@ -250,7 +266,7 @@ namespace fc { namespace rpc {
|
||||||
my->_out->close();
|
my->_out->close();
|
||||||
my->_done.wait();
|
my->_done.wait();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch ( fc::canceled_exception& ){} // expected exception
|
catch ( fc::canceled_exception& ){} // expected exception
|
||||||
catch ( fc::eof_exception& ){} // expected exception
|
catch ( fc::eof_exception& ){} // expected exception
|
||||||
catch ( fc::exception& e )
|
catch ( fc::exception& e )
|
||||||
|
|
@ -260,13 +276,9 @@ namespace fc { namespace rpc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fc::future<void> json_connection::exec()
|
void json_connection::set_on_disconnected_callback(std::function<void (exception_ptr)> callback)
|
||||||
{
|
{
|
||||||
if( my->_done.valid() )
|
my->_on_close = callback;
|
||||||
{
|
|
||||||
FC_THROW_EXCEPTION( assert_exception, "start should only be called once" );
|
|
||||||
}
|
|
||||||
return my->_done = fc::async( [=](){ my->read_loop(); }, "json_connection read_loop" );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void json_connection::add_method( const fc::string& name, method m )
|
void json_connection::add_method( const fc::string& name, method m )
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue