diff -r 000000000000 -r 4eba9c11703f web/Zend/TimeSync/Sntp.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/web/Zend/TimeSync/Sntp.php Mon Dec 13 18:29:26 2010 +0100 @@ -0,0 +1,119 @@ +_timeserver = 'udp://' . $timeserver; + if ($port !== null) { + $this->_port = $port; + } + } + + /** + * Prepares the data that will be send to the timeserver + * + * @return array + */ + protected function _prepare() + { + return "\n"; + } + + /** + * Reads the data returned from the timeserver + * + * @return string + */ + protected function _read() + { + $result = fread($this->_socket, 49); + $this->_delay = (($this->_delay - time()) / 2); + + return $result; + } + + /** + * Writes data to to the timeserver + * + * @param string $data Data to write to the timeserver + * @return void + */ + protected function _write($data) + { + $this->_connect(); + $this->_delay = time(); + fputs($this->_socket, $data); + } + + /** + * Extracts the data returned from the timeserver + * + * @param string $result Data to extract + * @return integer + */ + protected function _extract($result) + { + $dec = hexdec('7fffffff'); + $time = abs(($dec - hexdec(bin2hex($result))) - $dec); + $time -= 2208988800; + // Socket delay + $time -= $this->_delay; + + $this->_info['offset'] = $this->_delay; + + return $time; + } +}