speedcheck.c
Go to the documentation of this file.
00001 /***************************************************************************
00002  *                                  _   _ ____  _
00003  *  Project                     ___| | | |  _ \| |
00004  *                             / __| | | | |_) | |
00005  *                            | (__| |_| |  _ <| |___
00006  *                             \___|\___/|_| \_\_____|
00007  *
00008  * Copyright (C) 1998 - 2016, 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 https://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  ***************************************************************************/
00022 
00023 #include "curl_setup.h"
00024 
00025 #include <curl/curl.h>
00026 #include "urldata.h"
00027 #include "sendf.h"
00028 #include "multiif.h"
00029 #include "speedcheck.h"
00030 
00031 void Curl_speedinit(struct Curl_easy *data)
00032 {
00033   memset(&data->state.keeps_speed, 0, sizeof(struct timeval));
00034 }
00035 
00036 CURLcode Curl_speedcheck(struct Curl_easy *data,
00037                          struct timeval now)
00038 {
00039   if((data->progress.current_speed >= 0) &&
00040      data->set.low_speed_time &&
00041      (Curl_tvlong(data->state.keeps_speed) != 0) &&
00042      (data->progress.current_speed < data->set.low_speed_limit)) {
00043     time_t howlong = Curl_tvdiff(now, data->state.keeps_speed);
00044     time_t nextcheck = (data->set.low_speed_time * 1000) - howlong;
00045 
00046     /* We are now below the "low speed limit". If we are below it
00047        for "low speed time" seconds we consider that enough reason
00048        to abort the download. */
00049     if(nextcheck <= 0) {
00050       /* we have been this slow for long enough, now die */
00051       failf(data,
00052             "Operation too slow. "
00053             "Less than %ld bytes/sec transferred the last %ld seconds",
00054             data->set.low_speed_limit,
00055             data->set.low_speed_time);
00056       return CURLE_OPERATION_TIMEDOUT;
00057     }
00058     else {
00059       /* wait complete low_speed_time */
00060       Curl_expire_latest(data, nextcheck);
00061     }
00062   }
00063   else {
00064     /* we keep up the required speed all right */
00065     data->state.keeps_speed = now;
00066 
00067     if(data->set.low_speed_limit)
00068       /* if there is a low speed limit enabled, we set the expire timer to
00069          make this connection's speed get checked again no later than when
00070          this time is up */
00071       Curl_expire_latest(data, data->set.low_speed_time*1000);
00072   }
00073   return CURLE_OK;
00074 }


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Thu Jun 6 2019 20:43:06