diff --git a/include/fc/ip.hpp b/include/fc/ip.hpp index ddb7dbd..a34ee6b 100644 --- a/include/fc/ip.hpp +++ b/include/fc/ip.hpp @@ -37,7 +37,14 @@ namespace fc { private: address _ip; - uint16_t _port; + /** + * The compiler pads endpoint to a full 8 bytes, so while + * a port number is limited in range to 16 bits, we specify + * a full 32 bits so that memcmp can be used with sizeof(), + * otherwise 2 bytes will be 'random' and you do not know + * where they are stored. + */ + uint32_t _port; }; } } diff --git a/include/fc/optional.hpp b/include/fc/optional.hpp index fb4b5a7..4902360 100644 --- a/include/fc/optional.hpp +++ b/include/fc/optional.hpp @@ -41,15 +41,15 @@ namespace fc { new (&**this) T( fc::forward(u) ); _valid = true; } else { - **this = u; + **this = fc::forward(u); } return *this; } optional& operator=( const optional& o ) { - if( _valid && o.valid ) { **this = *o; } + if( _valid && o._valid ) { **this = *o; } else if( !_valid && o._valid ) { - *this = **o; + *this = *o; } // else !_valid && !o._valid == same! return *this; } @@ -59,8 +59,8 @@ namespace fc { T& operator*() { void* v = &_value[0]; return *static_cast(v); } const T& operator*()const { const void* v = &_value[0]; return *static_cast(v); } - T& operator->() { void* v = &_value[0]; return *static_cast(v); } - const T& operator->()const { const void* v = &_value[0]; return *static_cast(v); } + T* operator->() { void* v = &_value[0]; return static_cast(v); } + const T* operator->()const { const void* v = &_value[0]; return static_cast(v); } private: // force alignment... to 8 byte boundaries diff --git a/include/fc/reflect_vector.hpp b/include/fc/reflect_vector.hpp index 8421b73..49e5e22 100644 --- a/include/fc/reflect_vector.hpp +++ b/include/fc/reflect_vector.hpp @@ -2,6 +2,8 @@ #define _FC_REFLECT_VECTOR_HPP_ #include #include +#include + namespace fc { template class reflector> : public detail::reflector_impl, reflector> >{ @@ -23,5 +25,24 @@ namespace fc { } static reflector& instance() { static reflector inst; return inst; } }; + template<> + class reflector> : public detail::reflector_impl, reflector> >{ + public: + virtual const char* name()const { + return "vector"; + } + virtual void visit( void* s, const abstract_visitor& v )const { + vector& vec = *((vector*)s); + fc::string hex; + v.visit( hex ); + vec.resize( hex.size() / 2 ); + fc::from_hex( hex, vec.data(), vec.size() ); + } + virtual void visit( const void* s, const abstract_const_visitor& v )const { + const vector& vec = *((const vector*)s); + v.visit( fc::to_hex( vec.data(), vec.size() ) ); + } + static reflector& instance() { static reflector inst; return inst; } + }; } // namespace fc #endif // _FC_REFLECT_VECTOR_HPP_ diff --git a/include/fc/vector.hpp b/include/fc/vector.hpp index f49a31e..94e9514 100644 --- a/include/fc/vector.hpp +++ b/include/fc/vector.hpp @@ -56,12 +56,15 @@ namespace fc { struct vector_impl { public: vector_impl():_data(nullptr){} - vector_impl( vector_impl&& c):_data(c._data){c._data =nullptr; } + vector_impl( vector_impl&& c):_data(c._data){c._data =nullptr; slog( "move size %d",size()); } vector_impl( const vector_impl& c):_data(nullptr) { + slog( "copy: c.size %d", c.size() ); if( c.size() ) { _data = detail::data::allocate( c.size() ); + _data->size = c.size(); memcpy(begin(),c.begin(),c.size() ); } + slog( "copy: this.size %d", size() ); } vector_impl(uint64_t s):_data(nullptr){ resize(s); diff --git a/src/ip.cpp b/src/ip.cpp index 6e45c42..48b22e0 100644 --- a/src/ip.cpp +++ b/src/ip.cpp @@ -30,7 +30,7 @@ namespace fc { namespace ip { endpoint::endpoint() - :_port(0){} + :_port(0){ } endpoint::endpoint(const address& a, uint16_t p) :_port(p),_ip(a){} diff --git a/src/thread.cpp b/src/thread.cpp index 668986e..fba03bd 100644 --- a/src/thread.cpp +++ b/src/thread.cpp @@ -226,6 +226,7 @@ namespace fc { } void thread::async_task( task_base* t, const priority& p, const time_point& tp, const char* desc ) { + assert(my); t->_when = tp; // slog( "when %lld", t->_when.time_since_epoch().count() ); // slog( "delay %lld", (tp - fc::time_point::now()).count() ); diff --git a/src/udp_socket.cpp b/src/udp_socket.cpp index 4901062..4ed2bc1 100644 --- a/src/udp_socket.cpp +++ b/src/udp_socket.cpp @@ -9,6 +9,9 @@ namespace fc { class udp_socket::impl { public: impl():_sock( fc::asio::default_io_service() ){} + ~impl(){ + _sock.cancel(); + } boost::asio::ip::udp::socket _sock; };