No more values will be sent. Fibers waiting to send get .CLOSED; receivers get what is
buffered, then .CLOSED.
Io :: #import "Extensions/Io";
Io.io_run(() {
channel := Io.make_channel(int, 2);
defer Io.free_channel(channel);
Io.send(channel, 1);
Io.close(channel);
value, error := Io.recv(channel); // what was buffered still arrives
assert(error == .NONE && value == 1);
_, error = Io.recv(channel);
assert(error == .CLOSED);
});close :: (channel: *Channel($T))
Parameters
- channel: *Channel($T)
close :: (stream: Tcp_Stream, now := false) -> Io_Error
Closes the socket. Fibers still waiting on it return .CLOSED. Works for a canceled fiber too,
so defer close(conn) always cleans up. With now it closes at once without waiting, for code
that cannot block: a Local_Drop, or a fiber that must not give up its turn. Fibers still
waiting on the socket are not woken, so use the plain call unless the scheduler is ending.
Parameters
- stream: Tcp_Stream
- now := false
Returns
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);
assert(Io.close(client) == .NONE);
});close :: (listener: Tcp_Listener, now := false) -> Io_Error
Closes the listening socket. A fiber waiting in accept on it returns .CLOSED. The listener must not be used afterwards.
With now it closes at once without waiting and without waking such fibers; use it only where the code cannot block.
Parameters
- listener: Tcp_Listener
- now := false
Returns
close :: (stream: *Pipe_Stream, now := false) -> Io_Error
Closes this end: the other end reads what was already sent and then 0, writes to it fail, and
a fiber waiting in read on this end returns .CLOSED. Close each end once: the memory of both
goes when the second one is closed.
Parameters
- stream: *Pipe_Stream
- now := false
Returns
close :: (file: *Io_File, now := false) -> Io_Error
Closes the file. With now, without going through the engine (see close for a reader).
Parameters
- file: *Io_File
- now := false
Returns
Io :: #import "Extensions/Io";
#import "File";
Io.io_run(() {
file, _ := Io.open_file("/tmp/jacket-io-close.txt", .WRITE);
assert(Io.close(*file) == .NONE);
});
file_delete("/tmp/jacket-io-close.txt");Doesn't run in the browser (only on linux, macos).
close :: (reader: Reader, now := false) -> Io_Error
Closes the source behind a reader. With now, nothing waits: use it where the code cannot
block (a Local_Drop); fibers still waiting on the source are not woken, so prefer the plain
call unless the scheduler is ending.
Parameters
- reader: Reader
- now := false
Returns
Io :: #import "Extensions/Io";
Io.io_run(() {
near, far := Io.make_pipe();
Io.close(Io.reader_of(near));
Io.close(far);
});close :: (writer: Writer, now := false) -> Io_Error
Closes the sink behind a writer. A TCP stream or pipe end has a reader and a writer over one connection, so close only one of them.
Parameters
- writer: Writer
- now := false