Blob


1 .TH PLUMB 3
2 .SH NAME
3 eplumb, plumbfree, plumbopen, plumbopenfid, plumbsend, plumbsendtofid, plumbsendtext, plumblookup, plumbpack, plumbpackattr, plumbaddattr, plumbdelattr, plumbrecv, plumbrecvfid, plumbunpack, plumbunpackpartial, plumbunpackattr, Plumbmsg \- plumb messages
4 .SH SYNOPSIS
5 .B #include <u.h>
6 .br
7 .B #include <libc.h>
8 .br
9 .B #include <plumb.h>
10 .PP
11 .ta \w'\fLPlumbattr* 'u
12 .PP
13 .B
14 int plumbopen(char *port, int omode)
15 .PP
16 .B
17 int plumbsend(int fd, Plumbmsg *m)
18 .PP
19 .B
20 int plumbsendtext(int fd, char *src, char *dst, char *wdir, char *data)
21 .PP
22 .B
23 void plumbfree(Plumbmsg *m)
24 .PP
25 .B
26 Plumbmsg* plumbrecv(int fd)
27 .PP
28 .B
29 char* plumbpack(Plumbmsg *m, int *np)
30 .PP
31 .B
32 Plumbmsg* plumbunpack(char *buf, int n)
33 .PP
34 .B
35 Plumbmsg* plumbunpackpartial(char *buf, int n, int *morep)
36 .PP
37 .B
38 char* plumbpackattr(Plumbattr *a)
39 .PP
40 .B
41 Plumbattr* plumbunpackattr(char *a)
42 .PP
43 .B
44 char* plumblookup(Plumbattr *a, char *name)
45 .PP
46 .B
47 Plumbattr* plumbaddattr(Plumbattr *a, Plumbattr *new)
48 .PP
49 .B
50 Plumbattr* plumbdelattr(Plumbattra *a, char *name)
51 .PP
52 .B
53 int eplumb(int key, char *port)
54 .PP
55 .B
56 #include <9pclient.h>
57 .PP
58 .B
59 CFid *plumbopenfid(char *port, int omode)
60 .PP
61 .B
62 Plumbmsg* plumbrecvfid(CFid *fid)
63 .PP
64 .B
65 int plumbsendtofid(CFid *fid, Plumbmsg *m)
66 .SH DESCRIPTION
67 These routines manipulate
68 .IR plumb (7)
69 messages, transmitting them, receiving them, and
70 converting them between text and these data structures:
71 .IP
72 .EX
73 .ta 6n +\w'\fLPlumbattr 'u +\w'ndata; 'u
74 typedef
75 struct Plumbmsg
76 {
77 char *src;
78 char *dst;
79 char *wdir;
80 char *type;
81 Plumbattr *attr;
82 int ndata;
83 char *data;
84 } Plumbmsg;
86 typedef
87 struct Plumbattr
88 {
89 char *name;
90 char *value;
91 Plumbattr *next;
92 } Plumbattr;
93 .EE
94 .PP
95 .I Plumbopen
96 opens the named plumb
97 .IR port ,
98 using
99 .IR open (3)
100 mode
101 .IR omode .
102 If
103 .I port
104 begins with a slash, it is taken as a literal file name;
105 otherwise
106 .I plumbopen
107 searches for the location of the
108 .IR plumber (4)
109 service and opens the port there.
110 .PP
111 For programs using the
112 .IR event (3)
113 interface,
114 .I eplumb
115 registers, using the given
116 .IR key ,
117 receipt of messages from the named
118 .IR port .
119 .PP
120 .I Plumbsend
121 formats and writes message
122 .I m
123 to the file descriptor
124 .IR fd ,
125 which will usually be the result of
126 .B plumbopen("send",
127 .BR OWRITE) .
128 .I Plumbsendtext
129 is a simplified version for text-only messages; it assumes
130 .B type
131 is
132 .BR text ,
133 sets
134 .B attr
135 to nil,
136 and sets
137 .B ndata
138 to
139 .BI strlen( data )\f1.
140 .PP
141 .I Plumbfree
142 frees all the data associated with the message
143 .IR m ,
144 all the components of which must therefore have been allocated with
145 .IR malloc (3).
146 .PP
147 .I Plumbrecv
148 returns the next message available on the file descriptor
149 .IR fd ,
150 or nil for error.
151 .PP
152 .I Plumbpack
153 encodes message
154 .I m
155 as a character string in the format of
156 .IR plumb (7) ,
157 setting
158 .BI * np
159 to the length in bytes of the string.
160 .I Plumbunpack
161 does the inverse, translating the
162 .I n
163 bytes of
164 .I buf
165 into a
166 .BR Plumbmsg .
167 .PP
168 .I Plumbunpackpartial
169 enables unpacking of messages that arrive in pieces.
170 The first call to
171 .I plumbunpackpartial
172 for a given message must be sufficient to unpack the header;
173 subsequent calls permit unpacking messages with long data sections.
174 For each call,
175 .I buf
176 points to the beginning of the complete message received so far, and
177 .I n
178 reports the total number of bytes received for that message.
179 If the message is complete, the return value will be as in
180 .IR plumbunpack .
181 If not, and
182 .I morep
183 is not null, the return value will be
184 .B nil
185 and
186 .BR * morep
187 will be set to the number of bytes remaining to be read for this message to be complete
188 (recall that the byte count is in the header).
189 Those bytes should be read by the caller, placed at location
190 .IB buf + n \f1,
191 and the message unpacked again.
192 If an error is encountered, the return value will be
193 .B nil
194 and
195 .BI * morep
196 will be zero.
197 .PP
198 .I Plumbpackattr
199 converts the list
200 .I a
201 of
202 .B Plumbattr
203 structures into a null-terminated string.
204 If an attribute value contains white space, quote characters, or equal signs,
205 the value will be quoted appropriately.
206 A newline character will terminate processing.
207 .I Plumbunpackattr
208 converts the null-terminated string
209 .I a
210 back into a list of
211 .I Plumbattr
212 structures.
213 .PP
214 .I Plumblookup
215 searches the
216 .B Plumbattr
217 list
218 .I a
219 for an attribute with the given
220 .I name
221 and returns the associated value.
222 The returned string is the original value, not a copy.
223 If the attribute has no value, the returned value will be the empty string;
224 if the attribute does not occur in the list at all, the value will be nil.
225 .PP
226 .I Plumbaddattr
227 appends the
228 .I new
229 .B Plumbattr
230 (which may be a list) to the attribute list
231 .IR a
232 and returns the new list.
233 .I Plumbattr
234 searches the list
235 .I a
236 for the first attribute with name
237 .I name
238 and deletes it from the list, returning the resulting list.
239 .I Plumbdelattr
240 is a no-op if no such attribute exists.
241 .PP
242 The file descriptor returned by
243 .I plumbopen
244 is created with
245 .I fsopenfd
246 (see
247 .IR 9pclient (3)),
248 which masks information about read and write errors.
249 This is acceptable for use in
250 .I plumbrecv
251 but not for
252 .IR plumbsend ,
253 which depends on seeing details of write errors.
254 .IR Plumbopenfid ,
255 .IR plumbrecvfid ,
256 and
257 .IR plumbsendtofid
258 provide an explicit interface to
259 .I lib9pclient
260 that preserves the exact error details.
261 .SH SOURCE
262 .B \*9/src/libplumb
263 .SH SEE ALSO
264 .IR plumb (1),
265 .IR event (3),
266 .IR plumber (4),
267 .IR plumb (7)
268 .SH DIAGNOSTICS
269 When appropriate, including when a
270 .I plumbsend
271 fails, these routine set
272 .IR errstr .
273 .SH BUGS
274 To avoid rewriting clients that use
275 .IR plumbsend ,
276 the call
277 .B plumbopen("send",
278 .B OWRITE)
279 returns a useless file descriptor
280 (it is opened to
281 .BR /dev/null ).
282 .I Plumbsend
283 looks for this particular file descriptor
284 and uses a static copy of the
285 .B CFid
286 instead.