~ubuntu-branches/ubuntu/precise/rakudo/precise

« back to all changes in this revision

Viewing changes to src/setting/IO/Socket.pm

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghedini
  • Date: 2011-05-17 11:31:09 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20110517113109-rmfir654u1axbpt4
Tags: 0.1~2011.04-1
* New upstream release (Closes: #601862, #585762, #577502)
* New maintainer
* Switch to 3.0 (quilt) format
* Update dependencies (Closes: #584498)
* Update debian/copyright to lastest DEP5 revision
* Do not generate/install perl6 manpage (now done by the build system)
* Enable tests
* Bump Standards-Version to 3.9.2 (no changes needed)
* Do not install extra LICENSE files and duplicated docs
* Remove debian/clean (no more needed)
* Add Vcs-* fields in debian/control
* Rewrite (short) description
* Update upstream copyright years
* Upload to unstable

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
use v6;
2
 
 
3
 
role IO::Socket {
4
 
    has $!PIO;
5
 
    has $!buffer = '';
6
 
 
7
 
    method recv (Int $bufsize = Inf) {
8
 
        fail('Socket not available') unless $!PIO;
9
 
        my $received;
10
 
        while $bufsize > $!buffer.bytes {
11
 
            $received = $!PIO.recv();
12
 
            last unless $received.chars;
13
 
            $!buffer ~= $received;
14
 
        }
15
 
        if $bufsize == Inf {
16
 
            $received = $!buffer;
17
 
            $!buffer = '';
18
 
        } else {
19
 
            $received = $!buffer.substr(0, $bufsize);
20
 
            $!buffer .= substr($bufsize);
21
 
        }
22
 
        return $received;
23
 
    }
24
 
 
25
 
    method send (Str $string) {
26
 
        fail("Not connected") unless $!PIO;
27
 
        return $!PIO.send($string);
28
 
    }
29
 
 
30
 
    method close () {
31
 
        fail("Not connected!") unless $!PIO;
32
 
        return $!PIO.close();
33
 
    }
34
 
}