Initial commit.
[CMakeLuaTailorHgBridge.git] / CMakeLua / Utilities / cmcurl / speedcheck.c
blobe164ca777e15f1c518647c8b99aaf03582929dc8
1 /***************************************************************************
2 * _ _ ____ _
3 * Project ___| | | | _ \| |
4 * / __| | | | |_) | |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
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.
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.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 * $Id: speedcheck.c,v 1.2 2007/03/15 19:22:13 andy Exp $
22 ***************************************************************************/
24 #include "setup.h"
26 #include <stdio.h>
27 #include <string.h>
29 #include <curl/curl.h>
30 #include "urldata.h"
31 #include "sendf.h"
32 #include "multiif.h"
33 #include "speedcheck.h"
35 void Curl_speedinit(struct SessionHandle *data)
37 memset(&data->state.keeps_speed, 0, sizeof(struct timeval));
40 CURLcode Curl_speedcheck(struct SessionHandle *data,
41 struct timeval now)
43 if((data->progress.current_speed >= 0) &&
44 data->set.low_speed_time &&
45 (Curl_tvlong(data->state.keeps_speed) != 0) &&
46 (data->progress.current_speed < data->set.low_speed_limit)) {
47 long howlong = Curl_tvdiff(now, data->state.keeps_speed);
49 /* We are now below the "low speed limit". If we are below it
50 for "low speed time" seconds we consider that enough reason
51 to abort the download. */
53 if( (howlong/1000) > data->set.low_speed_time) {
54 /* we have been this slow for long enough, now die */
55 failf(data,
56 "Operation too slow. "
57 "Less than %d bytes/sec transfered the last %d seconds",
58 data->set.low_speed_limit,
59 data->set.low_speed_time);
60 return CURLE_OPERATION_TIMEOUTED;
62 Curl_expire(data, howlong);
64 else {
65 /* we keep up the required speed all right */
66 data->state.keeps_speed = now;
68 if(data->set.low_speed_limit)
69 /* if there is a low speed limit enabled, we set the expire timer to
70 make this connection's speed get checked again no later than when
71 this time is up */
72 Curl_expire(data, data->set.low_speed_time*1000);
74 return CURLE_OK;