Net.Memory
Connections that never leave the program: two ends of a Pipe, each a
Net.Connection as a TCP socket is, and a Listener that hands out the
far end of each connect. For testing a server or a protocol without a
socket, a port, or a network.
let l = Memory.listener(65536)
let client = Memory.connect(l)?
let server = accept(l)?
As a TCP connection behaves, within one program:
- Each direction holds at most the capacity it was made with. A write that does not fit waits for the peer to read, so a peer that stops reading stalls a writer, as a full socket buffer does.
- A read waits for bytes, and returns 0 once the peer has shut down its writing or closed its end and every byte before that has been read.
- A write after the peer closed its end, or after this end shut down its
writing, fails with
BrokenPipe. closeends every read and write parked on this end, in any task, withClosed, as it does every later one.- A deadline bounds every read and write from when it is set, and
setLimits'eacheach one from when it begins; one that passes isTimedOut.
Waiting suspends the task, as waiting on a socket does, so the far end may be served by another task of the same program.
One end of an in-memory connection. End 0 reads flow 0 and writes flow 1; end 1 the other way round.
Returns the two ends of a new connection, each direction holding at most
capacity bytes. Panics if capacity is below 1.
Where connect leaves the far end of each connection for accept.
Returns a listener whose connections hold at most capacity bytes in
each direction. Panics if capacity is below 1.
Returns the near end of a new connection to l, whose far end the next
accept returns. Fails with Closed once l is closed. Never waits.
A pipe has no addresses, and no TLS.
A deadline set on one end bounds that end's waits only.
The far end of the oldest connect not yet accepted, waiting for one if
there is none. Closing l ends the wait with Closed.