fixed bugs
This commit is contained in:
parent
ee55a08ab0
commit
5877435927
7 changed files with 43 additions and 8 deletions
|
|
@ -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;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,15 +41,15 @@ namespace fc {
|
|||
new (&**this) T( fc::forward<U>(u) );
|
||||
_valid = true;
|
||||
} else {
|
||||
**this = u;
|
||||
**this = fc::forward<U>(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<T*>(v); }
|
||||
const T& operator*()const { const void* v = &_value[0]; return *static_cast<const T*>(v); }
|
||||
|
||||
T& operator->() { void* v = &_value[0]; return *static_cast<T*>(v); }
|
||||
const T& operator->()const { const void* v = &_value[0]; return *static_cast<const T*>(v); }
|
||||
T* operator->() { void* v = &_value[0]; return static_cast<T*>(v); }
|
||||
const T* operator->()const { const void* v = &_value[0]; return static_cast<const T*>(v); }
|
||||
|
||||
private:
|
||||
// force alignment... to 8 byte boundaries
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
#define _FC_REFLECT_VECTOR_HPP_
|
||||
#include <fc/reflect.hpp>
|
||||
#include <fc/vector.hpp>
|
||||
#include <fc/hex.hpp>
|
||||
|
||||
namespace fc {
|
||||
template<typename T>
|
||||
class reflector<fc::vector<T>> : public detail::reflector_impl<vector<T>, reflector<vector<T>> >{
|
||||
|
|
@ -23,5 +25,24 @@ namespace fc {
|
|||
}
|
||||
static reflector& instance() { static reflector inst; return inst; }
|
||||
};
|
||||
template<>
|
||||
class reflector<fc::vector<char>> : public detail::reflector_impl<vector<char>, reflector<vector<char>> >{
|
||||
public:
|
||||
virtual const char* name()const {
|
||||
return "vector<char>";
|
||||
}
|
||||
virtual void visit( void* s, const abstract_visitor& v )const {
|
||||
vector<char>& vec = *((vector<char>*)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<char>& vec = *((const vector<char>*)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_
|
||||
|
|
|
|||
|
|
@ -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<T>::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);
|
||||
|
|
|
|||
|
|
@ -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() );
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue