summaryrefslogtreecommitdiffstats
path: root/Utilities/cmcurl/lib/cf-socket.c
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2023-10-12 19:29:04 (GMT)
committerBrad King <brad.king@kitware.com>2023-10-12 19:29:20 (GMT)
commitdf4efb72e4225dc3fd4f32313bc8b19122a98f66 (patch)
treedbbb93a136f4f44184cbab061b03489379ef717c /Utilities/cmcurl/lib/cf-socket.c
parent8f6a6b02e59c112dbe971adca4f25938903828ea (diff)
parente6a6c1abc1e6b6e3ca9fa77947279509b55e2b01 (diff)
downloadCMake-df4efb72e4225dc3fd4f32313bc8b19122a98f66.zip
CMake-df4efb72e4225dc3fd4f32313bc8b19122a98f66.tar.gz
CMake-df4efb72e4225dc3fd4f32313bc8b19122a98f66.tar.bz2
Merge branch 'upstream-curl' into update-curl
* upstream-curl: curl 2023-10-11 (d755a5f7) Issue: #25329
Diffstat (limited to 'Utilities/cmcurl/lib/cf-socket.c')
-rw-r--r--Utilities/cmcurl/lib/cf-socket.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/Utilities/cmcurl/lib/cf-socket.c b/Utilities/cmcurl/lib/cf-socket.c
index effe6e6..ce3f9e9 100644
--- a/Utilities/cmcurl/lib/cf-socket.c
+++ b/Utilities/cmcurl/lib/cf-socket.c
@@ -781,6 +781,8 @@ struct cf_socket_ctx {
#ifdef DEBUGBUILD
int wblock_percent; /* percent of writes doing EAGAIN */
int wpartial_percent; /* percent of bytes written in send */
+ int rblock_percent; /* percent of reads doing EAGAIN */
+ size_t recv_max; /* max enforced read size */
#endif
BIT(got_first_byte); /* if first byte was received */
BIT(accepted); /* socket was accepted, not connected */
@@ -811,6 +813,18 @@ static void cf_socket_ctx_init(struct cf_socket_ctx *ctx,
if(l >= 0 && l <= 100)
ctx->wpartial_percent = (int)l;
}
+ p = getenv("CURL_DBG_SOCK_RBLOCK");
+ if(p) {
+ long l = strtol(p, NULL, 10);
+ if(l >= 0 && l <= 100)
+ ctx->rblock_percent = (int)l;
+ }
+ p = getenv("CURL_DBG_SOCK_RMAX");
+ if(p) {
+ long l = strtol(p, NULL, 10);
+ if(l >= 0)
+ ctx->recv_max = (size_t)l;
+ }
}
#endif
}
@@ -1358,6 +1372,27 @@ static ssize_t cf_socket_recv(struct Curl_cfilter *cf, struct Curl_easy *data,
fdsave = cf->conn->sock[cf->sockindex];
cf->conn->sock[cf->sockindex] = ctx->sock;
+#ifdef DEBUGBUILD
+ /* simulate network blocking/partial reads */
+ if(cf->cft != &Curl_cft_udp && ctx->rblock_percent > 0) {
+ unsigned char c;
+ Curl_rand(data, &c, 1);
+ if(c >= ((100-ctx->rblock_percent)*256/100)) {
+ CURL_TRC_CF(data, cf, "recv(len=%zu) SIMULATE EWOULDBLOCK", len);
+ *err = CURLE_AGAIN;
+ nread = -1;
+ cf->conn->sock[cf->sockindex] = fdsave;
+ return nread;
+ }
+ }
+ if(cf->cft != &Curl_cft_udp && ctx->recv_max && ctx->recv_max < len) {
+ size_t orig_len = len;
+ len = ctx->recv_max;
+ CURL_TRC_CF(data, cf, "recv(len=%zu) SIMULATE max read of %zu bytes",
+ orig_len, len);
+ }
+#endif
+
if(ctx->buffer_recv && !Curl_bufq_is_empty(&ctx->recvbuf)) {
CURL_TRC_CF(data, cf, "recv from buffer");
nread = Curl_bufq_read(&ctx->recvbuf, (unsigned char *)buf, len, err);