diff options
author | dartraiden <wowemuh@gmail.com> | 2024-07-25 00:50:30 +0300 |
---|---|---|
committer | dartraiden <wowemuh@gmail.com> | 2024-07-25 02:38:23 +0300 |
commit | 67a42fc97c64c83e02f6f0d68e5a4a22c71138d3 (patch) | |
tree | 21eb2d53a9cd7e645a58662dee11588f56057eee /libs/libcurl/src/cfilters.c | |
parent | 0a365886f2d06750a707037d894e1492988eb53c (diff) |
libcurl: update to 8.9.0
Diffstat (limited to 'libs/libcurl/src/cfilters.c')
-rw-r--r-- | libs/libcurl/src/cfilters.c | 111 |
1 files changed, 108 insertions, 3 deletions
diff --git a/libs/libcurl/src/cfilters.c b/libs/libcurl/src/cfilters.c index 4bb958cf3a..d10c6c1ed0 100644 --- a/libs/libcurl/src/cfilters.c +++ b/libs/libcurl/src/cfilters.c @@ -45,7 +45,7 @@ #define ARRAYSIZE(A) (sizeof(A)/sizeof((A)[0]))
#endif
-#ifdef DEBUGBUILD
+#ifdef UNITTESTS
/* used by unit2600.c */
void Curl_cf_def_close(struct Curl_cfilter *cf, struct Curl_easy *data)
{
@@ -55,6 +55,15 @@ void Curl_cf_def_close(struct Curl_cfilter *cf, struct Curl_easy *data) }
#endif
+CURLcode Curl_cf_def_shutdown(struct Curl_cfilter *cf,
+ struct Curl_easy *data, bool *done)
+{
+ (void)cf;
+ (void)data;
+ *done = TRUE;
+ return CURLE_OK;
+}
+
static void conn_report_connect_stats(struct Curl_easy *data,
struct connectdata *conn);
@@ -166,6 +175,61 @@ void Curl_conn_close(struct Curl_easy *data, int index) if(cf) {
cf->cft->do_close(cf, data);
}
+ Curl_shutdown_clear(data, index);
+}
+
+CURLcode Curl_conn_shutdown(struct Curl_easy *data, int sockindex, bool *done)
+{
+ struct Curl_cfilter *cf;
+ CURLcode result = CURLE_OK;
+ timediff_t timeout_ms;
+ struct curltime now;
+
+ DEBUGASSERT(data->conn);
+ /* Get the first connected filter that is not shut down already. */
+ cf = data->conn->cfilter[sockindex];
+ while(cf && (!cf->connected || cf->shutdown))
+ cf = cf->next;
+
+ if(!cf) {
+ *done = TRUE;
+ return CURLE_OK;
+ }
+
+ *done = FALSE;
+ now = Curl_now();
+ if(!Curl_shutdown_started(data, sockindex)) {
+ DEBUGF(infof(data, "shutdown start on%s connection",
+ sockindex? " secondary" : ""));
+ Curl_shutdown_start(data, sockindex, &now);
+ }
+ else {
+ timeout_ms = Curl_shutdown_timeleft(data->conn, sockindex, &now);
+ if(timeout_ms < 0) {
+ failf(data, "SSL shutdown timeout");
+ return CURLE_OPERATION_TIMEDOUT;
+ }
+ }
+
+ while(cf) {
+ if(!cf->shutdown) {
+ bool cfdone = FALSE;
+ result = cf->cft->do_shutdown(cf, data, &cfdone);
+ if(result) {
+ CURL_TRC_CF(data, cf, "shut down failed with %d", result);
+ return result;
+ }
+ else if(!cfdone) {
+ CURL_TRC_CF(data, cf, "shut down not done yet");
+ return CURLE_OK;
+ }
+ CURL_TRC_CF(data, cf, "shut down successfully");
+ cf->shutdown = TRUE;
+ }
+ cf = cf->next;
+ }
+ *done = (!result);
+ return result;
}
ssize_t Curl_cf_recv(struct Curl_easy *data, int num, char *buf,
@@ -345,8 +409,10 @@ CURLcode Curl_conn_connect(struct Curl_easy *data, cf = data->conn->cfilter[sockindex];
DEBUGASSERT(cf);
- if(!cf)
+ if(!cf) {
+ *done = FALSE;
return CURLE_FAILED_INIT;
+ }
*done = cf->connected;
if(!*done) {
@@ -442,6 +508,9 @@ void Curl_conn_cf_adjust_pollset(struct Curl_cfilter *cf, /* Get the lowest not-connected filter, if there are any */
while(cf && !cf->connected && cf->next && !cf->next->connected)
cf = cf->next;
+ /* Skip all filters that have already shut down */
+ while(cf && cf->shutdown)
+ cf = cf->next;
/* From there on, give all filters a chance to adjust the pollset.
* Lower filters are called later, so they may override */
while(cf) {
@@ -462,6 +531,42 @@ void Curl_conn_adjust_pollset(struct Curl_easy *data, }
}
+int Curl_conn_cf_poll(struct Curl_cfilter *cf,
+ struct Curl_easy *data,
+ timediff_t timeout_ms)
+{
+ struct easy_pollset ps;
+ struct pollfd pfds[MAX_SOCKSPEREASYHANDLE];
+ unsigned int i, npfds = 0;
+
+ DEBUGASSERT(cf);
+ DEBUGASSERT(data);
+ DEBUGASSERT(data->conn);
+ memset(&ps, 0, sizeof(ps));
+ memset(pfds, 0, sizeof(pfds));
+
+ Curl_conn_cf_adjust_pollset(cf, data, &ps);
+ DEBUGASSERT(ps.num <= MAX_SOCKSPEREASYHANDLE);
+ for(i = 0; i < ps.num; ++i) {
+ short events = 0;
+ if(ps.actions[i] & CURL_POLL_IN) {
+ events |= POLLIN;
+ }
+ if(ps.actions[i] & CURL_POLL_OUT) {
+ events |= POLLOUT;
+ }
+ if(events) {
+ pfds[npfds].fd = ps.sockets[i];
+ pfds[npfds].events = events;
+ ++npfds;
+ }
+ }
+
+ if(!npfds)
+ DEBUGF(infof(data, "no sockets to poll!"));
+ return Curl_poll(pfds, npfds, timeout_ms);
+}
+
void Curl_conn_get_host(struct Curl_easy *data, int sockindex,
const char **phost, const char **pdisplay_host,
int *pport)
@@ -718,7 +823,7 @@ CURLcode Curl_conn_send(struct Curl_easy *data, int sockindex, DEBUGASSERT(data);
DEBUGASSERT(data->conn);
conn = data->conn;
-#ifdef CURLDEBUG
+#ifdef DEBUGBUILD
{
/* Allow debug builds to override this logic to force short sends
*/
|