Net.Memory

lib/Net/Memory.gob

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:

Waiting suspends the task, as waiting on a socket does, so the far end may be served by another task of the same program.

type Pipe

One end of an in-memory connection. End 0 reads flow 0 and writes flow 1; end 1 the other way round.

fun pair : fun(Int) -> (Pipe, Pipe)

Returns the two ends of a new connection, each direction holding at most capacity bytes. Panics if capacity is below 1.

type Listener

Where connect leaves the far end of each connection for accept.

fun listener : fun(Int) -> Net.Memory.Listener

Returns a listener whose connections hold at most capacity bytes in each direction. Panics if capacity is below 1.

fun connect : fun(Net.Memory.Listener) -> Either IOError Pipe

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.

instance Read Pipe
instance Write Pipe
instance HasConnectionInfo Pipe

A pipe has no addresses, and no TLS.

instance Connection Pipe

A deadline set on one end bounds that end's waits only.

instance Listener Net.Memory.Listener

The far end of the oldest connect not yet accepted, waiting for one if there is none. Closing l ends the wait with Closed.

accept : [Listener l] fun(l) -> Either IOError (Accepted l) -- from Net.accept
closeListener : [Listener l] fun(l) -> Either IOError Unit -- from Net.closeListener