Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

base: master
...
compare: rurban/socket-read2-gh909
  • 2 commits
  • 2 files changed
  • 0 commit comments
  • 1 contributor
Commits on Jan 07, 2013
Reini Urban rurban [spec] GH #909 Update the socket doc for read and recv for our new PO…
…SIX behaviour

Before parrot-4.10 the high-level read() returned the wanted amount of bytes.
Now it behaves the same as recv(), which means that up to bytes are returned

We might want to add a setsockopt(level, option, value) method.
7f5d727
Commits on Jan 08, 2013
Reini Urban rurban [GH #909] Add test for chunked socket read
Socket.read will return chunked parts.
2734bd2
Showing with 40 additions and 5 deletions.
  1. +15 −2 src/pmc/socket.pmc
  2. +25 −3 t/pmc/socket.t
17 src/pmc/socket.pmc
View
@@ -1,5 +1,5 @@
/*
-Copyright (C) 2008-2012, Parrot Foundation.
+Copyright (C) 2008-2013, Parrot Foundation.
=head1 NAME
@@ -316,6 +316,9 @@ argument, and only returns a status object. When the recv operation is
complete, it invokes the callback, passing it a status object and a
string containing the received message.
+If the socket is closed or on other errors, it throws an .EXCEPTION_PIO_ERROR
+Exception.
+
=cut
*/
@@ -415,10 +418,20 @@ but continues to send new connection events until the socket is closed.]
=item C<METHOD read(INTVAL bytes)>
-Read the given number of bytes from the socket and return them in a string.
+Read up to the given number of bytes from the socket and return them in a string.
+
+This method behaves always the same as recv(). Only if the socket is already closed
+return an empty string.
=cut
+TODO: add setsockopt(level, option, value) for the pre-parrot 4.10 behavior, to receive larger buffers.
+
+The receive low-water mark (the SO_RCVLOWAT setsockopt option) determines the minimum amount of data
+that must be received before the read function is completed. If the read function times out, any
+data that was received is returned to the application even if the amount of data received is less
+than the receive low-water mark value.
+
*/
METHOD read(INTVAL nb) {
28 t/pmc/socket.t
View
@@ -1,5 +1,5 @@
#!./parrot
-# Copyright (C) 2006-2011, Parrot Foundation.
+# Copyright (C) 2006-2013, Parrot Foundation.
=head1 NAME
@@ -24,7 +24,7 @@ stack, so we don't need to check if this parrot is IPv6-aware.
.sub main :main
.include 'test_more.pir'
- plan(23)
+ plan(25)
test_init()
test_get_fd()
@@ -196,8 +196,30 @@ CODE
is(status, '12', 'send')
str = sock.'recv'()
is(str, 'test message', 'recv')
- sock.'close'()
+ .local int i, len, oldlen, readlen
+ i = 0
+ loop:
+ str = concat str, "a"
+ i = i + 1
+ if i < 2048 goto loop
+ oldlen = length str
+ status = sock.'send'(str)
+ is(status, oldlen, 'send() big')
+ str = ""
+ .local string tmpstr
+ loop1:
+ tmpstr = sock.'read'(1024)
+ readlen = length tmpstr
+ str = concat str, tmpstr
+ len = length str
+ # diag(len)
+ if len == 0 goto bigger
+ if len < oldlen goto loop1
+ bigger:
+ is(len, oldlen, 'read(1024) chunked')
+
+ sock.'close'()
server.'close'()
status = server.'exit_status'()
nok(status, 'Exit status of server process')

No commit comments for this range

Something went wrong with that request. Please try again.