forsyth20121205-174063a80cc13 years agoHistory
247 lines · 4.8 KB · Text
RawDownload
.TH SYS-DIAL 2.SH NAMEannounce, dial, listen \- make network connections.SH SYNOPSIS.EXinclude "sys.m";sys := load Sys Sys->PATH; Connection: adt{    dfd:  ref FD;  # data file    cfd:  ref FD;  # control file    dir:  string;  # pathname of line directory}; announce: fn(addr: string):           (int, Connection);dial:     fn(addr, local: string):    (int, Connection);listen:   fn(c: Connection):          (int, Connection);.EE.SH DESCRIPTIONThese routines establish network connections.Their description uses the following definitions:.TF network.PD.TP.I addris a network address in one of the following forms:.br.IP.IB network ! netaddr ! service\f1.br.IB network ! netaddr\f1.br.IR netaddr.TP.I networkAny directory listed in.B /net(eg,.BR tcp ),or the special token,.BR net .The name.B netacts as a free variable that stands for any network in commonbetween the source and.IR netaddr .A network name can be preceded by the full path name of a directoryof networks, using the form.I /dir/network(eg,.BR /net.alt/tcp )..TP.I netaddrA host name, a domain name, a network address,or a meta-name of the form.BI $ attribute\f1,whichis replaced by.I valuefrom the corresponding attribute-value pairin the connection server data base (see.IR db (6))..PPThe functions.B dialand.B announcetranslate a given.I addrto an actual network address usingthe connection server.IR cs (8).If a logical name.I addrcorresponds to several network addresses,for instance if a destination machine has several interfaces,.I cswill return them all.In particular, if.I addris.BR net ,.I cswill return addresses onall networks that are common to source and destination.The translation procedure accesses.I csusing its interface file.BR cs ,which is sought as follows:first, in an explicit directory.BI / dirif one was given in.IR network ;second, in the standard directory.BR /net ;and finally in the directory.BR /net.alt.RB ( dialonly).If the connection server cannot be found,the.I addris used as-is..PPIf a connection attempt is successful, the.B dirmember of the resulting.B Connectionwill bethe path name of a.I line directorythat has files for accessing the connection.One line directory exists for each possible connection.The.B datafile in the line directory is opened tomake a connection, and read and written to communicate with the destination.The.B ctlfile in the line directory can be used to send commands to the line.See.IR ip (3)for messages that can be written to the.B ctlfile.The last close of the.B dataor.B ctlfile will close the connection.The.B remotefile in the line directory contains the address called; the file.B localcontains the local address assigned..PPThe.B dialroutinemakes a call to destination.I addron a multiplexed network.If the connection server returns several addresses,.B dialtries each in turn, until a connection is madeor no addresses remain to be tried.It returns a.B Connectioncontaining a file descriptor.B dfdopen for reading and writing the.B datafile in the line directory,and a file descriptor.B cfdopen for reading and writing the.B ctlfile.If.IR localis non-empty, andthe network allows the local address to be set,as is the case with UDP and TCP port numbers,the local address will be set to.IR local ..PP.B Announceand.B listenare the complements of.BR dial ..B Announceestablishes a network name to which incoming calls can be made.In.IR addr ,.I netaddrgives the name or address of one of the local host's interfaces on which to listen forcalls to the given.IR service ;it can be.B *to listen for calls on any interface on.IR network ..B Announcereturns a.B Connectionstructure in which only the.B cfddescriptor is open, on the control file representing the announcement..B Listentakes as its only argument the.B Connectionstructure of a successful call to.BR announce .When a call is received,.B listenreturns an open.B Connectionstructure as if from.BR dial ,except that only the.B cfddescriptor is open,.B dfdis nil,and the caller must open the data file for itself..SH EXAMPLES.PPMake a call and return an open file descriptor touse for communications:.IP.EXcallkremvax(): (int, Connection){	return sys->dial("tcp!kremvax!80", nil);}.EE.PPCall the local certificate signer:.IP.EXdialsigner(service: string): (int, Connection){	return sys->dial("net!$SIGNER!inflogin", nil);}.EE.SH SOURCE.B /emu/port/inferno.c.br.B /emu/port/dial.c.br.B /os/port/inferno.c.br.B /os/port/dial.c.SH DIAGNOSTICSThe integer valued functions return 0 on success and -1 on error;the system error string is set.The integer component of the tuple returned by the other functionsfollows the same convention..SH BUGSNote that.B listendoes not open the.B datafile.