speedcheck.c 2.4 KB

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