//------------------------------------------------------------------------------ /* Copyright (c) 2011-2013, OpenCoin, Inc. */ //============================================================================== #ifndef __SNTPCLIENT__ #define __SNTPCLIENT__ class SNTPQuery { public: bool mReceivedReply; time_t mLocalTimeSent; uint32 mQueryNonce; SNTPQuery (time_t j = (time_t) - 1) : mReceivedReply (false), mLocalTimeSent (j) { ; } }; class SNTPClient : LeakChecked { public: SNTPClient (boost::asio::io_service& service); void init (const std::vector& servers); void addServer (const std::string& mServer); void queryAll (); bool doQuery (); bool getOffset (int& offset); private: std::map mQueries; boost::mutex mLock; boost::asio::ip::udp::socket mSocket; boost::asio::deadline_timer mTimer; boost::asio::ip::udp::resolver mResolver; std::vector< std::pair > mServers; int mOffset; time_t mLastOffsetUpdate; std::list mOffsetList; std::vector mReceiveBuffer; boost::asio::ip::udp::endpoint mReceiveEndpoint; void receivePacket (const boost::system::error_code& error, std::size_t bytes); void resolveComplete (const boost::system::error_code& error, boost::asio::ip::udp::resolver::iterator iterator); void sentPacket (boost::shared_ptr, const boost::system::error_code&, std::size_t); void timerEntry (const boost::system::error_code&); void sendComplete (const boost::system::error_code& error, std::size_t bytesTransferred); void processReply (); }; #endif // vim:ts=4