]> granicus.if.org Git - curl/commitdiff
read_callback: move to SessionHandle from connectdata
authorDaniel Stenberg <daniel@haxx.se>
Wed, 20 May 2015 12:33:04 +0000 (14:33 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Wed, 20 May 2015 21:06:45 +0000 (23:06 +0200)
With many easy handles using the same connection for multiplexing, it is
important we store and keep the transfer-oriented stuff in the
SessionHandle so that callbacks and callback data work fine even when
many easy handles share the same physical connection.

lib/file.c
lib/ftp.c
lib/http.c
lib/multi.c
lib/ssh.c
lib/telnet.c
lib/transfer.c
lib/transfer.h
lib/url.c
lib/urldata.h

index 324d4e290288d1e078260f0f362d7da735316e36..175b10731e59ddacf8c20136265787fcb7cea207 100644 (file)
@@ -315,8 +315,6 @@ static CURLcode file_upload(struct connectdata *conn)
    * Since FILE: doesn't do the full init, we need to provide some extra
    * assignments here.
    */
-  conn->fread_func = data->set.fread_func;
-  conn->fread_in = data->set.in;
   conn->data->req.upload_fromhere = buf;
 
   if(!dir)
index e04f58361228787c0e095ac6e25c7ac1e38f5526..de628a2dc7a73f33b0a002222841faf7a4a2e24b 100644 (file)
--- a/lib/ftp.c
+++ b/lib/ftp.c
@@ -1670,8 +1670,8 @@ static CURLcode ftp_state_ul_setup(struct connectdata *conn,
             BUFSIZE : curlx_sotouz(data->state.resume_from - passed);
 
           size_t actuallyread =
-            conn->fread_func(data->state.buffer, 1, readthisamountnow,
-                             conn->fread_in);
+            data->set.fread_func(data->state.buffer, 1, readthisamountnow,
+                                 data->set.in);
 
           passed += actuallyread;
           if((actuallyread == 0) || (actuallyread > readthisamountnow)) {
index b5bfd2c9bd082ad6cd61b553a9bac7619b4fe883..2745160284c67ed6173c788bc85ae2a186482084 100644 (file)
@@ -1016,8 +1016,8 @@ static size_t readmoredata(char *buffer,
       /* move backup data into focus and continue on that */
       http->postdata = http->backup.postdata;
       http->postsize = http->backup.postsize;
-      conn->fread_func = http->backup.fread_func;
-      conn->fread_in = http->backup.fread_in;
+      conn->data->set.fread_func = http->backup.fread_func;
+      conn->data->set.in = http->backup.fread_in;
 
       http->sending++; /* move one step up */
 
@@ -1172,14 +1172,14 @@ CURLcode Curl_add_buffer_send(Curl_send_buffer *in,
         ptr = in->buffer + amount;
 
         /* backup the currently set pointers */
-        http->backup.fread_func = conn->fread_func;
-        http->backup.fread_in = conn->fread_in;
+        http->backup.fread_func = conn->data->set.fread_func;
+        http->backup.fread_in = conn->data->set.in;
         http->backup.postdata = http->postdata;
         http->backup.postsize = http->postsize;
 
         /* set the new pointers for the request-sending */
-        conn->fread_func = (curl_read_callback)readmoredata;
-        conn->fread_in = (void *)conn;
+        conn->data->set.fread_func = (curl_read_callback)readmoredata;
+        conn->data->set.in = (void *)conn;
         http->postdata = ptr;
         http->postsize = (curl_off_t)size;
 
@@ -1475,8 +1475,8 @@ CURLcode Curl_http_done(struct connectdata *conn,
 #endif
 
   /* set the proper values (possibly modified on POST) */
-  conn->fread_func = data->set.fread_func; /* restore */
-  conn->fread_in = data->set.in; /* restore */
+  data->set.fread_func = data->set.fread_func; /* restore */
+  data->set.in = data->set.in; /* restore */
   conn->seek_func = data->set.seek_func; /* restore */
   conn->seek_client = data->set.seek_client; /* restore */
 
@@ -2447,14 +2447,14 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
 
     /* Get the currently set callback function pointer and store that in the
        form struct since we might want the actual user-provided callback later
-       on. The conn->fread_func pointer itself will be changed for the
+       on. The data->set.fread_func pointer itself will be changed for the
        multipart case to the function that returns a multipart formatted
        stream. */
-    http->form.fread_func = conn->fread_func;
+    http->form.fread_func = data->set.fread_func;
 
     /* Set the read function to read from the generated form data */
-    conn->fread_func = (curl_read_callback)Curl_FormReader;
-    conn->fread_in = &http->form;
+    data->set.fread_func = (curl_read_callback)Curl_FormReader;
+    data->set.in = &http->form;
 
     http->sending = HTTPSEND_BODY;
 
@@ -2672,8 +2672,8 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
 
         http->sending = HTTPSEND_BODY;
 
-        conn->fread_func = (curl_read_callback)readmoredata;
-        conn->fread_in = (void *)conn;
+        data->set.fread_func = (curl_read_callback)readmoredata;
+        data->set.in = (void *)conn;
 
         /* set the upload size to the progress meter */
         Curl_pgrsSetUploadSize(data, http->postsize);
index a5790cb0290ec65570095a9fcb94739bc117bb43..fcef2e10f69954e91b87316938f64e39e6478615 100644 (file)
@@ -1513,7 +1513,7 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi,
                    __LINE__));
 
       /* read/write data if it is ready to do so */
-      result = Curl_readwrite(data->easy_conn, &done);
+      result = Curl_readwrite(data->easy_conn, data, &done);
 
       k = &data->req;
 
index bd16c7fbee1db4dc59588772df2d99f43bd185f0..f20645341293993feb4bb4c6cf31b0dbe2bb3193 100644 (file)
--- a/lib/ssh.c
+++ b/lib/ssh.c
@@ -1737,8 +1737,8 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
                 BUFSIZE : curlx_sotouz(data->state.resume_from - passed);
 
               size_t actuallyread =
-                conn->fread_func(data->state.buffer, 1, readthisamountnow,
-                                 conn->fread_in);
+                data->set.fread_func(data->state.buffer, 1, readthisamountnow,
+                                     data->set.in);
 
               passed += actuallyread;
               if((actuallyread == 0) || (actuallyread > readthisamountnow)) {
index 91863c065ddc58510a764a6f9314b8a7cdf07298..4ea049d21b130bfb6f1522ec40e668c1c0e6b38a 100644 (file)
@@ -1423,7 +1423,7 @@ static CURLcode telnet_do(struct connectdata *conn, bool *done)
       for(;;) {
         if(data->set.is_fread_set) {
           /* read from user-supplied method */
-          result = (int) conn->fread_func(buf, 1, BUFSIZE - 1, conn->fread_in);
+          result = (int) conn->fread_func(buf, 1, BUFSIZE - 1, data->set.in);
           if(result == CURL_READFUNC_ABORT) {
             keepon = FALSE;
             result = CURLE_READ_ERROR;
@@ -1562,13 +1562,13 @@ static CURLcode telnet_do(struct connectdata *conn, bool *done)
   pfd[0].fd = sockfd;
   pfd[0].events = POLLIN;
 
-  if(conn->fread_func != (curl_read_callback)fread) {
+  if(data->set.fread_func != (curl_read_callback)fread) {
     poll_cnt = 1;
     interval_ms = 100; /* poll user-supplied read function */
   }
   else {
     /* really using fread, so infile is a FILE* */
-    pfd[1].fd = fileno((FILE *)conn->fread_in);
+    pfd[1].fd = fileno((FILE *)data->set.in);
     pfd[1].events = POLLIN;
     poll_cnt = 2;
     interval_ms = 1 * 1000;
@@ -1627,7 +1627,7 @@ static CURLcode telnet_do(struct connectdata *conn, bool *done)
       }
       else {
         /* read from user-supplied method */
-        nread = (int)conn->fread_func(buf, 1, BUFSIZE - 1, conn->fread_in);
+        nread = (int)data->set.fread_func(buf, 1, BUFSIZE - 1, data->set.in);
         if(nread == CURL_READFUNC_ABORT) {
           keepon = FALSE;
           break;
index 7671730f57e3ab6149e062941998ceab96ebd77e..42d38b51aab1db51a91f348729d182dce62040ad 100644 (file)
@@ -115,8 +115,8 @@ CURLcode Curl_fillreadbuffer(struct connectdata *conn, int bytes, int *nreadp)
 
   /* this function returns a size_t, so we typecast to int to prevent warnings
      with picky compilers */
-  nread = (int)conn->fread_func(data->req.upload_fromhere, 1,
-                                buffersize, conn->fread_in);
+  nread = (int)data->set.fread_func(data->req.upload_fromhere, 1,
+                                    buffersize, data->set.in);
 
   if(nread == CURL_READFUNC_ABORT) {
     failf(data, "operation aborted by callback");
@@ -1013,9 +1013,9 @@ static CURLcode readwrite_upload(struct SessionHandle *data,
  * be read and written to/from the connection.
  */
 CURLcode Curl_readwrite(struct connectdata *conn,
+                        struct SessionHandle *data,
                         bool *done)
 {
-  struct SessionHandle *data = conn->data;
   struct SingleRequest *k = &data->req;
   CURLcode result;
   int didwhat=0;
index ad4a3acd6749da11d2ac51e0d95c3fcdece6416a..316aeaebc95af19531869632c74eb7385c8abb10 100644 (file)
@@ -7,7 +7,7 @@
  *                            | (__| |_| |  _ <| |___
  *                             \___|\___/|_| \_\_____|
  *
- * Copyright (C) 1998 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2015, 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
@@ -40,7 +40,8 @@ CURLcode Curl_follow(struct SessionHandle *data, char *newurl,
                      followtype type);
 
 
-CURLcode Curl_readwrite(struct connectdata *conn, bool *done);
+CURLcode Curl_readwrite(struct connectdata *conn,
+                        struct SessionHandle *data, bool *done);
 int Curl_single_getsock(const struct connectdata *conn,
                         curl_socket_t *socks,
                         int numsocks);
index bc342b0f9cafab7e777ce62ac2ba1b85f0b3e563..1b57ef1027d34b00e00237a97ce9c5a816f3f8ea 100644 (file)
--- a/lib/url.c
+++ b/lib/url.c
@@ -5844,8 +5844,6 @@ static CURLcode create_conn(struct SessionHandle *data,
    * Inherit the proper values from the urldata struct AFTER we have arranged
    * the persistent connection stuff
    */
-  conn->fread_func = data->set.fread_func;
-  conn->fread_in = data->set.in;
   conn->seek_func = data->set.seek_func;
   conn->seek_client = data->set.seek_client;
 
index 2484f47b04f2ca0b56ae67974ac9c924358fb367..64b855e32d974f09506ad83aeee7a9021ff2d616 100644 (file)
@@ -988,10 +988,6 @@ struct connectdata {
 
   /*************** Request - specific items ************/
 
-  /* previously this was in the urldata struct */
-  curl_read_callback fread_func; /* function that reads the input */
-  void *fread_in;           /* pointer to pass to the fread() above */
-
 #if defined(USE_NTLM)
   struct ntlmdata ntlm;     /* NTLM differs from other authentication schemes
                                because it authenticates connections, not
@@ -1426,8 +1422,8 @@ struct UserDefined {
   long proxyport; /* If non-zero, use this port number by default. If the
                      proxy string features a ":[port]" that one will override
                      this. */
-  void *out;         /* the fetched file goes here */
-  void *in;          /* the uploaded file is read from here */
+  void *out;         /* CURLOPT_WRITEDATA */
+  void *in;          /* CURLOPT_READDATA */
   void *writeheader; /* write the header to this if non-NULL */
   void *rtp_out;     /* write RTP to this if non-NULL */
   long use_port;     /* which port to use (when not using default) */