subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhuij...@apache.org
Subject svn commit: r1562077 - in /subversion/trunk/subversion: include/svn_error_codes.h include/svn_io.h libsvn_ra_svn/cyrus_auth.c libsvn_ra_svn/streams.c libsvn_subr/deprecated.c libsvn_subr/stream.c
Date Tue, 28 Jan 2014 14:18:38 GMT
Author: rhuijben
Date: Tue Jan 28 14:18:37 2014
New Revision: 1562077

URL: http://svn.apache.org/r1562077
Log:
Following up on r1561688, remove the automatic use of a full read as default
implementation for a possibly partial read. Provide a default full read
implementation for code that only implements partial reads.

* subversion/include/svn_error_codes.h
  (SVN_ERR_STREAM_DATA_AVAILABLE_NOT_SUPPORTED): Rename to...
  (SVN_ERR_STREAM_NOT_SUPPORTED): ... this instead of adding yet another error.

* subversion/include/svn_io.h
  (svn_stream_set_read2,
   svn_stream_set_read): Tweak comments.
  (svn_stream_read2): Document not implemented behavior.
  (svn_stream_data_available): Update error code.

* subversion/libsvn_ra_svn/cyrus_auth.c
  (sasl_read_full_cb): Remove function.
  (svn_ra_svn__enable_sasl_encryption): Pass null instead of stub.

* subversion/libsvn_ra_svn/streams.c
  (sock_read_full_cb): Remove function.
  (svn_ra_svn__stream_from_sock): Pass NULL instead of stub.

* subversion/libsvn_subr/deprecated.c
  (svn_stream_set_read): Update caller with new rules.

* subversion/libsvn_subr/stream.c
  (full_read_fallback): New function.
  (svn_stream_read2): Return documented error instead of assert when not set.
  (svn_stream_read_full): Fall back to multiple calls to svn_stream_read2
    not set.
  (data_available_handler_apr): Update error code.

Modified:
    subversion/trunk/subversion/include/svn_error_codes.h
    subversion/trunk/subversion/include/svn_io.h
    subversion/trunk/subversion/libsvn_ra_svn/cyrus_auth.c
    subversion/trunk/subversion/libsvn_ra_svn/streams.c
    subversion/trunk/subversion/libsvn_subr/deprecated.c
    subversion/trunk/subversion/libsvn_subr/stream.c

Modified: subversion/trunk/subversion/include/svn_error_codes.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/include/svn_error_codes.h?rev=1562077&r1=1562076&r2=1562077&view=diff
==============================================================================
--- subversion/trunk/subversion/include/svn_error_codes.h (original)
+++ subversion/trunk/subversion/include/svn_error_codes.h Tue Jan 28 14:18:37 2014
@@ -323,9 +323,9 @@ SVN_ERROR_START
              "Stream doesn't support seeking")
 
   /** Since New in 1.9. */
-  SVN_ERRDEF(SVN_ERR_STREAM_DATA_AVAILABLE_NOT_SUPPORTED,
+  SVN_ERRDEF(SVN_ERR_STREAM_NOT_SUPPORTED,
              SVN_ERR_STREAM_CATEGORY_START + 4,
-             "Stream doesn't support data available")
+             "Stream doesn't support this capability")
 
   /* node errors */
 

Modified: subversion/trunk/subversion/include/svn_io.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/include/svn_io.h?rev=1562077&r1=1562076&r2=1562077&view=diff
==============================================================================
--- subversion/trunk/subversion/include/svn_io.h (original)
+++ subversion/trunk/subversion/include/svn_io.h Tue Jan 28 14:18:37 2014
@@ -910,7 +910,9 @@ void
 svn_stream_set_baton(svn_stream_t *stream,
                      void *baton);
 
-/** Set @a stream's read functions to @a read_fn and @a read_full_fn
+/** Set @a stream's read functions to @a read_fn and @a read_full_fn. If
+ * @a read_full_fn is NULL a default implementation based on multiple calls
+ * to @a read_fn will be used.
  *
  * @since New in 1.9.
  */
@@ -921,8 +923,7 @@ svn_stream_set_read2(svn_stream_t *strea
 
 /** Set @a stream's read function to @a read_fn.
  *
- * This function now sets both the read and full read function to read_fn as
- * originally the stream api only supported full reads.
+ * This function sets only the full read function to read_fn.
  *
  * @deprecated Provided for backward compatibility with the 1.8 API.
  */
@@ -1218,7 +1219,8 @@ svn_stream_read_full(svn_stream_t *strea
 
 /** Read all currently available upto @a *len into @a buffer. Use
  * svn_stream_read_full() if you want to wait for the buffer to be filled
- * or EOF.
+ * or EOF. If the stream doesn't support limited reads this function will
+ * return an #SVN_ERR_STREAM_NOT_SUPPORTED error.
  *
  * A 0 byte read signals the end of the stream.
  *
@@ -1316,8 +1318,8 @@ svn_stream_seek(svn_stream_t *stream, co
 
 /** When a stream supports polling for available data, obtain a boolean
  * indicating whether data is waiting to be read. If the stream doesn't
- * support polling this function returns a
- * #SVN_ERR_STREAM_DATA_AVAILABLE_NOT_SUPPORTED error.
+ * support polling this function returns a #SVN_ERR_STREAM_NOT_SUPPORTED
+ * error.
  *
  * If the data_available callback is implemented and the stream is at the end
  * the stream will set @a *data_available to FALSE.

Modified: subversion/trunk/subversion/libsvn_ra_svn/cyrus_auth.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_ra_svn/cyrus_auth.c?rev=1562077&r1=1562076&r2=1562077&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_ra_svn/cyrus_auth.c (original)
+++ subversion/trunk/subversion/libsvn_ra_svn/cyrus_auth.c Tue Jan 28 14:18:37 2014
@@ -650,12 +650,6 @@ static svn_error_t *sasl_read_cb(void *b
   return SVN_NO_ERROR;
 }
 
-static svn_error_t *sasl_read_full_cb(void *baton, char *buffer, apr_size_t *len)
-{
-  /* ### Currently unused code path */
-  return svn_error_create(SVN_ERR_RA_NOT_IMPLEMENTED, NULL, NULL);
-}
-
 /* Implements svn_write_fn_t. */
 static svn_error_t *
 sasl_write_cb(void *baton, const char *buffer, apr_size_t *len)
@@ -777,7 +771,7 @@ svn_error_t *svn_ra_svn__enable_sasl_enc
             svn_stream_t *sasl_in = svn_stream_create(sasl_baton, conn->pool);
             svn_stream_t *sasl_out = svn_stream_create(sasl_baton, conn->pool);
 
-            svn_stream_set_read2(sasl_in, sasl_read_cb, sasl_read_full_cb);
+            svn_stream_set_read2(sasl_in, sasl_read_cb, NULL /* use default */);
             svn_stream_set_data_available(sasl_in, sasl_pending_cb);
             svn_stream_set_write(sasl_out, sasl_write_cb);
 

Modified: subversion/trunk/subversion/libsvn_ra_svn/streams.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_ra_svn/streams.c?rev=1562077&r1=1562076&r2=1562077&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_ra_svn/streams.c (original)
+++ subversion/trunk/subversion/libsvn_ra_svn/streams.c Tue Jan 28 14:18:37 2014
@@ -124,15 +124,6 @@ sock_read_cb(void *baton, char *buffer, 
   return SVN_NO_ERROR;
 }
 
-static svn_error_t *
-sock_read_full_cb(void *baton, char *buffer, apr_size_t *len)
-{
-  /* TODO: Implement */
-
-  /* ### Unreachable code */
-  return svn_error_create(SVN_ERR_RA_NOT_IMPLEMENTED, NULL, NULL);
-}
-
 /* Implements svn_write_fn_t */
 static svn_error_t *
 sock_write_cb(void *baton, const char *buffer, apr_size_t *len)
@@ -182,7 +173,7 @@ svn_ra_svn__stream_from_sock(apr_socket_
 
   sock_stream = svn_stream_create(b, result_pool);
 
-  svn_stream_set_read2(sock_stream, sock_read_cb, sock_read_full_cb);
+  svn_stream_set_read2(sock_stream, sock_read_cb, NULL /* use default */);
   svn_stream_set_write(sock_stream, sock_write_cb);
   svn_stream_set_data_available(sock_stream, sock_pending_cb);
 

Modified: subversion/trunk/subversion/libsvn_subr/deprecated.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/deprecated.c?rev=1562077&r1=1562076&r2=1562077&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/deprecated.c (original)
+++ subversion/trunk/subversion/libsvn_subr/deprecated.c Tue Jan 28 14:18:37 2014
@@ -1072,7 +1072,8 @@ void
 svn_stream_set_read(svn_stream_t *stream,
                     svn_read_fn_t read_fn)
 {
-  svn_stream_set_read2(stream, read_fn, read_fn);
+  svn_stream_set_read2(stream, NULL /* only full read support */,
+                       read_fn);
 }
 
 svn_error_t *

Modified: subversion/trunk/subversion/libsvn_subr/stream.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/stream.c?rev=1562077&r1=1562076&r2=1562077&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/stream.c (original)
+++ subversion/trunk/subversion/libsvn_subr/stream.c Tue Jan 28 14:18:37 2014
@@ -153,21 +153,53 @@ svn_stream__set_is_buffered(svn_stream_t
   stream->is_buffered_fn = is_buffered_fn;
 }
 
+/* Standard implementation for svn_stream_read_full() based on multiple.
+   svn_stream_read2() calls
+   (in separate function to make it more likely for svn_stream_read_full
+    to be inlined) */
+static svn_error_t *
+full_read_fallback(svn_stream_t *stream, char *buffer, apr_size_t *len)
+{
+  apr_size_t to_read;
+
+  to_read = *len;
+
+  while (to_read > 0)
+    {
+      *len = to_read;
+      SVN_ERR(svn_stream_read2(stream, buffer, len));
+
+      to_read -= *len;
+      buffer += *len;
+
+      if (*len == 0)
+        {
+          *len = to_read;
+          return SVN_NO_ERROR;
+        }
+    }
+
+  return SVN_NO_ERROR;
+}
+
 svn_error_t *
 svn_stream_read2(svn_stream_t *stream, char *buffer, apr_size_t *len)
 {
-  SVN_ERR_ASSERT(stream->read_fn != NULL);
+  if (stream->read_fn == NULL)
+    return svn_error_create(SVN_ERR_STREAM_NOT_SUPPORTED, NULL, NULL);
+
   return svn_error_trace(stream->read_fn(stream->baton, buffer, len));
 }
 
 svn_error_t *
 svn_stream_read_full(svn_stream_t *stream, char *buffer, apr_size_t *len)
 {
-  SVN_ERR_ASSERT(stream->read_full_fn != NULL);
+  if (stream->read_full_fn == NULL)
+    return svn_error_trace(full_read_fallback(stream, buffer, len));
+
   return svn_error_trace(stream->read_full_fn(stream->baton, buffer, len));
 }
 
-
 svn_error_t *
 svn_stream_skip(svn_stream_t *stream, apr_size_t len)
 {
@@ -224,8 +256,7 @@ svn_stream_data_available(svn_stream_t *
                           svn_boolean_t *data_available)
 {
   if (stream->data_available_fn == NULL)
-    return svn_error_create(SVN_ERR_STREAM_DATA_AVAILABLE_NOT_SUPPORTED,
-                            NULL, NULL);
+    return svn_error_create(SVN_ERR_STREAM_NOT_SUPPORTED, NULL, NULL);
 
   return svn_error_trace(stream->data_available_fn(stream->baton,
                                                    data_available));
@@ -936,7 +967,7 @@ data_available_handler_apr(void *baton, 
     }
   else
     {
-      return svn_error_create(SVN_ERR_STREAM_DATA_AVAILABLE_NOT_SUPPORTED,
+      return svn_error_create(SVN_ERR_STREAM_NOT_SUPPORTED,
                               svn_error_create(status, NULL, NULL),
                               NULL);
     }



Mime
View raw message