here's APR::Brigade::pflatten(), with tests
--Geoff
Index: t/response/TestAPR/flatten.pm
===================================================================
RCS file: /home/cvspublic/modperl-2.0/t/response/TestAPR/flatten.pm,v
retrieving revision 1.1
diff -u -r1.1 flatten.pm
--- t/response/TestAPR/flatten.pm 23 Jan 2004 15:26:55 -0000 1.1
+++ t/response/TestAPR/flatten.pm 23 Jan 2004 19:40:18 -0000
@@ -16,7 +16,7 @@
my $r = shift;
- plan $r, tests => 9;
+ plan $r, tests => 15;
# first, create a brigade
my $bb = APR::Brigade->new($r->pool,
@@ -34,7 +34,52 @@
$bb->length,
'APR::Brigade::length()');
- # slurp up the entire brigade
+ # APR::Brigade::pflatten() tests
+
+ # pflatten() is recommended over flatten() if you
+ # want to slurp up the entire brigade. flatten()
+ # is more suited to examining only the first N bytes
+ {
+ my $rc = $bb->pflatten(my $data, my $length, $r->pool);
+
+ ok t_cmp(APR::SUCCESS,
+ $rc,
+ 'APR::Brigade::pflatten() return value');
+
+ ok t_cmp(200000,
+ $length,
+ 'APR::Brigade::pflatten() length population');
+
+ ok t_cmp(200000,
+ length($data),
+ 'APR::Brigade::pflatten() returned all the data');
+
+ # don't use t_cmp() here, else we get 200,000 characters
+ # to look at in verbose mode
+ t_debug("APR::Brigade::pflatten() data all 'x' characters");
+ ok ($data !~ m/[^x]/);
+ }
+
+ # pflatten() populates $length. make sure that if users
+ # get flatten() (which requires a length) and pflatten()
+ # confused that we don't segfault
+ {
+ my $rc = $bb->pflatten(my $data, 30, $r->pool);
+
+ ok t_cmp(APR::SUCCESS,
+ $rc,
+ 'APR::Brigade::pflatten() return value');
+
+ # incoming $length is ignored - all data is returned
+ ok t_cmp(200000,
+ length($data),
+ 'APR::Brigade::pflatten() returned all the data');
+
+ }
+
+
+ # APR::Brigade::flatten() tests
+
# this is somewhat wasteful, since we're simulating a user
# 'guessing' at how much data there is to slurp
{
@@ -94,8 +139,6 @@
length($data),
'APR::Brigade::flatten() returned all the data');
}
-
- # pflatten() examples to come...
Apache::OK;
}
Index: xs/APR/Brigade/APR__Brigade.h
===================================================================
RCS file: /home/cvspublic/modperl-2.0/xs/APR/Brigade/APR__Brigade.h,v
retrieving revision 1.5
diff -u -r1.5 APR__Brigade.h
--- xs/APR/Brigade/APR__Brigade.h 23 Jan 2004 15:26:55 -0000 1.5
+++ xs/APR/Brigade/APR__Brigade.h 23 Jan 2004 19:40:18 -0000
@@ -103,3 +103,28 @@
return status;
}
+
+static MP_INLINE
+apr_status_t mpxs_apr_brigade_pflatten(pTHX_ apr_bucket_brigade *bb,
+ SV *sv_buf, SV *sv_len,
+ apr_pool_t *pool)
+{
+ apr_status_t status;
+ apr_size_t length;
+ char *buffer;
+
+ status = apr_brigade_pflatten(bb, &buffer, &length, pool);
+
+ /* XXX what if the pool goes out of scope? */
+ sv_setpvn(sv_buf, buffer, length);
+
+ /* we shouldn't need this check per the API, but just in
+ * case people get the flatten() and pflatten() arguments
+ * confused...
+ */
+ if (!SvREADONLY(sv_len)) {
+ sv_setiv(sv_len, length);
+ }
+
+ return status;
+}
Index: xs/maps/apr_functions.map
===================================================================
RCS file: /home/cvspublic/modperl-2.0/xs/maps/apr_functions.map,v
retrieving revision 1.66
diff -u -r1.66 apr_functions.map
--- xs/maps/apr_functions.map 23 Jan 2004 15:26:55 -0000 1.66
+++ xs/maps/apr_functions.map 23 Jan 2004 19:40:18 -0000
@@ -87,7 +87,7 @@
-apr_brigade_putc
!apr_brigade_cleanup
apr_brigade_flatten | mpxs_ | bb, SV *:sv_buf, SV *:sv_len
-?apr_brigade_pflatten
+ apr_brigade_pflatten | mpxs_ | bb, SV *:sv_buf, SV *:sv_len, pool
?apr_brigade_split_line
mpxs_APR__Brigade_first #APR_BRIGADE_FIRST
mpxs_APR__Brigade_last #APR_BRIGADE_LAST
Index: xs/tables/current/ModPerl/FunctionTable.pm
===================================================================
RCS file: /home/cvspublic/modperl-2.0/xs/tables/current/ModPerl/FunctionTable.pm,v
retrieving revision 1.139
diff -u -r1.139 FunctionTable.pm
--- xs/tables/current/ModPerl/FunctionTable.pm 23 Jan 2004 15:26:56 -0000 1.139
+++ xs/tables/current/ModPerl/FunctionTable.pm 23 Jan 2004 19:40:19 -0000
@@ -6484,6 +6484,32 @@
]
},
{
+ 'return_type' => 'apr_status_t',
+ 'name' => 'mpxs_apr_brigade_pflatten',
+ 'args' => [
+ {
+ 'type' => 'PerlInterpreter *',
+ 'name' => 'my_perl'
+ },
+ {
+ 'type' => 'apr_bucket_brigade *',
+ 'name' => 'bb'
+ },
+ {
+ 'type' => 'SV *',
+ 'name' => 'sv_buf'
+ },
+ {
+ 'type' => 'SV *',
+ 'name' => 'sv_len'
+ },
+ {
+ 'type' => 'apr_pool_t *',
+ 'name' => 'pool'
+ },
+ ]
+ },
+ {
'return_type' => 'apr_ipsubnet_t *',
'name' => 'mpxs_apr_ipsubnet_create',
'args' => [
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]