You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apr.apache.org by Cliff Woolley <cl...@yahoo.com> on 2000/12/12 06:50:03 UTC
[PATCH] ap_brigade_partition() (was Re: brigade/bucket splitting)
Okay, here is the updated patch. I've dumped ap_brigade_split_offset() in favor of
ap_brigade_partition() as suggested by Greg.
Note as I mentioned in my previous email that all you have to do to simulate the
behavior of _split_offset() is effectively the following, though in reality you'd
want to test the result of the partition for NULL first:
ap_bucket_brigade *bb2 = ap_brigade_split(bb,ap_brigade_partition(bb,point));
I also agree with Greg on the point==len issue. I this instance, if point==len, no
split should occur, since it's unnecessary to dump an empty bucket into the brigade
at the partition point, and it's a nice optimization to avoid calling
split/read/split if we already have a bucket that starts where we want it to. This
is not a bucket split function, so it doesn't need to act exactly like one.
I'm on Ryan's side, however, about the partition-past-the-end case... that really
does need to be an error condition. If we partition past the end, there's no bucket
to return a pointer to.
--Cliff
Index: include/ap_buckets.h
===================================================================
RCS file: /home/cvspublic/apr-util/include/ap_buckets.h,v
retrieving revision 1.59
diff -u -r1.59 ap_buckets.h
--- include/ap_buckets.h 2000/12/09 21:22:43 1.59
+++ include/ap_buckets.h 2000/12/12 05:47:08
@@ -583,6 +583,18 @@
APR_DECLARE(ap_bucket_brigade *) ap_brigade_split(ap_bucket_brigade *b,
ap_bucket *e);
+/**
+ * Partition a bucket brigade at a given offset (in bytes from the start of
+ * the brigade). This is useful whenever a filter wants to use known ranges
+ * of bytes from the brigade; the ranges can even overlap.
+ * @param b The brigade to partition
+ * @param point The offset at which to partition the brigade
+ * @return A pointer to the first bucket after the partition;
+ * or NULL in any error condition (including partition past the end)
+ * @deffunc ap_bucket *ap_brigade_partition(ap_bucket_brigade *b, apr_off_t point)
+ */
+APR_DECLARE(ap_bucket *) ap_brigade_partition(ap_bucket_brigade *b, apr_off_t
point);
+
#if APR_NOT_DONE_YET
/**
* consume nbytes from beginning of b -- call ap_bucket_destroy as
@@ -704,18 +716,6 @@
* @deffunc apr_status_t ap_bucket_copy(ap_bucket *e, ap_bucket **c)
*/
#define ap_bucket_copy(e,c) e->type->copy(e, c)
-
-/**
- * Split a bucket into two, using ap_bucket_split() if that's possible
- * for the given bucket type. If split() is not implemented for the
- * bucket's type, then we perform a blocking read on the bucket. That
- * morphs the bucket into a splittable bucket (eg, pipe becomes heap),
- * and we then split the result.
- * @param e The bucket to split
- * @param point The offset to split the bucket at
- * @deffunc apr_status_t ap_bucket_split_any(ap_bucket *e, apr_off_t point)
- */
-APR_DECLARE(apr_status_t) ap_bucket_split_any(ap_bucket *e, apr_off_t point);
/* Bucket type handling */
Index: src/buckets/ap_buckets.c
===================================================================
RCS file: /home/cvspublic/apr-util/src/buckets/ap_buckets.c,v
retrieving revision 1.36
diff -u -r1.36 ap_buckets.c
--- src/buckets/ap_buckets.c 2000/12/09 21:22:44 1.36
+++ src/buckets/ap_buckets.c 2000/12/12 05:47:10
@@ -122,31 +122,46 @@
return a;
}
-APR_DECLARE(apr_status_t) ap_bucket_split_any(ap_bucket *e, apr_off_t point)
+APR_DECLARE(ap_bucket *) ap_brigade_partition(ap_bucket_brigade *b, apr_off_t
point)
{
- apr_status_t rv;
- const char *str;
+ ap_bucket *e;
+ const char *s;
apr_size_t len;
- /* try to split this bucket directly */
- rv = ap_bucket_split(e, point);
- if (rv != APR_ENOTIMPL) {
- return rv;
- }
+ if (point < 0)
+ return NULL;
- /* if the bucket cannot be split, we must read from it,
- * changing its type to one that can be split */
- if (point < 0) {
- return APR_EINVAL;
- }
- rv = ap_bucket_read(e, &str, &len, AP_BLOCK_READ);
- if (rv != APR_SUCCESS) {
- return rv;
- }
- if (point > len) {
- return APR_EINVAL;
+ AP_BRIGADE_FOREACH(e, b) {
+ /* bucket is of a known length */
+ if ((point > e->length) && (e->length != -1)) {
+ if (AP_BUCKET_IS_EOS(e))
+ return NULL;
+ point -= e->length;
+ }
+ else if (point == e->length) {
+ return AP_BUCKET_NEXT(e);
+ }
+ else {
+ /* try to split the bucket natively */
+ if (ap_bucket_split(e, point) != APR_ENOTIMPL)
+ return AP_BUCKET_NEXT(e);
+
+ /* if the bucket cannot be split, we must read from it,
+ * changing its type to one that can be split */
+ if (ap_bucket_read(e, &s, &len, AP_BLOCK_READ) != APR_SUCCESS)
+ return NULL;
+
+ if (point < len) {
+ if (ap_bucket_split(e, point) == APR_SUCCESS)
+ return AP_BUCKET_NEXT(e);
+ else
+ return NULL;
+ }
+ else if (point == len)
+ return AP_BUCKET_NEXT(e);
+ }
}
- return ap_bucket_split(e, point);
+ return NULL;
}
APR_DECLARE(int) ap_brigade_to_iovec(ap_bucket_brigade *b,
__________________________________________________
Do You Yahoo!?
Yahoo! Shopping - Thousands of Stores. Millions of Products.
http://shopping.yahoo.com/