# New Ticket Created by  "Tokuhiro Matsuno" 
# Please include the string:  [perl #126315]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org/Ticket/Display.html?id=126315 >


When I'm implementing a http client, I need to read 1 packet data without 
expecting size. In socket programming context, this case  is generic 
requirement.

In rakudo's src/core/IO/Socket.pm. It calls nqp::readfh.

    method recv (Cool $chars = Inf, :$bin? = False) {
        fail('Socket not available') unless $!PIO;
        if $bin {
            nqp::readfh($!PIO, nqp::decont(buf8.new),
                $chars == Inf ?? 1048576 !! $chars.Int);
        }
        else {
            nqp::p6box_s(nqp::readcharsfh($!PIO,
                $chars == Inf ?? 1048576 !! $chars.Int));
        }
     }

It's mapped to read_fhb on MoarVM.

      QAST::MASTOperations.add_core_moarop_mapping('readfh', 'read_fhb', 1);

see src/vm/moar/QAST/QASTOperationsMAST.nqp.

And then, it calls  MVM_io_syncstream_read_bytes(scrc/io/syncstream.c). If 
there's no enough bytes in the buffer, MoarVM calls  read_to_buffer, that calls 
uv_read_start -> uv_read_stop async. Main thread goes to 
MVM_string_decodestream_bytes_to_buf(src/strings/decode_stream.c). It will do a 
busy loop to read bytes to buffering the requested bytes.

I request to implement a way to read 1 packet.

Reply via email to