tool_cb_rea.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 1998 - 2022, 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 https://curl.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. * SPDX-License-Identifier: curl
  22. *
  23. ***************************************************************************/
  24. #include "tool_setup.h"
  25. #define ENABLE_CURLX_PRINTF
  26. /* use our own printf() functions */
  27. #include "curlx.h"
  28. #include "tool_cfgable.h"
  29. #include "tool_cb_rea.h"
  30. #include "tool_operate.h"
  31. #include "memdebug.h" /* keep this as LAST include */
  32. /*
  33. ** callback for CURLOPT_READFUNCTION
  34. */
  35. size_t tool_read_cb(char *buffer, size_t sz, size_t nmemb, void *userdata)
  36. {
  37. ssize_t rc;
  38. struct InStruct *in = userdata;
  39. rc = read(in->fd, buffer, sz*nmemb);
  40. if(rc < 0) {
  41. if(errno == EAGAIN) {
  42. errno = 0;
  43. in->config->readbusy = TRUE;
  44. return CURL_READFUNC_PAUSE;
  45. }
  46. /* since size_t is unsigned we can't return negative values fine */
  47. rc = 0;
  48. }
  49. in->config->readbusy = FALSE;
  50. return (size_t)rc;
  51. }
  52. /*
  53. ** callback for CURLOPT_XFERINFOFUNCTION used to unpause busy reads
  54. */
  55. int tool_readbusy_cb(void *clientp,
  56. curl_off_t dltotal, curl_off_t dlnow,
  57. curl_off_t ultotal, curl_off_t ulnow)
  58. {
  59. struct per_transfer *per = clientp;
  60. struct OperationConfig *config = per->config;
  61. (void)dltotal; /* unused */
  62. (void)dlnow; /* unused */
  63. (void)ultotal; /* unused */
  64. (void)ulnow; /* unused */
  65. if(config->readbusy) {
  66. config->readbusy = FALSE;
  67. curl_easy_pause(per->curl, CURLPAUSE_CONT);
  68. }
  69. return per->noprogress? 0 : CURL_PROGRESSFUNC_CONTINUE;
  70. }