venti-conn 3.7 KB

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