]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
hyper: implement unpausing via client reader
authorStefan Eissing <stefan@eissing.org>
Thu, 7 Mar 2024 09:08:35 +0000 (10:08 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Thu, 7 Mar 2024 14:58:30 +0000 (15:58 +0100)
Just a tidy up to contain 'ifdef' pollution of common
code parts with implementation specifics.

- remove the ifdef hyper unpausing in easy.c
- add hyper client reader for CURL_CR_PROTOCOL phase
  that implements the unpause method for calling
  the hyper waker if it is set

Closes #13075

lib/c-hyper.c
lib/easy.c
lib/sendf.c
lib/sendf.h
scripts/singleuse.pl

index f11b126a57147525500cd723678fef676e04a5d3..41d758170b08a694163e372129eec561312d80a8 100644 (file)
@@ -67,6 +67,9 @@
 #include "curl_memory.h"
 #include "memdebug.h"
 
+
+static CURLcode cr_hyper_add(struct Curl_easy *data);
+
 typedef enum {
     USERDATA_NOT_SET = 0, /* for tasks with no userdata set; must be zero */
     USERDATA_RESP_BODY
@@ -718,14 +721,12 @@ out:
 }
 
 /*
- * bodysend() sets up headers in the outgoing request for an HTTP transfer that
- * sends a body
+ * finalize_request() sets up last headers and optional body settings
  */
-
-static CURLcode bodysend(struct Curl_easy *data,
-                         hyper_headers *headers,
-                         hyper_request *hyperreq,
-                         Curl_HttpReq httpreq)
+static CURLcode finalize_request(struct Curl_easy *data,
+                                 hyper_headers *headers,
+                                 hyper_request *hyperreq,
+                                 Curl_HttpReq httpreq)
 {
   CURLcode result = CURLE_OK;
   struct dynbuf req;
@@ -757,7 +758,8 @@ static CURLcode bodysend(struct Curl_easy *data,
       result = CURLE_OUT_OF_MEMORY;
     }
   }
-  return result;
+
+  return cr_hyper_add(data);
 }
 
 static CURLcode cookies(struct Curl_easy *data,
@@ -1127,7 +1129,7 @@ CURLcode Curl_http(struct Curl_easy *data, bool *done)
   if(result)
     goto error;
 
-  result = bodysend(data, headers, req, httpreq);
+  result = finalize_request(data, headers, req, httpreq);
   if(result)
     goto error;
 
@@ -1212,6 +1214,50 @@ void Curl_hyper_done(struct Curl_easy *data)
     hyper_waker_free(h->exp100_waker);
     h->exp100_waker = NULL;
   }
+  if(h->send_body_waker) {
+    hyper_waker_free(h->send_body_waker);
+    h->send_body_waker = NULL;
+  }
+}
+
+static CURLcode cr_hyper_unpause(struct Curl_easy *data,
+                                 struct Curl_creader *reader)
+{
+  (void)reader;
+  if(data->hyp.send_body_waker) {
+    hyper_waker_wake(data->hyp.send_body_waker);
+    data->hyp.send_body_waker = NULL;
+  }
+  return CURLE_OK;
+}
+
+/* Hyper client reader, handling unpausing */
+static const struct Curl_crtype cr_hyper_protocol = {
+  "cr-hyper",
+  Curl_creader_def_init,
+  Curl_creader_def_read,
+  Curl_creader_def_close,
+  Curl_creader_def_needs_rewind,
+  Curl_creader_def_total_length,
+  Curl_creader_def_resume_from,
+  Curl_creader_def_rewind,
+  cr_hyper_unpause,
+  sizeof(struct Curl_creader)
+};
+
+static CURLcode cr_hyper_add(struct Curl_easy *data)
+{
+  struct Curl_creader *reader = NULL;
+  CURLcode result;
+
+  result = Curl_creader_create(&reader, data, &cr_hyper_protocol,
+                               CURL_CR_PROTOCOL);
+  if(!result)
+    result = Curl_creader_add(data, reader);
+
+  if(result && reader)
+    Curl_creader_free(data, reader);
+  return result;
 }
 
 #endif /* !defined(CURL_DISABLE_HTTP) && defined(USE_HYPER) */
index dbc2e7f1791d3fb7e713240ee45e0b4108a83598..d41ca32d7f6b408a990132d5f25d9b1885eaeddf 100644 (file)
@@ -1126,16 +1126,6 @@ CURLcode curl_easy_pause(struct Curl_easy *data, int action)
       return result;
   }
 
-#ifdef USE_HYPER
-  if(!(newstate & KEEP_SEND_PAUSE)) {
-    /* need to wake the send body waker */
-    if(data->hyp.send_body_waker) {
-      hyper_waker_wake(data->hyp.send_body_waker);
-      data->hyp.send_body_waker = NULL;
-    }
-  }
-#endif
-
   /* if there's no error and we're not pausing both directions, we want
      to have this handle checked soon */
   if((newstate & (KEEP_RECV_PAUSE|KEEP_SEND_PAUSE)) !=
index ce9b2b07576ff24799d13902ff8629aa69e03e10..5bec063d94c7168703ad6e6eb9a68ef2eaa4595b 100644 (file)
@@ -523,6 +523,21 @@ void Curl_creader_def_close(struct Curl_easy *data,
   (void)reader;
 }
 
+CURLcode Curl_creader_def_read(struct Curl_easy *data,
+                               struct Curl_creader *reader,
+                               char *buf, size_t blen,
+                               size_t *nread, bool *eos)
+{
+  if(reader->next)
+    return reader->next->crt->do_read(data, reader->next, buf, blen,
+                                      nread, eos);
+  else {
+    *nread = 0;
+    *eos = FALSE;
+    return CURLE_READ_ERROR;
+  }
+}
+
 bool Curl_creader_def_needs_rewind(struct Curl_easy *data,
                                    struct Curl_creader *reader)
 {
index a62cfe8c6873de7d7752348ee4f4cb7ebc26dd9b..1bcbb3fd01e2e31963e98a7de0f2f5183373e460 100644 (file)
@@ -241,6 +241,10 @@ CURLcode Curl_creader_def_init(struct Curl_easy *data,
                                struct Curl_creader *reader);
 void Curl_creader_def_close(struct Curl_easy *data,
                             struct Curl_creader *reader);
+CURLcode Curl_creader_def_read(struct Curl_easy *data,
+                               struct Curl_creader *reader,
+                               char *buf, size_t blen,
+                               size_t *nread, bool *eos);
 bool Curl_creader_def_needs_rewind(struct Curl_easy *data,
                                    struct Curl_creader *reader);
 curl_off_t Curl_creader_def_total_length(struct Curl_easy *data,
index 3948d0a79a848d5904353430369c10be0c42efbb..064990226a3b67e0e13ec3694cb888e574ab5cbc 100755 (executable)
@@ -46,6 +46,7 @@ my %wl = (
     'Curl_xfer_write_resp' => 'internal api',
     'Curl_creader_def_init' => 'internal api',
     'Curl_creader_def_close' => 'internal api',
+    'Curl_creader_def_read' => 'internal api',
     'Curl_creader_def_total_length' => 'internal api',
 );