ngnix 時鐘 ngx_gettimeofday 更新時間

來源:互聯網
上載者:User

ngxin 項目,有 windows 版本,之前為了最佳化效能,用 timeGetTime(); 擷取時間。

這樣導致了時鐘不穩定,時鐘正常跑一段時間後就不跑了,或者逾時。

用 timeGetTime(); 擷取返回的數值不定時出現問題。按 msdn 說,這個函數不能單獨直接使用於代碼運算。

 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, particularly where the value is used to control code execution. You should always use the difference between two timeGetTime return values
in computations. 

voidngx_gettimeofday(struct timeval *tp){#ifdef NGX_WIN32    DWORD dt = timeGetTime(); // 錯誤碼項    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}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.