From 93996b1b21e59a4dbfb707ca727dd779a8057907 Mon Sep 17 00:00:00 2001 From: Fernando Brito Date: Wed, 1 Dec 2010 01:45:45 -0300 Subject: [PATCH 1/7] Move read and readline from FileHandle to Handle --- src/pmc/filehandle.pmc | 33 --------------------------------- src/pmc/handle.pmc | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/pmc/filehandle.pmc b/src/pmc/filehandle.pmc index 932a3aaea8..c6131541f5 100644 --- a/src/pmc/filehandle.pmc +++ b/src/pmc/filehandle.pmc @@ -308,39 +308,6 @@ Test if the filehandle is closed. } -/* - -=item C - -Read the given number of bytes from the filehandle and return them in a string. - -=cut - -*/ - - METHOD read(INTVAL length) { - STRING * const string_result = Parrot_io_reads(INTERP, SELF, length); - - RETURN(STRING *string_result); - } - - -/* - -=item C - -Read a line from the filehandle and return it in a string. - -=cut - -*/ - - METHOD readline() { - STRING * const string_result = Parrot_io_readline(INTERP, SELF); - RETURN(STRING *string_result); - } - - /* =item C diff --git a/src/pmc/handle.pmc b/src/pmc/handle.pmc index 35e8f21e8c..0eb0ec3b3f 100644 --- a/src/pmc/handle.pmc +++ b/src/pmc/handle.pmc @@ -91,6 +91,39 @@ platforms that use integer file descriptors). } +/* + +=item C + +Read the given number of bytes from the handle and return them in a string. + +=cut + +*/ + + METHOD read(INTVAL length) { + STRING * const string_result = Parrot_io_reads(INTERP, SELF, length); + + RETURN(STRING *string_result); + } + + +/* + +=item C + +Read a line from the handle and return it in a string. + +=cut + +*/ + + METHOD readline() { + STRING * const string_result = Parrot_io_readline(INTERP, SELF); + RETURN(STRING *string_result); + } + + /* =item C From da7f551b2f0fdd3b51d04eceb350b88227463bb2 Mon Sep 17 00:00:00 2001 From: Fernando Brito Date: Wed, 1 Dec 2010 01:49:49 -0300 Subject: [PATCH 2/7] Make recv method call Parrot_io_reads --- src/io/api.c | 5 ++++- src/pmc/socket.pmc | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/io/api.c b/src/io/api.c index e739e9daf6..52aeb33a2a 100644 --- a/src/io/api.c +++ b/src/io/api.c @@ -381,7 +381,7 @@ Parrot_io_flush(PARROT_INTERP, ARGMOD_NULLOK(PMC *pmc)) =item C -Return a new C holding up to C bytes read from the filehandle +Return a new C holding up to C bytes read from the handle PMC. Calls the C method on the filehandle PMC. =cut @@ -452,6 +452,9 @@ Parrot_io_reads(PARROT_INTERP, ARGMOD(PMC *pmc), size_t length) SETATTR_StringHandle_read_offset(interp, pmc, offset + read_length); } } + else if (pmc->vtable->base_type == enum_class_Socket) { + INTVAL read = Parrot_io_recv(interp, pmc, &result); + } else Parrot_pcc_invoke_method_from_c_args(interp, pmc, CONST_STRING(interp, "read"), "I->S", length, &result); return result; diff --git a/src/pmc/socket.pmc b/src/pmc/socket.pmc index fa2d0aa704..f792c29022 100644 --- a/src/pmc/socket.pmc +++ b/src/pmc/socket.pmc @@ -214,7 +214,7 @@ string containing the received message. METHOD recv() { STRING * result; - INTVAL read = Parrot_io_recv(INTERP, SELF, &result); + result = Parrot_io_reads(INTERP, SELF, 0); RETURN(STRING * result); } From 617ebe6d2a2d3d9deb4efd8ca7cef6fa93d03cf1 Mon Sep 17 00:00:00 2001 From: Fernando Brito Date: Wed, 1 Dec 2010 01:54:46 -0300 Subject: [PATCH 3/7] Make Parrot_io_readline throw exception on Socket --- src/io/api.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/io/api.c b/src/io/api.c index 52aeb33a2a..de3ee44c37 100644 --- a/src/io/api.c +++ b/src/io/api.c @@ -512,6 +512,10 @@ Parrot_io_readline(PARROT_INTERP, ARGMOD(PMC *pmc)) result = STRING_substr(interp, result, offset, read_length); SETATTR_StringHandle_read_offset(interp, pmc, newline_pos + 1); } + else if (pmc->vtable->base_type == enum_class_Socket) { + Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_UNIMPLEMENTED, + "Parrot_io_readline on Socket not implemented"); + } else Parrot_pcc_invoke_method_from_c_args(interp, pmc, CONST_STRING(interp, "readline"), "->S", &result); return result; From 4af637d6351efe66ea0dd64163f67428c77c91d1 Mon Sep 17 00:00:00 2001 From: Fernando Brito Date: Wed, 1 Dec 2010 02:00:05 -0300 Subject: [PATCH 4/7] Remove read and readline from FileHandle (should be inherited from Handle) --- src/pmc/handle.pmc | 1 - src/pmc/stringhandle.pmc | 31 ------------------------------- 2 files changed, 32 deletions(-) diff --git a/src/pmc/handle.pmc b/src/pmc/handle.pmc index 0eb0ec3b3f..af7ed8d147 100644 --- a/src/pmc/handle.pmc +++ b/src/pmc/handle.pmc @@ -103,7 +103,6 @@ Read the given number of bytes from the handle and return them in a string. METHOD read(INTVAL length) { STRING * const string_result = Parrot_io_reads(INTERP, SELF, length); - RETURN(STRING *string_result); } diff --git a/src/pmc/stringhandle.pmc b/src/pmc/stringhandle.pmc index 8bda3ce0d6..1d49cf2a07 100644 --- a/src/pmc/stringhandle.pmc +++ b/src/pmc/stringhandle.pmc @@ -232,37 +232,6 @@ Check if the StringHandle is open. RETURN(INTVAL status); } -/* - -=item C - -Read the entire contents of the stringhandle and return it in a string. The -C argument is currently ignored. - -=cut - -*/ - - METHOD read(INTVAL length) { - STRING * const string_result = Parrot_io_reads(INTERP, SELF, length); - RETURN(STRING *string_result); - } - -/* - -=item C - -Read a line from the stringhandle and return it in a string. (Currently only -responds to "\n" newlines.) - -=cut - -*/ - - METHOD readline() { - STRING * const string_result = Parrot_io_readline(INTERP, SELF); - RETURN(STRING *string_result); - } /* From 35efb357d2beb1333f1d28df6b21f6e5a9eb5f64 Mon Sep 17 00:00:00 2001 From: Fernando Brito Date: Wed, 1 Dec 2010 02:14:30 -0300 Subject: [PATCH 5/7] [t] Move socket get_fd test to its own method --- t/pmc/socket.t | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/t/pmc/socket.t b/t/pmc/socket.t index d445477ff5..9df25afab5 100644 --- a/t/pmc/socket.t +++ b/t/pmc/socket.t @@ -22,6 +22,7 @@ Tests the Socket PMC. plan(16) test_init() + test_get_fd() test_clone() test_bool() test_close() @@ -40,13 +41,16 @@ Tests the Socket PMC. new $P0, ['Socket'] ok(1, 'Instantiated a Socket PMC') - $N0 = $P0.'get_fd'() - isnt($N0, -1, 'Socket get_fd did not return -1') - $S0 = typeof $P0 is($S0, 'Socket', 'PMC has correct type') .end +.sub test_get_fd + new $P0, ['Socket'] + $N0 = $P0.'get_fd'() + isnt($N0, -1, 'Socket get_fd did not return -1') +.end + .sub test_bool new $P0, ['Socket'] ok($P0, 'get_bool on Socket') From d3bdb44cc5945faff78252551224f40edf74615b Mon Sep 17 00:00:00 2001 From: Fernando Brito Date: Wed, 1 Dec 2010 15:58:03 -0300 Subject: [PATCH 6/7] [t] Add test to Socket readline (not implemented) --- t/pmc/socket.t | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/t/pmc/socket.t b/t/pmc/socket.t index 9df25afab5..9fb8a01e1f 100644 --- a/t/pmc/socket.t +++ b/t/pmc/socket.t @@ -19,10 +19,11 @@ Tests the Socket PMC. .sub main :main .include 'test_more.pir' - plan(16) + plan(17) test_init() test_get_fd() + test_readline() test_clone() test_bool() test_close() @@ -51,6 +52,15 @@ Tests the Socket PMC. isnt($N0, -1, 'Socket get_fd did not return -1') .end +.sub test_readline + throws_substring(<<'CODE', 'not implemented', 'Socket readline is not implemented') + .sub main + new $P0, ['Socket'] + $P0.'readline'() + .end +CODE +.end + .sub test_bool new $P0, ['Socket'] ok($P0, 'get_bool on Socket') From 4a2f0c7585096a63615e9f8ba70cbeb289c27483 Mon Sep 17 00:00:00 2001 From: Fernando Brito Date: Wed, 1 Dec 2010 16:17:50 -0300 Subject: [PATCH 7/7] [t] Add test to Socket read --- t/pmc/socket.t | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/t/pmc/socket.t b/t/pmc/socket.t index 9fb8a01e1f..1331715f9d 100644 --- a/t/pmc/socket.t +++ b/t/pmc/socket.t @@ -19,10 +19,11 @@ Tests the Socket PMC. .sub main :main .include 'test_more.pir' - plan(17) + plan(18) test_init() test_get_fd() + test_read() test_readline() test_clone() test_bool() @@ -52,6 +53,12 @@ Tests the Socket PMC. isnt($N0, -1, 'Socket get_fd did not return -1') .end +.sub test_read + new $P0, ['Socket'] + $N0 = $P0.'read'(5) + is($N0, 0, 'Socket read returns 0 when not connected') +.end + .sub test_readline throws_substring(<<'CODE', 'not implemented', 'Socket readline is not implemented') .sub main