venti-conn 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. .TH VENTI-CONN 2
  2. .SH NAME
  3. VtConn, vtconn, vtdial, vtfreeconn, vtsend, vtrecv, vtversion,
  4. vtdebug, vthangup \- Venti network connections
  5. .SH SYNOPSIS
  6. .PP
  7. .ft L
  8. #include <u.h>
  9. .br
  10. #include <libc.h>
  11. .br
  12. #include <venti.h>
  13. .PP
  14. .ft L
  15. .nf
  16. .ta +\w'\fL 'u
  17. typedef struct VtConn {
  18. int debug;
  19. char *version;
  20. char *uid;
  21. char *sid;
  22. char addr[256];
  23. ...
  24. } VtConn;
  25. .PP
  26. .ta \w'\fLextern int 'u
  27. .B
  28. VtConn* vtconn(int infd, int outfd)
  29. .PP
  30. .B
  31. VtConn* vtdial(char *addr)
  32. .PP
  33. .B
  34. int vtversion(VtConn *z)
  35. .PP
  36. .B
  37. int vtsend(VtConn *z, Packet *p)
  38. .PP
  39. .B
  40. Packet* vtrecv(VtConn *z)
  41. .PP
  42. .B
  43. void vtrecvproc(void *z)
  44. .PP
  45. .B
  46. void vtsendproc(void *z)
  47. .PP
  48. .B
  49. void vtdebug(VtConn *z, char *fmt, ...)
  50. .PP
  51. .B
  52. void vthangup(VtConn *z)
  53. .PP
  54. .B
  55. void vtfreeconn(VtConn *z)
  56. .PP
  57. .B
  58. extern int chattyventi; /* default 0 */
  59. .SH DESCRIPTION
  60. A
  61. .B VtConn
  62. structure represents a connection to a Venti server
  63. (when used by a client) or to a client (when used by a server).
  64. It contains the following user-visible fields:
  65. .BR debug ,
  66. a flag enabling debugging prints;
  67. .BR version ,
  68. the protocol version in use;
  69. .BR uid ,
  70. the (unverified) name of the client;
  71. .BR sid ,
  72. the (unverified) name of the server;
  73. and
  74. .BR addr ,
  75. the network address of the remote side.
  76. .PP
  77. .I Vtconn
  78. initializes a new connection structure using file descriptors
  79. .I infd
  80. and
  81. .I outfd
  82. (which may be the same)
  83. for reading and writing.
  84. .I Vtdial
  85. dials the given network address
  86. (see
  87. .IR dial (2))
  88. and returns a corresponding connection.
  89. It returns nil if the connection cannot be established.
  90. .PP
  91. .I Vtversion
  92. exchanges version information with the remote side
  93. as described in
  94. .IR venti (6).
  95. The negotiated version is stored in
  96. .IB z ->version \fR.
  97. .PP
  98. .I Vtsend
  99. writes a packet
  100. (see
  101. .IR venti-packet (2))
  102. on the connection
  103. .IR z .
  104. The packet
  105. .IR p
  106. should be a formatted Venti message as might
  107. be returned by
  108. .IR vtfcallpack ;
  109. .I vtsend
  110. will add the two-byte length field
  111. (see
  112. .IR venti (6))
  113. at the begnning.
  114. .I Vtsend
  115. frees
  116. .IR p ,
  117. even on error.
  118. .PP
  119. .I Vtrecv
  120. reads a packet from the connection
  121. .IR z .
  122. Analogous to
  123. .IR vtsend ,
  124. the data read from the connection must start with
  125. a two-byte length, but the returned packet will omit them.
  126. .PP
  127. By default,
  128. .I vtsend
  129. and
  130. .I vtrecv
  131. block until the packet can be written or read from the network.
  132. In a threaded program
  133. (see
  134. .IR thread (2)),
  135. this may not be desirable.
  136. If the caller arranges for
  137. .IR vtsendproc
  138. and
  139. .IR vtrecvproc
  140. to run in their own procs
  141. (typically by calling
  142. .IR proccreate ),
  143. then
  144. .I vtsend
  145. and
  146. .I vtrecv
  147. will yield the proc in which they are run
  148. to other threads when waiting on the network.
  149. The
  150. .B void*
  151. argument to
  152. .I vtsendproc
  153. and
  154. .I vtrecvproc
  155. must be the connection structure
  156. .IR z .
  157. .PP
  158. .I Vtdebug
  159. prints the formatted message to standard error
  160. when
  161. .IB z ->debug
  162. is set. Otherwise it is a no-op.
  163. .PP
  164. .I Vthangup
  165. hangs up a connection.
  166. It closes the associated file descriptors
  167. and shuts down send and receive procs if they have been
  168. started.
  169. Future calls to
  170. .IR vtrecv
  171. or
  172. .IR vtsend
  173. will return errors.
  174. Additional calls to
  175. .I vthangup
  176. will have no effect.
  177. .PP
  178. .I Vtfreeconn
  179. frees the connection structure, hanging it up first
  180. if necessary.
  181. .PP
  182. If the global variable
  183. .I chattyventi
  184. is set, the library prints all Venti RPCs to standard error
  185. as they are sent or received.
  186. .SH SOURCE
  187. .B /sys/src/libventi
  188. .SH SEE ALSO
  189. .IR venti (1),
  190. .IR venti (2),
  191. .IR venti-client (2),
  192. .IR venti-packet (2),
  193. .IR venti-server (2),
  194. .IR venti (6)
  195. .SH DIAGNOSTICS
  196. Routines that return pointers return nil on error.
  197. Routines returning integers return 0 on success, \-1 on error.
  198. All routines set
  199. .I errstr
  200. on error.