Skip to content

Commit

Permalink
proper try to get the string as utf8
Browse files Browse the repository at this point in the history
If the recieved data cant be decoded to utf8 it will stay
a binary bytestream. This allows one to recv utf8-strings
and/or binary data.
  • Loading branch information
FROGGS committed Jan 12, 2013
1 parent 2d844dd commit 1c35c39
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/core/IO/Socket.pm
Expand Up @@ -7,8 +7,11 @@ my role IO::Socket {

if $!buffer.chars < $chars {
my str $r = $!PIO.recv;
$r = pir::trans_encoding__Ssi($r,
pir::find_encoding__Is('utf8'));
try {
my Mu $bb := pir::new__Ps('ByteBuffer');
pir::set__vPs($bb, $r);
$r = $bb.get_string(PARROT_ENCODING('utf8'));
}
$!buffer ~= nqp::p6box_s($r);
}

Expand Down

0 comments on commit 1c35c39

Please sign in to comment.