From 43659333d3847adaae7034dd36a989ded6c400e6 Mon Sep 17 00:00:00 2001 From: Vikram Rajkumar Date: Tue, 3 Feb 2015 18:12:37 -0500 Subject: [PATCH 1/7] Fix compiler warning --- src/filesystem.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/filesystem.cpp b/src/filesystem.cpp index 85dd1f5..a590065 100644 --- a/src/filesystem.cpp +++ b/src/filesystem.cpp @@ -520,13 +520,13 @@ namespace fc { }; simple_lock_file::impl::impl(const path& lock_file_path) : - is_locked(false), - lock_file_path(lock_file_path), #ifdef _WIN32 - file_handle(INVALID_HANDLE_VALUE) + file_handle(INVALID_HANDLE_VALUE), #else - file_handle(-1) + file_handle(-1), #endif + is_locked(false), + lock_file_path(lock_file_path) {} simple_lock_file::impl::~impl() From 41630e7629180e32d1e1c26a2c8e251e9456ad3e Mon Sep 17 00:00:00 2001 From: Vikram Rajkumar Date: Wed, 4 Feb 2015 18:05:28 -0500 Subject: [PATCH 2/7] Pretty-print objects in log messages --- src/variant.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/variant.cpp b/src/variant.cpp index 9df67da..e1d6df7 100644 --- a/src/variant.cpp +++ b/src/variant.cpp @@ -693,7 +693,7 @@ string format_string( const string& format, const variant_object& args ) { if( val->value().is_object() || val->value().is_array() ) { - ss << json::to_string( val->value() ); + ss << '\n' << json::to_pretty_string( val->value() ); } else { From 54a51c3471662ecde8e3579eb63090a87a0525cb Mon Sep 17 00:00:00 2001 From: Vikram Rajkumar Date: Thu, 5 Feb 2015 18:52:03 -0500 Subject: [PATCH 3/7] Define fc::ripemd160::hash() for arbitrary serializable objects --- include/fc/crypto/ripemd160.hpp | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/include/fc/crypto/ripemd160.hpp b/include/fc/crypto/ripemd160.hpp index 4c2e3b6..2539412 100644 --- a/include/fc/crypto/ripemd160.hpp +++ b/include/fc/crypto/ripemd160.hpp @@ -1,14 +1,15 @@ #pragma once -#include -#include -#include +#include +#include +#include +#include namespace fc{ class sha512; class sha256; -class ripemd160 +class ripemd160 { public: ripemd160(); @@ -25,14 +26,14 @@ class ripemd160 static ripemd160 hash( const string& ); template - static ripemd160 hash( const T& t ) - { - ripemd160::encoder e; - e << t; - return e.result(); - } + static ripemd160 hash( const T& t ) + { + ripemd160::encoder e; + fc::raw::pack( e, t ); + return e.result(); + } - class encoder + class encoder { public: encoder(); @@ -64,10 +65,10 @@ class ripemd160 friend bool operator != ( const ripemd160& h1, const ripemd160& h2 ); friend ripemd160 operator ^ ( const ripemd160& h1, const ripemd160& h2 ); friend bool operator >= ( const ripemd160& h1, const ripemd160& h2 ); - friend bool operator > ( const ripemd160& h1, const ripemd160& h2 ); - friend bool operator < ( const ripemd160& h1, const ripemd160& h2 ); - - uint32_t _hash[5]; + friend bool operator > ( const ripemd160& h1, const ripemd160& h2 ); + friend bool operator < ( const ripemd160& h1, const ripemd160& h2 ); + + uint32_t _hash[5]; }; class variant; From 9c5450185a3d74b41f4a9722185a191bcbb2362a Mon Sep 17 00:00:00 2001 From: Vikram Rajkumar Date: Thu, 5 Feb 2015 18:52:59 -0500 Subject: [PATCH 4/7] Revert "Pretty-print objects in log messages" This reverts commit 41630e7629180e32d1e1c26a2c8e251e9456ad3e. --- src/variant.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/variant.cpp b/src/variant.cpp index e1d6df7..9df67da 100644 --- a/src/variant.cpp +++ b/src/variant.cpp @@ -693,7 +693,7 @@ string format_string( const string& format, const variant_object& args ) { if( val->value().is_object() || val->value().is_array() ) { - ss << '\n' << json::to_pretty_string( val->value() ); + ss << json::to_string( val->value() ); } else { From 55c5d9592095f554333639b71e8f7ea006579518 Mon Sep 17 00:00:00 2001 From: Eric Frias Date: Mon, 9 Feb 2015 18:55:58 -0500 Subject: [PATCH 5/7] Add raw serialization of real128 --- include/fc/real128.hpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/include/fc/real128.hpp b/include/fc/real128.hpp index 98033b5..3a7d26d 100644 --- a/include/fc/real128.hpp +++ b/include/fc/real128.hpp @@ -1,3 +1,4 @@ +#pragma once #include #define FC_REAL128_PRECISION (uint64_t(1000000) * uint64_t(1000000) * uint64_t(1000000)) @@ -38,4 +39,14 @@ namespace fc { void to_variant( const real128& var, variant& vo ); void from_variant( const variant& var, real128& vo ); + namespace raw + { + template + inline void pack( Stream& s, const real128& value_to_pack ) { s.write( (char*)&value_to_pack, sizeof(value_to_pack) ); } + template + inline void unpack( Stream& s, real128& value_to_unpack ) { s.read( (char*)&value_to_unpack, sizeof(value_to_unpack) ); } + } + + + } // namespace fc From b068865eb51b8562e3e590b99d404980d9239cd6 Mon Sep 17 00:00:00 2001 From: Nathan Hourt Date: Tue, 10 Feb 2015 18:35:50 -0500 Subject: [PATCH 6/7] Dumb hack that seems to prevent crashing when destroying json_connection --- include/fc/rpc/json_connection.hpp | 2 ++ src/rpc/json_connection.cpp | 36 ++++++++++++++---------------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/include/fc/rpc/json_connection.hpp b/include/fc/rpc/json_connection.hpp index dd8aba3..a0b36b8 100644 --- a/include/fc/rpc/json_connection.hpp +++ b/include/fc/rpc/json_connection.hpp @@ -32,6 +32,8 @@ namespace fc { namespace rpc { logger get_logger()const; void set_logger( const logger& l ); + void set_close_callback(std::function callback); + /** * @name server interface * diff --git a/src/rpc/json_connection.cpp b/src/rpc/json_connection.cpp index 77a3918..402d07d 100644 --- a/src/rpc/json_connection.cpp +++ b/src/rpc/json_connection.cpp @@ -16,6 +16,14 @@ namespace fc { namespace rpc { public: json_connection_impl( fc::buffered_istream_ptr&& in, fc::buffered_ostream_ptr&& out ) :_in(fc::move(in)),_out(fc::move(out)),_eof(false),_next_id(0),_logger("json_connection"){} + ~json_connection_impl() { + _done.cancel_and_wait(__FUNCTION__); + _out->close(); + _handle_message_future.cancel_and_wait(__FUNCTION__); + //Work around crash because _done.cancel_and_wait didn't work, and read_loop() is going to resume + //and crash us in just a moment if we allow ourselves to destroy now. + fc::usleep(fc::milliseconds(100)); + } fc::buffered_istream_ptr _in; fc::buffered_ostream_ptr _out; @@ -30,7 +38,7 @@ namespace fc { namespace rpc { boost::unordered_map _named_param_methods; fc::mutex _write_mutex; - //std::function _on_close; + std::function _on_close; logger _logger; @@ -225,6 +233,9 @@ namespace fc { namespace rpc { void close( fc::exception_ptr e ) { + e = fc::exception_ptr(new FC_EXCEPTION( unhandled_exception, "json connection closed" )); + if( _on_close ) + _on_close(e); wlog( "close ${reason}", ("reason", e->to_detail_string() ) ); for( auto itr = _awaiting.begin(); itr != _awaiting.end(); ++itr ) { @@ -240,24 +251,6 @@ namespace fc { namespace rpc { json_connection::~json_connection() { - try - { - if( my->_handle_message_future.valid() && !my->_handle_message_future.ready() ) - my->_handle_message_future.cancel_and_wait(__FUNCTION__); - if( my->_done.valid() && !my->_done.ready() ) - { - my->_done.cancel("json_connection is destructing"); - my->_out->close(); - my->_done.wait(); - } - } - catch ( fc::canceled_exception& ){} // expected exception - catch ( fc::eof_exception& ){} // expected exception - catch ( fc::exception& e ) - { - // unhandled, unexpected exception cannot throw from destructor, so log it. - wlog( "${exception}", ("exception",e.to_detail_string()) ); - } } fc::future json_connection::exec() @@ -698,4 +691,9 @@ namespace fc { namespace rpc { my->_logger = l; } + void json_connection::set_close_callback(std::function callback) + { + my->_on_close = callback; + } + }} From 13430fce127bb3fdba53d218dd840aea8e46408c Mon Sep 17 00:00:00 2001 From: Nathan Hourt Date: Wed, 11 Feb 2015 17:20:58 -0500 Subject: [PATCH 7/7] Revert "Dumb hack that seems to prevent crashing when destroying json_connection" This reverts commit b068865eb51b8562e3e590b99d404980d9239cd6. Caused crashes elsewhere. --- include/fc/rpc/json_connection.hpp | 2 -- src/rpc/json_connection.cpp | 36 ++++++++++++++++-------------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/include/fc/rpc/json_connection.hpp b/include/fc/rpc/json_connection.hpp index a0b36b8..dd8aba3 100644 --- a/include/fc/rpc/json_connection.hpp +++ b/include/fc/rpc/json_connection.hpp @@ -32,8 +32,6 @@ namespace fc { namespace rpc { logger get_logger()const; void set_logger( const logger& l ); - void set_close_callback(std::function callback); - /** * @name server interface * diff --git a/src/rpc/json_connection.cpp b/src/rpc/json_connection.cpp index 402d07d..77a3918 100644 --- a/src/rpc/json_connection.cpp +++ b/src/rpc/json_connection.cpp @@ -16,14 +16,6 @@ namespace fc { namespace rpc { public: json_connection_impl( fc::buffered_istream_ptr&& in, fc::buffered_ostream_ptr&& out ) :_in(fc::move(in)),_out(fc::move(out)),_eof(false),_next_id(0),_logger("json_connection"){} - ~json_connection_impl() { - _done.cancel_and_wait(__FUNCTION__); - _out->close(); - _handle_message_future.cancel_and_wait(__FUNCTION__); - //Work around crash because _done.cancel_and_wait didn't work, and read_loop() is going to resume - //and crash us in just a moment if we allow ourselves to destroy now. - fc::usleep(fc::milliseconds(100)); - } fc::buffered_istream_ptr _in; fc::buffered_ostream_ptr _out; @@ -38,7 +30,7 @@ namespace fc { namespace rpc { boost::unordered_map _named_param_methods; fc::mutex _write_mutex; - std::function _on_close; + //std::function _on_close; logger _logger; @@ -233,9 +225,6 @@ namespace fc { namespace rpc { void close( fc::exception_ptr e ) { - e = fc::exception_ptr(new FC_EXCEPTION( unhandled_exception, "json connection closed" )); - if( _on_close ) - _on_close(e); wlog( "close ${reason}", ("reason", e->to_detail_string() ) ); for( auto itr = _awaiting.begin(); itr != _awaiting.end(); ++itr ) { @@ -251,6 +240,24 @@ namespace fc { namespace rpc { json_connection::~json_connection() { + try + { + if( my->_handle_message_future.valid() && !my->_handle_message_future.ready() ) + my->_handle_message_future.cancel_and_wait(__FUNCTION__); + if( my->_done.valid() && !my->_done.ready() ) + { + my->_done.cancel("json_connection is destructing"); + my->_out->close(); + my->_done.wait(); + } + } + catch ( fc::canceled_exception& ){} // expected exception + catch ( fc::eof_exception& ){} // expected exception + catch ( fc::exception& e ) + { + // unhandled, unexpected exception cannot throw from destructor, so log it. + wlog( "${exception}", ("exception",e.to_detail_string()) ); + } } fc::future json_connection::exec() @@ -691,9 +698,4 @@ namespace fc { namespace rpc { my->_logger = l; } - void json_connection::set_close_callback(std::function callback) - { - my->_on_close = callback; - } - }}