doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
speedcheck.c
Go to the documentation of this file.
1 /***************************************************************************
2  * _ _ ____ _
3  * Project ___| | | | _ \| |
4  * / __| | | | |_) | |
5  * | (__| |_| | _ <| |___
6  * \___|\___/|_| \_\_____|
7  *
8  * Copyright (C) 1998 - 2004, Daniel Stenberg, <daniel@haxx.se>, et al.
9  *
10  * This software is licensed as described in the file COPYING, which
11  * you should have received as part of this distribution. The terms
12  * are also available at http://curl.haxx.se/docs/copyright.html.
13  *
14  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15  * copies of the Software, and permit persons to whom the Software is
16  * furnished to do so, under the terms of the COPYING file.
17  *
18  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19  * KIND, either express or implied.
20  *
21  * $Id: speedcheck.c,v 1.19 2004/01/07 09:19:35 bagder Exp $
22  ***************************************************************************/
23 
24 #include "setup.h"
25 
26 #include <stdio.h>
27 #include <string.h>
28 
29 #include <curl/curl.h>
30 #include "urldata.h"
31 #include "sendf.h"
32 #include "speedcheck.h"
33 
35 {
36  memset(&data->state.keeps_speed, 0, sizeof(struct timeval));
37 }
38 
40  struct timeval now)
41 {
42  if((data->progress.current_speed >= 0) &&
43  data->set.low_speed_time &&
44  (Curl_tvlong(data->state.keeps_speed) != 0) &&
45  (data->progress.current_speed < data->set.low_speed_limit)) {
46 
47  /* We are now below the "low speed limit". If we are below it
48  for "low speed time" seconds we consider that enough reason
49  to abort the download. */
50 
51  if( (Curl_tvdiff(now, data->state.keeps_speed)/1000) >
52  data->set.low_speed_time) {
53  /* we have been this slow for long enough, now die */
54  failf(data,
55  "Operation too slow. "
56  "Less than %d bytes/sec transfered the last %d seconds",
57  data->set.low_speed_limit,
58  data->set.low_speed_time);
60  }
61  }
62  else {
63  /* we keep up the required speed all right */
64  data->state.keeps_speed = now;
65  }
66  return CURLE_OK;
67 }
void Curl_speedinit(struct SessionHandle *data)
Definition: speedcheck.c:34
#define failf
Definition: sendf.h:32
CURLcode
Definition: curl.h:209
struct UrlState state
Definition: urldata.h:903
curl_off_t current_speed
Definition: urldata.h:612
struct Progress progress
Definition: urldata.h:902
long Curl_tvlong(struct timeval t1)
Definition: timeval.c:98
long low_speed_time
Definition: urldata.h:799
GLsizei GLsizei GLenum GLenum const GLvoid * data
Definition: glext.h:2853
long Curl_tvdiff(struct timeval newer, struct timeval older)
Definition: timeval.c:92
CURLcode Curl_speedcheck(struct SessionHandle *data, struct timeval now)
Definition: speedcheck.c:39
Definition: curl.h:210
struct UserDefined set
Definition: urldata.h:898
long low_speed_limit
Definition: urldata.h:798
struct timeval keeps_speed
Definition: urldata.h:669