blob: 4aed55c3aa3ea4a3b731e6195ef873607180ff6c [file] [log] [blame]
xf.libfc6e712025-02-07 01:54:34 -08001/***************************************************************************
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
26#define ENABLE_CURLX_PRINTF
27/* use our own printf() functions */
28#include "curlx.h"
29
30#include "tool_cfgable.h"
31#include "tool_cb_rea.h"
32#include "tool_operate.h"
33
34#include "memdebug.h" /* keep this as LAST include */
35
36/*
37** callback for CURLOPT_READFUNCTION
38*/
39
40size_t tool_read_cb(char *buffer, size_t sz, size_t nmemb, void *userdata)
41{
42 ssize_t rc;
43 struct InStruct *in = userdata;
44
45 rc = read(in->fd, buffer, sz*nmemb);
46 if(rc < 0) {
47 if(errno == EAGAIN) {
48 errno = 0;
49 in->config->readbusy = TRUE;
50 return CURL_READFUNC_PAUSE;
51 }
52 /* since size_t is unsigned we can't return negative values fine */
53 rc = 0;
54 }
55 in->config->readbusy = FALSE;
56 return (size_t)rc;
57}
58
59/*
60** callback for CURLOPT_XFERINFOFUNCTION used to unpause busy reads
61*/
62
63int tool_readbusy_cb(void *clientp,
64 curl_off_t dltotal, curl_off_t dlnow,
65 curl_off_t ultotal, curl_off_t ulnow)
66{
67 struct per_transfer *per = clientp;
68 struct OperationConfig *config = per->config;
69
70 (void)dltotal; /* unused */
71 (void)dlnow; /* unused */
72 (void)ultotal; /* unused */
73 (void)ulnow; /* unused */
74
75 if(config->readbusy) {
76 config->readbusy = FALSE;
77 curl_easy_pause(per->curl, CURLPAUSE_CONT);
78 }
79
80 return per->noprogress? 0 : CURL_PROGRESSFUNC_CONTINUE;
81}