You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@commons.apache.org by gs...@apache.org on 2003/10/27 22:14:32 UTC

svn commit: rev 53 - commons/serf/branches/gen2

Author: gstein
Date: Mon Oct 27 13:14:32 2003
New Revision: 53

Modified:
   commons/serf/branches/gen2/serf.h
Log:
Change the read() function to allow reading up to a specific number of
bytes, rather than always doing "all available". Also provide a new
readline() function.

* serf/branches/gen2/serf.h:
  (SERF_READ_ALL_AVAIL): new constant to define "read all available data".
  (SERF_NEWLINE_CR, SERF_NEWLINE_CRLF, SERF_NEWLINE_LF, SERF_NEWLINE_ANY,
      SERF_NEWLINE_NONE): new constants to define different newline types.
  (bucket.read): take a new parameter to specify the (maximum) number of
    bytes to read from the bucket. this prevents protocol read overruns.
  (bucket.readline): new function to read a line of text from the bucket.


Modified: commons/serf/branches/gen2/serf.h
==============================================================================
--- commons/serf/branches/gen2/serf.h	(original)
+++ commons/serf/branches/gen2/serf.h	Mon Oct 27 13:14:32 2003
@@ -266,13 +266,28 @@
  * @{
  */
 
+/** Pass as REQUESTED to the read() bucket function to read, consume,
+ * and return all available data.
+ */
+#define SERF_READ_ALL_AVAIL ((apr_size_t)-1)
+
+/** Acceptable newline types for bucket->readline(). */
+#define SERF_NEWLINE_CR    0x0001
+#define SERF_NEWLINE_CRLF  0x0002
+#define SERF_NEWLINE_LF    0x0004
+#define SERF_NEWLINE_ANY   0x0007
+
+/** Used to indicate that a newline is not present in the data buffer. */
+#define SERF_NEWLINE_NONE  0x0008
+
+
 struct serf_bucket_type_t {
 
     /** name of this bucket type */
     const char *name;
 
     /**
-     * Read and consume data out of @a bucket.
+     * Read (and consume) up to @a requested bytes from @a bucket.
      *
      * A pointer to the data will be returned in @a data, and its length
      * is specified by @a len.
@@ -285,8 +300,25 @@
      * If an application needs the data to exist for a longer duration,
      * then it must make a copy.
      */
-    apr_status_t (*read)(serf_bucket_t *bucket,
+    apr_status_t (*read)(serf_bucket_t *bucket, apr_size_t requested,
                          const char **data, apr_size_t *len);
+
+    /**
+     * Read (and consume) a line of data from @a bucket.
+     *
+     * The acceptable forms of a newline are given by @a acceptable, and
+     * the type found is returned in @a found. If a newline is not present
+     * in the returned data, then SERF_NEWLINE_NONE is stored into @a found.
+     *
+     * A pointer to the data is returned in @a data, and its length is
+     * specified by @a len. The data will include the newline, if present.
+     *
+     * The lifetime of the data is the same as that of the @see read
+     * function above.
+     */
+    apr_status_t (*readline)(serf_bucket_t *bucket, int acceptable,
+                             int *found,
+                             const char **data, apr_size_t *len);
 
     /**
      * Peek, but don't consume, the data in @a bucket.