develooper Front page | perl.cvs.mod_parrot | Postings from January 2009

[svn:mod_parrot] r567 - in mod_parrot/trunk: src/pmc t/response/TestAPI

From:
jhorwitz
Date:
January 1, 2009 15:48
Subject:
[svn:mod_parrot] r567 - in mod_parrot/trunk: src/pmc t/response/TestAPI
Message ID:
20090101234829.1EDC4CB9FA@x12.develooper.com
Author: jhorwitz
Date: Thu Jan  1 15:48:28 2009
New Revision: 567

Modified:
   mod_parrot/trunk/src/pmc/modparrothandle.pmc
   mod_parrot/trunk/t/response/TestAPI/modparrothandle.pir

Log:
implement readall method for ModParrotHandle


Modified: mod_parrot/trunk/src/pmc/modparrothandle.pmc
==============================================================================
--- mod_parrot/trunk/src/pmc/modparrothandle.pmc	(original)
+++ mod_parrot/trunk/src/pmc/modparrothandle.pmc	Thu Jan  1 15:48:28 2009
@@ -37,6 +37,8 @@
 #include "httpd.h"
 #include "http_protocol.h"
 
+#define MODPARROTHANDLE_READ_SIZE 1024
+
 pmclass ModParrotHandle dynpmc need_ext group modparrot_group {
     ATTR INTVAL  flags;               /* Filehandle flags             */
     ATTR STRING *mode;                /* The mode string used in open */
@@ -312,15 +314,62 @@
 
 /*
 
-=item METHOD readall(STRING *name);
+=item <METHOD readall(STRING *ignored)>
 
-TODO
+XXX
 
 =cut
 
 */
 
-/* readall code here */
+    METHOD readall(STRING *ignored) {
+        PMC *rpmc, *attrpmc;
+        STRING *result, *attrname;
+        request_rec *r;
+        apr_table_t *headers;
+        const char *buf;
+        int length, nread, total;
+
+        if (Parrot_io_is_closed_filehandle(INTERP, SELF)) {
+            Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_PIO_ERROR,
+                "Cannot readall without a request_rec object or open handle");
+        }
+
+        GET_ATTR_r(INTERP, SELF, rpmc);
+        if (!rpmc)
+            Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_PIO_ERROR,
+                "Cannot read from a closed filehandle");
+        attrname = const_string(INTERP, "r");
+        attrpmc = VTABLE_get_attr_str(INTERP, rpmc, attrname);
+        r = (request_rec *)PMC_data(attrpmc);
+
+        result = string_make_empty(INTERP, enum_stringrep_one, 0);
+        headers = r->headers_in;
+        buf = apr_table_get(headers, "Content-Length");
+        if (!buf) {
+            RETURN (STRING *result);
+        }
+        length = atoi(buf);
+        if (!length) {
+            RETURN (STRING *result);
+        }
+        do {
+            STRING * const part =
+                Parrot_io_reads(INTERP, SELF, MODPARROTHANDLE_READ_SIZE);
+            /* XXX is this reliably in bytes??? */
+            nread = string_length(INTERP, part);
+            if (nread) {
+                result = string_append(INTERP, result, part);
+            }
+            else {
+                /* prevent infinite loops.  this should never happen */
+                break;
+            }
+            total += nread;
+        } while (total < length);
+
+        RETURN(STRING *result);
+    }
 
 /*
 

Modified: mod_parrot/trunk/t/response/TestAPI/modparrothandle.pir
==============================================================================
--- mod_parrot/trunk/t/response/TestAPI/modparrothandle.pir	(original)
+++ mod_parrot/trunk/t/response/TestAPI/modparrothandle.pir	Thu Jan  1 15:48:28 2009
@@ -68,7 +68,14 @@
     r.'puts'("not ok 9 - readline # TODO\n")
 
   START_10:
-    r.'puts'("not ok 10 - readall # TODO\n")
+    push_eh NOT_OK_10
+    $S0 = fh.'readall'('')
+    pop_eh
+    if $S0 == "" goto OK_10
+  NOT_OK_10:
+    r.'puts'("not ")
+  OK_10:
+    r.'puts'("ok 10 - readall\n")
 
   START_11:
     fh.'setstdin'(old)



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About