00001 /*************************************************************************** 00002 * _ _ ____ _ 00003 * Project ___| | | | _ \| | 00004 * / __| | | | |_) | | 00005 * | (__| |_| | _ <| |___ 00006 * \___|\___/|_| \_\_____| 00007 * 00008 * Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al. 00009 * 00010 * This software is licensed as described in the file COPYING, which 00011 * you should have received as part of this distribution. The terms 00012 * are also available at http://curl.haxx.se/docs/copyright.html. 00013 * 00014 * You may opt to use, copy, modify, merge, publish, distribute and/or sell 00015 * copies of the Software, and permit persons to whom the Software is 00016 * furnished to do so, under the terms of the COPYING file. 00017 * 00018 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 00019 * KIND, either express or implied. 00020 * 00021 * $Id: speedcheck.c,v 1.22 2006-10-17 09:05:44 bagder Exp $ 00022 ***************************************************************************/ 00023 00024 #include "setup.h" 00025 00026 #include <stdio.h> 00027 #include <string.h> 00028 00029 #include <curl/curl.h> 00030 #include "urldata.h" 00031 #include "sendf.h" 00032 #include "multiif.h" 00033 #include "speedcheck.h" 00034 00035 void Curl_speedinit(struct SessionHandle *data) 00036 { 00037 memset(&data->state.keeps_speed, 0, sizeof(struct timeval)); 00038 } 00039 00040 CURLcode Curl_speedcheck(struct SessionHandle *data, 00041 struct timeval now) 00042 { 00043 if((data->progress.current_speed >= 0) && 00044 data->set.low_speed_time && 00045 (Curl_tvlong(data->state.keeps_speed) != 0) && 00046 (data->progress.current_speed < data->set.low_speed_limit)) { 00047 long howlong = Curl_tvdiff(now, data->state.keeps_speed); 00048 00049 /* We are now below the "low speed limit". If we are below it 00050 for "low speed time" seconds we consider that enough reason 00051 to abort the download. */ 00052 00053 if( (howlong/1000) > data->set.low_speed_time) { 00054 /* we have been this slow for long enough, now die */ 00055 failf(data, 00056 "Operation too slow. " 00057 "Less than %d bytes/sec transfered the last %d seconds", 00058 data->set.low_speed_limit, 00059 data->set.low_speed_time); 00060 return CURLE_OPERATION_TIMEOUTED; 00061 } 00062 Curl_expire(data, howlong); 00063 } 00064 else { 00065 /* we keep up the required speed all right */ 00066 data->state.keeps_speed = now; 00067 00068 if(data->set.low_speed_limit) 00069 /* if there is a low speed limit enabled, we set the expire timer to 00070 make this connection's speed get checked again no later than when 00071 this time is up */ 00072 Curl_expire(data, data->set.low_speed_time*1000); 00073 } 00074 return CURLE_OK; 00075 }
1.5.6