Io module

read_full

procedureextensionexperimental4 overloadsSource

Reads until buffer is full. .END_OF_FILE if the peer closed first, with the bytes read.

Example↗
Io :: #import "Extensions/Io";

Io.io_run(() {
    listener, _ := Io.tcp_listen("127.0.0.1:0");
    defer Io.close(listener);

    address, _ := Io.local_address(listener);
    client, _ := Io.connect(address);
    server, _ := Io.accept(listener);
    defer Io.close(client);
    defer Io.close(server);

    Io.write(client, "abcd");

    buffer: [4] u8;
    count, error := Io.read_full(server, buffer);
    assert(error == .NONE && count == 4);
});
read_full :: (stream: Tcp_Stream, buffer: [] u8) -> (s64, Io_Error)

Parameters

stream: Tcp_Stream
buffer: [] u8

Returns

s64
read_full :: (stream: *Pipe_Stream, buffer: [] u8) -> (s64, Io_Error)

Reads until buffer is full; .END_OF_FILE if the other end closed first.

Parameters

stream: *Pipe_Stream
buffer: [] u8

Returns

s64
read_full :: (file: *Io_File, buffer: [] u8) -> (s64, Io_Error)

Reads until buffer is full. .END_OF_FILE if the file ended first, with the bytes read.

Parameters

file: *Io_File
buffer: [] u8

Returns

s64
Example
Io :: #import "Extensions/Io";
#import "File";

Io.io_run(() {
    Io.write_file("/tmp/jacket-io-full.txt", "abc");

    file, _ := Io.open_file("/tmp/jacket-io-full.txt");
    defer Io.close(*file);

    buffer: [8] u8;
    count, error := Io.read_full(*file, buffer);
    assert(error == .END_OF_FILE && count == 3);
});
file_delete("/tmp/jacket-io-full.txt");

Doesn't run in the browser (only on linux, macos).

read_full :: (reader: Reader, buffer: [] u8) -> (s64, Io_Error)

Reads until buffer is full. .END_OF_FILE if the source ended first, with the bytes read.

Parameters

reader: Reader
buffer: [] u8

Returns

s64
Example↗
Io :: #import "Extensions/Io";

Io.io_run(() {
    near, far := Io.make_pipe();
    defer Io.close(near);
    defer Io.close(far);
    Io.write(Io.writer_of(far), "abcdef");
    Io.shutdown_write(far);

    head: [4] u8;
    count, error := Io.read_full(Io.reader_of(near), head);
    assert(error == .NONE && count == 4);

    tail: [4] u8;
    count, error = Io.read_full(Io.reader_of(near), tail);
    assert(error == .END_OF_FILE && count == 2);
});

See also