Ngnix clock ngx_gettimeofday Update Time

Source: Internet
Author: User

Ngxin project, which has a Windows version. to optimize performance, use timegettime (); to obtain the time.

As a result, the clock is unstable, and the clock does not run after a period of normal operation, or times out.

An error occurs when timegettime () is used to obtain the returned value. According to msdn, this function cannot be used directly for code operations.

Http://msdn.microsoft.com/en-us/library/ms713418.aspx

Timegettime

This can cause problems in code that directly uses the timegettime return value in computations, where the value is used to control code execution. You shoshould always use the difference between two timegettime return values
In computations.

Voidngx_gettimeofday (struct timeval * TP) {# ifdef ngx_win32 DWORD dt = timegettime (); // error code item TP-> TV _sec = (long) (Dt/1000 ); TP-> TV _usec = (long) (DT * 1000); # else ulonglong USEC; filetime ft; systemtime st; getsystemtime (& St); systemtimetofiletime (& St, & ft ); USEC = ft. dwhighdatetime; USEC <= 32; USEC | = ft. dwlowdatetime; USEC/= 10; USEC-= 11644473600000000ll; TP-> TV _sec = (long) (USEC/1000000); TP-> TV _usec = (long) (USEC % 1000000 ); # endif // ngx_win32}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.