Charles.Forsyth20060303-partialeea662d19 years agoHistory
158 lines · 3.0 KB · Text
RawDownload
.TH SYS-FILE2CHAN 2.SH NAMEfile2chan \- create file connected to Limbo channel.SH SYNOPSIS.EXinclude "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): ref FileIO;.EE.fi.SH DESCRIPTION.B File2chanpresents an interface for binding Limbo channels to files in the file name space.A.I serverprogram calls.B file2chanto create a.I filein a directory.IR dir ,which must be a directory on which device.RB ` #s 'has been bound(see.IR srv (3)).A.I clientprogram can open the file for reading or writing (see.IR sys-open (2)and.IR sys-read (2))to communicate with the server..PP.B File2chanreturns a.B FileIOtype holding two channels used to deliver tuples representingthe contents of the.B Treadand.B TwriteStyx messages received by the system on the server's behalf; see.IR intro (5)..PPWhen the client invokes the.B readsystem call on the file, the serverreceives a tuple, say.BI ( offset\fP,\fP\ count\fP,\fP\ fid\fP,\fP\ rc )\f1,on the.B readchannel.The request asks for.I countbytes of data, starting at.I offsetbytes from the beginning of the fileassociated with.IR fid .The server sends its reply to the client by transmitting a tuple, say.BI ( data\fP,\fP\ error )\f1,that contains the.I datafor the.BR read ,on the channel.I rcreceived as part of the.B readtuple.If the request was successful, the.I errorstring should be.BR nil .If an error occurred,.I errorshould be a diagnostic string,and the.I dataarray should be.BR nil .The client blocks in the.B readsystem call until the server sends its reply.The client receives only.I countbytes even if.I datais larger..PPWhen the client does a.B writesystem call on the file,the server receives a tuple,.BI ( offset\fP,\fP\ data\fP,\fP\ fid\fP,\fP\ wc )\f1,on the.B writechannel.A.BI ( count\fP,\fP\ error )response is sent back on the.I wcchannel received in the.B writetuple:.I countgives the number of bytes written (zero if an error occurs), and.I erroris an empty or.B nilstring or an explanation of the problem..PPIf the client closes the file for reading (writing), the server will receive a.B read.RB ( write )message with a.B nil.I rc.BI ( wc )\f1.The server can use these signals to determine when to stop processing.The.I fidreceived by the server can be used to manage the multiplexing of multipleactive clients sharing a single file; see.IR intro (5)for details..SH SOURCE.B /emu/port/devsrv.c.br.B /os/port/devsrv.c.SH SEE ALSO.IR sh-file2chan (1),.IR sys-intro (2),.IR sys-open (2),.IR sys-read (2),.IR sys-bind (2),.IR intro (5).SH BUGS.B Readand.B writesystem calls for the file will not return until theserver sends its reply on the appropriate channel,so the process doing the.B reador.B writecannot be the one serving.