aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/curl/src/tool_cb_rea.c
diff options
context:
space:
mode:
authorAlexSm <alex@ydb.tech>2024-01-18 11:28:56 +0100
committerGitHub <noreply@github.com>2024-01-18 11:28:56 +0100
commit9d0a3761b3201e0d9db879a7adf91876ebdb0564 (patch)
tree541d11ac878c18efd7ebca81e35112aa0fef995b /contrib/libs/curl/src/tool_cb_rea.c
parent404ef8886ecc9736bc58ade6da2fbd83b486a408 (diff)
downloadydb-9d0a3761b3201e0d9db879a7adf91876ebdb0564.tar.gz
Library import 8 (#1074)
* Library import 8 * Add contrib/libs/cxxsupp/libcxx/include/__verbose_abort
Diffstat (limited to 'contrib/libs/curl/src/tool_cb_rea.c')
-rw-r--r--contrib/libs/curl/src/tool_cb_rea.c63
1 files changed, 57 insertions, 6 deletions
diff --git a/contrib/libs/curl/src/tool_cb_rea.c b/contrib/libs/curl/src/tool_cb_rea.c
index 4aed55c3aa..8cb5bbe8ac 100644
--- a/contrib/libs/curl/src/tool_cb_rea.c
+++ b/contrib/libs/curl/src/tool_cb_rea.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2022, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@@ -23,6 +23,10 @@
***************************************************************************/
#include "tool_setup.h"
+#ifdef HAVE_SYS_SELECT_H
+#include <sys/select.h>
+#endif
+
#define ENABLE_CURLX_PRINTF
/* use our own printf() functions */
#include "curlx.h"
@@ -30,6 +34,8 @@
#include "tool_cfgable.h"
#include "tool_cb_rea.h"
#include "tool_operate.h"
+#include "tool_util.h"
+#include "tool_msgs.h"
#include "memdebug.h" /* keep this as LAST include */
@@ -39,20 +45,65 @@
size_t tool_read_cb(char *buffer, size_t sz, size_t nmemb, void *userdata)
{
- ssize_t rc;
- struct InStruct *in = userdata;
+ ssize_t rc = 0;
+ struct per_transfer *per = userdata;
+ struct OperationConfig *config = per->config;
+
+ if((per->uploadfilesize != -1) &&
+ (per->uploadedsofar == per->uploadfilesize)) {
+ /* done */
+ return 0;
+ }
+
+ if(config->timeout_ms) {
+ struct timeval now = tvnow();
+ long msdelta = tvdiff(now, per->start);
+
+ if(msdelta > config->timeout_ms)
+ /* timeout */
+ return 0;
+#ifndef _WIN32
+ /* this logic waits on read activity on a file descriptor that is not a
+ socket which makes it not work with select() on Windows */
+ else {
+ fd_set bits;
+ struct timeval timeout;
+ long wait = config->timeout_ms - msdelta;
- rc = read(in->fd, buffer, sz*nmemb);
+ /* wait this long at the most */
+ timeout.tv_sec = wait/1000;
+ timeout.tv_usec = (int)((wait%1000)*1000);
+
+ FD_ZERO(&bits);
+ FD_SET(per->infd, &bits);
+ if(!select(per->infd + 1, &bits, NULL, NULL, &timeout))
+ return 0; /* timeout */
+ }
+#endif
+ }
+
+ rc = read(per->infd, buffer, sz*nmemb);
if(rc < 0) {
if(errno == EAGAIN) {
errno = 0;
- in->config->readbusy = TRUE;
+ config->readbusy = TRUE;
return CURL_READFUNC_PAUSE;
}
/* since size_t is unsigned we can't return negative values fine */
rc = 0;
}
- in->config->readbusy = FALSE;
+ if((per->uploadfilesize != -1) &&
+ (per->uploadedsofar + rc > per->uploadfilesize)) {
+ /* do not allow uploading more than originally set out to do */
+ curl_off_t delta = per->uploadedsofar + rc - per->uploadfilesize;
+ warnf(per->config->global, "File size larger in the end than when "
+ "started. Dropping at least %" CURL_FORMAT_CURL_OFF_T " bytes",
+ delta);
+ rc = (ssize_t)(per->uploadfilesize - per->uploadedsofar);
+ }
+ config->readbusy = FALSE;
+
+ /* when select() returned zero here, it timed out */
return (size_t)rc;
}