New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow IO::Socket.recv() to take a parameter specifying the number of bytes to receive #1380
Comments
From @carbinThe current incarnation of recv() continually calls Parrot's recv() This patch gets around this by making recv() take a parameter which -- |
From @carbin0001-Change-IO-Socket.recv-to-accept-a-parameter-speci.patchFrom 34f5c66ba8ea9e9f345c8847d08e58dfb3ca7d7c Mon Sep 17 00:00:00 2001
From: Carlin Bingham <carlin@theintersect.org>
Date: Mon, 26 Oct 2009 11:40:40 +1300
Subject: [PATCH] Change IO::Socket.recv() to accept a parameter specifying the number of bytes which will be received
---
src/setting/IO/Socket.pm | 22 ++++++++++++++--------
1 files changed, 14 insertions(+), 8 deletions(-)
diff --git a/src/setting/IO/Socket.pm b/src/setting/IO/Socket.pm
index 3b175f2..2373b4b 100644
--- a/src/setting/IO/Socket.pm
+++ b/src/setting/IO/Socket.pm
@@ -2,16 +2,22 @@ use v6;
role IO::Socket {
has $!PIO;
+ has $!buffer = '';
- method recv () {
+ method recv (Int $bufsize = Inf) {
fail('Socket not available') unless $!PIO;
- my $received = $!PIO.recv();
- my $len = $received.chars;
- my $buf;
- while $len > 0 {
- $buf = $!PIO.recv();
- $received ~= $buf;
- $len = $buf.chars;
+ my $received;
+ while $bufsize > $!buffer.bytes {
+ $received = $!PIO.recv();
+ last unless $received.chars;
+ $!buffer ~= $received;
+ }
+ if $bufsize == Inf {
+ $received = $!buffer;
+ $!buffer = '';
+ } else {
+ $received = $!buffer.substr(0, $bufsize);
+ $!buffer .= substr($bufsize);
}
return $received;
}
--
1.6.0.4
|
From @moritzApplied as 22ded10cd3f8e9774ca17d5bb8e42bed7efb7938, tests unfudged. Cheers, |
@moritz - Status changed from 'new' to 'resolved' |
Migrated from rt.perl.org#70017 (status was 'resolved')
Searchable as RT70017$
The text was updated successfully, but these errors were encountered: