curl / Mailing Lists / curl-library / Single Mail

curl-library

Re: curl_multi_perform sometimes does not return while its threadus es1 00% cpu resources

From: Daniel Stenberg via curl-library <curl-library_at_cool.haxx.se>
Date: Tue, 25 Dec 2018 11:14:47 +0100 (CET)

On Tue, 25 Dec 2018, "h9791521_at_docomo.ne.jp" wrote:

> In reality, time_t is defined to unsigned type in 32 bit Windows

I'm still not convinced about this as it contradicts other sources, including
Microsoft's own documentation. Can you show us the exact typedefs used for
this and tell us which header file that makes that time_t type?

> timediff_t Curl_timediff(struct curltime newer, struct curltime older)

This function is unit-tested in test 1323, also on Windows [1]. Wouldn't that
test fail if your claim is correct?

The Curl_timediff*() functions possibly need something like the patch below to
work with unsigned time_t:

diff --git a/lib/timeval.c b/lib/timeval.c
index 2d7c782fa..c8eff5a5b 100644
--- a/lib/timeval.c
+++ b/lib/timeval.c
@@ -185,26 +185,26 @@ struct curltime Curl_now(void)
   *
   * @unittest: 1323
   */
  timediff_t Curl_timediff(struct curltime newer, struct curltime older)
  {
- timediff_t diff = newer.tv_sec-older.tv_sec;
+ timediff_t diff = (timediff_t)newer.tv_sec-older.tv_sec;
    if(diff >= (TIME_MAX/1000))
      return TIME_MAX;
    else if(diff <= (TIME_MIN/1000))
      return TIME_MIN;
- return diff * 1000 + (newer.tv_usec-older.tv_usec)/1000;
+ return diff * 1000 + ((timediff_t)newer.tv_usec-older.tv_usec)/1000;
  }

  /*
   * Returns: time difference in number of microseconds. For too large diffs it
   * returns max value.
   */
  timediff_t Curl_timediff_us(struct curltime newer, struct curltime older)
  {
- timediff_t diff = newer.tv_sec-older.tv_sec;
+ timediff_t diff = (timediff_t)newer.tv_sec-older.tv_sec;
    if(diff >= (TIME_MAX/1000000))
      return TIME_MAX;
    else if(diff <= (TIME_MIN/1000000))
      return TIME_MIN;
- return diff * 1000000 + newer.tv_usec-older.tv_usec;
+ return diff * 1000000 + (timediff_t)newer.tv_usec-older.tv_usec;
  }

[1] =
https://ci.appveyor.com/project/curlorg/curl/builds/21046798/job/i6s5hasky0h5yt11#L8646

-- 
  / daniel.haxx.se
-------------------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library
Etiquette:   https://curl.haxx.se/mail/etiquette.html
Received on 2018-12-25