Fix ntp on win32

This commit is contained in:
Eric Frias 2014-07-25 14:40:47 -04:00
parent 8fff034711
commit c208a968b2

View file

@ -44,6 +44,8 @@ namespace fc
std::array<unsigned char, 48> send_buf { {010,0,0,0,0,0,0,0,0} }; std::array<unsigned char, 48> send_buf { {010,0,0,0,0,0,0,0,0} };
_last_request_time = fc::time_point::now(); _last_request_time = fc::time_point::now();
_sock.send_to( (const char*)send_buf.data(), send_buf.size(), ep ); _sock.send_to( (const char*)send_buf.data(), send_buf.size(), ep );
if (!_read_loop.valid() || _read_loop.ready())
_read_loop = async( [this](){ read_loop(); } );
break; break;
} }
} }
@ -105,9 +107,9 @@ namespace fc
:my( new detail::ntp_impl() ) :my( new detail::ntp_impl() )
{ {
my->_sock.open(); my->_sock.open();
// if you start the read loop here, the recieve_from call will throw "invalid argument" on win32,
// so instead we trigger the read loop after making our first request
my->_ntp_thread.async( [=](){ my->request_time(); } ); my->_ntp_thread.async( [=](){ my->request_time(); } );
my->_read_loop = my->_ntp_thread.async( [=](){ my->read_loop(); } );
} }
ntp::~ntp() ntp::~ntp()
@ -137,7 +139,7 @@ namespace fc
void ntp::request_now() void ntp::request_now()
{ {
my->request_now(); my->_ntp_thread.async( [=](){ my->request_now(); } ).wait();
} }
optional<time_point> ntp::get_time()const optional<time_point> ntp::get_time()const