You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by gs...@apache.org on 2012/05/08 03:10:37 UTC

svn commit: r1335313 - in /subversion/trunk/subversion/libsvn_ra_serf: ra_serf.h util.c

Author: gstein
Date: Tue May  8 01:10:37 2012
New Revision: 1335313

URL: http://svn.apache.org/viewvc?rev=1335313&view=rev
Log:
Switch to using a flag for discarding the rest of the body, rather
than altering the values in the handler_t.

* subversion/libsvn_ra_serf/ra_serf.h:
  (svn_ra_serf__handler_t): add DISCARD_BODY flag

* subversion/libsvn_ra_serf/util.c:
  (drain_bucket): new function factored out of
    svn_ra_serf__response_discard_handler to drain a bucket of its
    contents.
  (svn_ra_serf__handle_discard_body): switch to drain_bucket()
  (svn_ra_serf__response_discard_handler): use drain_bucket()
  (svn_ra_serf__handle_multistatus_only): do not alter the handler;
    just set the new DISCARD_BODY flag
  (handle_response): don't invoke another handler (one invocation is
    not enough to drain a response body). set the new DISCARD_BODY
    flag in case more content arrives (it shouldn't due to EOF). add
    code to the body processing to drain the content if DISCARD_BODY
    has been set.
  (svn_ra_serf__request_create): reset the DISCARD_BODY flag

Modified:
    subversion/trunk/subversion/libsvn_ra_serf/ra_serf.h
    subversion/trunk/subversion/libsvn_ra_serf/util.c

Modified: subversion/trunk/subversion/libsvn_ra_serf/ra_serf.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_ra_serf/ra_serf.h?rev=1335313&r1=1335312&r2=1335313&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_ra_serf/ra_serf.h (original)
+++ subversion/trunk/subversion/libsvn_ra_serf/ra_serf.h Tue May  8 01:10:37 2012
@@ -456,6 +456,11 @@ typedef struct svn_ra_serf__handler_t {
   /* Internal flag to indicate we've parsed the headers.  */
   svn_boolean_t reading_body;
 
+  /* When this flag will be set, the core handler will discard any unread
+     portion of the response body. The registered response handler will
+     no longer be called.  */
+  svn_boolean_t discard_body;
+
   /* Pool for allocating SLINE.REASON and LOCATION. If this pool is NULL,
      then the requestor does not care about SLINE and LOCATION.  */
   apr_pool_t *handler_pool;

Modified: subversion/trunk/subversion/libsvn_ra_serf/util.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_ra_serf/util.c?rev=1335313&r1=1335312&r2=1335313&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_ra_serf/util.c (original)
+++ subversion/trunk/subversion/libsvn_ra_serf/util.c Tue May  8 01:10:37 2012
@@ -846,6 +846,24 @@ cdata_error(svn_ra_serf__xml_parser_t *p
   return SVN_NO_ERROR;
 }
 
+
+static apr_status_t
+drain_bucket(serf_bucket_t *bucket)
+{
+  /* Read whatever is in the bucket, and just drop it.  */
+  while (1)
+    {
+      apr_status_t status;
+      const char *data;
+      apr_size_t len;
+
+      status = serf_bucket_read(bucket, SERF_READ_ALL_AVAIL, &data, &len);
+      if (status)
+        return status;
+    }
+}
+
+
 /* Implements svn_ra_serf__response_handler_t */
 svn_error_t *
 svn_ra_serf__handle_discard_body(serf_request_t *request,
@@ -906,9 +924,7 @@ svn_ra_serf__handle_discard_body(serf_re
 
     }
 
-  status = svn_ra_serf__response_discard_handler(request, response,
-                                                 NULL, pool);
-
+  status = drain_bucket(response);
   if (status)
     return svn_error_wrap_apr(status, NULL);
 
@@ -921,22 +937,7 @@ svn_ra_serf__response_discard_handler(se
                                       void *baton,
                                       apr_pool_t *pool)
 {
-  /* Just loop through and discard the body. */
-  while (1)
-    {
-      apr_status_t status;
-      const char *data;
-      apr_size_t len;
-
-      status = serf_bucket_read(response, SERF_READ_ALL_AVAIL, &data, &len);
-
-      if (status)
-        {
-          return status;
-        }
-
-      /* feed me */
-    }
+  return drain_bucket(response);
 }
 
 const char *
@@ -1144,8 +1145,7 @@ svn_ra_serf__handle_multistatus_only(ser
 
           /* The body was not text/xml, so we don't know what to do with it.
              Toss anything that arrives.  */
-          handler->response_handler = svn_ra_serf__handle_discard_body;
-          handler->response_baton = NULL;
+          handler->discard_body = TRUE;
         }
     }
 
@@ -1719,10 +1719,9 @@ handle_response(serf_request_t *request,
                                     " (http status=%d)"),
                                   handler->sline.code);
 
-          /* This discard may be no-op, but let's preserve the algorithm
-             used elsewhere in this function for clarity's sake. */
-          svn_ra_serf__response_discard_handler(request, response, NULL,
-                                                scratch_pool);
+          /* In case anything else arrives... discard it.  */
+          handler->discard_body = TRUE;
+
           return err;
         }
     }
@@ -1779,6 +1778,13 @@ handle_response(serf_request_t *request,
 
  process_body:
 
+  /* We've been instructed to ignore the body. Drain whatever is present.  */
+  if (handler->discard_body)
+    {
+      *serf_status = drain_bucket(response);
+      return SVN_NO_ERROR;
+    }
+
   /* If we are supposed to parse the body as a server_error, then do
      that now.  */
   if (handler->server_error != NULL)
@@ -1814,8 +1820,7 @@ handle_response(serf_request_t *request,
           handler->server_error = NULL;
 
           /* If anything arrives after this, then just discard it.  */
-          handler->response_handler = svn_ra_serf__handle_discard_body;
-          handler->response_baton = NULL;
+          handler->discard_body = TRUE;
         }
 
       *serf_status = APR_EOF;
@@ -1956,9 +1961,9 @@ svn_ra_serf__request_create(svn_ra_serf_
   handler->sline.version = 0;
   handler->location = NULL;
   handler->reading_body = FALSE;
+  handler->discard_body = FALSE;
 
-  /* ### sometimes, we alter the >response_handler. how to reset that?
-     ### so far, that is just to discard the body. maybe a flag?  */
+  /* ### do we ever alter the >response_handler?  */
 
   /* ### do we need to hold onto the returned request object, or just
      ### not worry about it (the serf ctx will manage it).  */