blob: ea597de3a7fc0cb0a64b806d6824bbd211480017 [file] [log] [blame]
VtConn, vtconn, vtdial, vtfreeconn, vtsend, vtrecv, vtversion,
vtdebug, vthangup \- Venti network connections
.ft L
#include <u.h>
#include <libc.h>
#include <venti.h>
.ft L
.ta +\w'\fL 'u
typedef struct VtConn {
int debug;
char *version;
char *uid;
char *sid;
char addr[256];
} VtConn;
.ta \w'\fLextern int 'u
VtConn* vtconn(int infd, int outfd)
int vtreconn(VtConn *z, int infd, int outfd)
VtConn* vtdial(char *addr)
int vtredial(VtConn *z, char *addr)
int vtversion(VtConn *z)
int vtsend(VtConn *z, Packet *p)
Packet* vtrecv(VtConn *z)
void vtrecvproc(void *z)
void vtsendproc(void *z)
void vtdebug(VtConn *z, char *fmt, ...)
void vthangup(VtConn *z)
void vtfreeconn(VtConn *z)
extern int chattyventi; /* default 0 */
.B VtConn
structure represents a connection to a Venti server
(when used by a client) or to a client (when used by a server).
It contains the following user-visible fields:
.BR debug ,
a flag enabling debugging prints;
.BR version ,
the protocol version in use;
.BR uid ,
the (unverified) name of the client;
.BR sid ,
the (unverified) name of the server;
.BR addr ,
the network address of the remote side.
.I Vtconn
initializes a new connection structure using file descriptors
.I infd
.I outfd
(which may be the same)
for reading and writing.
.I Vtdial
dials the given network address
.IR dial (3))
and returns a corresponding connection.
It returns nil if the connection cannot be established.
.I Vtversion
exchanges version information with the remote side
as described in
.IR venti (7).
The negotiated version is stored in
.IB z ->version \fR.
.I Vtsend
writes a packet
.IR venti-packet (3))
on the connection
.IR z .
The packet
.IR p
should be a formatted Venti message as might
be returned by
.IR vtfcallpack ;
.I vtsend
will add the two-byte length field
.IR venti (7))
at the begnning.
.I Vtsend
.IR p ,
even on error.
.I Vtrecv
reads a packet from the connection
.IR z .
Analogous to
.IR vtsend ,
the data read from the connection must start with
a two-byte length, but the returned packet will omit them.
By default,
.I vtsend
.I vtrecv
block until the packet can be written or read from the network.
In a threaded program
.IR thread (3)),
this may not be desirable.
If the caller arranges for
.IR vtsendproc
.IR vtrecvproc
to run in their own procs
(typically by calling
.IR proccreate ),
.I vtsend
.I vtrecv
will yield the proc in which they are run
to other threads when waiting on the network.
.B void*
argument to
.I vtsendproc
.I vtrecvproc
must be the connection structure
.IR z .
.I Vtdebug
prints the formatted message to standard error
.IB z ->debug
is set. Otherwise it is a no-op.
.I Vthangup
hangs up a connection.
It closes the associated file descriptors
and shuts down send and receive procs if they have been
Future calls to
.IR vtrecv
.IR vtsend
will return errors.
Additional calls to
.I vthangup
will have no effect.
.I Vtfreeconn
frees the connection structure, hanging it up first
if necessary.
If the global variable
.I chattyventi
is set, the library prints all Venti RPCs to standard error
as they are sent or received.
.B \*9/src/libventi
.IR venti (1),
.IR venti (3),
.IR venti-client (3),
.IR venti-packet (3),
.IR venti-server (3),
.IR venti (7)
Routines that return pointers return nil on error.
Routines returning integers return 0 on success, \-1 on error.
All routines set
.I errstr
on error.