updated source code boilerplate/header
[platform/upstream/curl.git] / lib / speedcheck.c
1 /***************************************************************************
2  *                                  _   _ ____  _     
3  *  Project                     ___| | | |  _ \| |    
4  *                             / __| | | | |_) | |    
5  *                            | (__| |_| |  _ <| |___ 
6  *                             \___|\___/|_| \_\_____|
7  *
8  * Copyright (C) 1998 - 2002, 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$
22  ***************************************************************************/
23
24 #include "setup.h"
25
26 #include <stdio.h>
27 #include <string.h>
28 #if defined(__MINGW32__)
29 #include <winsock.h>
30 #endif
31
32 #include <curl/curl.h>
33 #include "urldata.h"
34 #include "sendf.h"
35 #include "speedcheck.h"
36
37 void Curl_speedinit(struct SessionHandle *data)
38 {
39   memset(&data->state.keeps_speed, 0, sizeof(struct timeval));
40 }
41
42 CURLcode Curl_speedcheck(struct SessionHandle *data,
43                          struct timeval now)
44 {
45   if((data->progress.current_speed >= 0) &&
46      data->set.low_speed_time &&
47      (Curl_tvlong(data->state.keeps_speed) != 0) &&
48      (data->progress.current_speed < data->set.low_speed_limit)) {
49
50     /* We are now below the "low speed limit". If we are below it
51        for "low speed time" seconds we consider that enough reason
52        to abort the download. */
53     
54     if( (Curl_tvdiff(now, data->state.keeps_speed)/1000) >
55         data->set.low_speed_time) {
56       /* we have been this slow for long enough, now die */
57       failf(data,
58             "Operation too slow. "
59             "Less than %d bytes/sec transfered the last %d seconds",
60             data->set.low_speed_limit,
61             data->set.low_speed_time);
62       return CURLE_OPERATION_TIMEOUTED;
63     }
64   }
65   else {
66     /* we keep up the required speed all right */
67     data->state.keeps_speed = now;
68   }
69   return CURLE_OK;
70 }
71
72 /*
73  * local variables:
74  * eval: (load-file "../curl-mode.el")
75  * end:
76  * vim600: fdm=marker
77  * vim: et sw=2 ts=2 sts=2 tw=78
78  */