include "sys.m"; sys:= load Sys Sys->PATH; Rread: type chan of (array of byte, string); Rwrite: type chan of (int, string); FileIO: adt { read: chan of (int, int, int, Rread); write: chan of (int, array of byte, int, Rwrite); }; file2chan: fn(dir, file: string, flags: int): ref FileIO;
Although the interface is couched in file semantics, the goal need not be the creation a server to replicate the duties of existing file systems (e.g., persistent storage of data). The server can be designed to provide new services.
Reads
When the client invokes the read system call on the file, the server receives a tuple, (offset, count, fid, rc), on the read channel of returned ref FileIO. The server should interpret that as a request as follows:
To allow the client to complete its read request successfully, the server should respond by sending into rc a tuple, (data, nil), where data satisfies the client's request.
The client blocks in its read system call until the server sends its reply.
Writes
When the client does a write system call on the file, the server receives a tuple, (offset, data, fid, wc), on the write channel of the returned ref FileIO. That request should be interpreted as follows:
The server should respond with a tuple (count, string) on wc, the channel received in the tuple from the write channel. To indicate a successful write operation to the client the server's response should be (count, nil), where count is the number of bytes (i.e., len data) received from the client.
The client blocks in its write system call until the server sends its reply.
Closes
When file is closed for reading (writing), the server will receive a read (write) message with a nil rc (wc). The server can use these events to determine when to stop processing for a given fid. Fid's
The fid received by the server can be used to manage the multiplexing of multiple active clients sharing a single file. See Limbo Modules for details.
See Also
Limbo System Modules, bind, open, read, print, and Limbo Modules
Caveat
The read and write system calls for the file will not return until the server sends it reply on the appropriate channel; consequently, the process doing the read or write should not be the one serving, lest it deadlock.