From 00eb9e2576ed6d6228b64169c37764ebf90cf8a2 Mon Sep 17 00:00:00 2001 From: Vladimir Serdyuk Date: Sat, 11 Sep 2021 16:49:46 +0300 Subject: [PATCH] asio: Fix MSVC build (after QUIC merge) --- src/util.cc | 31 ++++++++++++++++++++----------- src/util.h | 2 ++ 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/util.cc b/src/util.cc index ad7d681a..90f77777 100644 --- a/src/util.cc +++ b/src/util.cc @@ -418,27 +418,34 @@ char *iso8601_date(char *res, int64_t ms) { char *iso8601_basic_date(char *res, int64_t ms) { time_t sec = ms / 1000; - tm tms; - if (localtime_r(&sec, &tms) == nullptr) { - return res; + struct tm* ptms; +#if !defined(_MSC_VER) + struct tm tms; + ptms = localtime_r(&sec, &tms); +#else + ptms = localtime(&sec); +#endif + + if (ptms == nullptr) { + return res; } auto p = res; - p = cpydig(p, tms.tm_year + 1900, 4); - p = cpydig(p, tms.tm_mon + 1, 2); - p = cpydig(p, tms.tm_mday, 2); + p = cpydig(p, ptms->tm_year + 1900, 4); + p = cpydig(p, ptms->tm_mon + 1, 2); + p = cpydig(p, ptms->tm_mday, 2); *p++ = 'T'; - p = cpydig(p, tms.tm_hour, 2); - p = cpydig(p, tms.tm_min, 2); - p = cpydig(p, tms.tm_sec, 2); + p = cpydig(p, ptms->tm_hour, 2); + p = cpydig(p, ptms->tm_min, 2); + p = cpydig(p, ptms->tm_sec, 2); *p++ = '.'; p = cpydig(p, ms % 1000, 3); #ifdef HAVE_STRUCT_TM_TM_GMTOFF - auto gmtoff = tms.tm_gmtoff; + auto gmtoff = ptms->tm_gmtoff; #else // !HAVE_STRUCT_TM_TM_GMTOFF - auto gmtoff = nghttp2_timegm(&tms) - sec; + auto gmtoff = nghttp2_timegm(ptms) - sec; #endif // !HAVE_STRUCT_TM_TM_GMTOFF if (gmtoff == 0) { *p++ = 'Z'; @@ -1790,6 +1797,7 @@ int daemonize(int nochdir, int noclose) { #endif // !defined(__APPLE__) } +#ifdef ENABLE_HTTP3 int msghdr_get_local_addr(Address &dest, msghdr *msg, int family) { switch (family) { case AF_INET: @@ -1823,6 +1831,7 @@ int msghdr_get_local_addr(Address &dest, msghdr *msg, int family) { return -1; } +#endif } // namespace util diff --git a/src/util.h b/src/util.h index ca9b437d..17879694 100644 --- a/src/util.h +++ b/src/util.h @@ -863,7 +863,9 @@ std::mt19937 make_mt19937(); // daemon() using fork(). int daemonize(int nochdir, int noclose); +#ifdef ENABLE_HTTP3 int msghdr_get_local_addr(Address &dest, msghdr *msg, int family); +#endif } // namespace util