12 plumbopen(char *name, int omode)
15 fsplumb = nsmount("plumb", "");
19 * It's important that when we send something,
20 * we find out whether it was a valid plumb write.
21 * (If it isn't, the client might fall back to some
22 * other mechanism or indicate to the user what happened.)
23 * We can't use a pipe for this, so we have to use the
24 * fid interface. But we need to return a fd.
25 * Return a fd for /dev/null so that we return a unique
26 * file descriptor. In plumbsend we'll look for pfd
27 * and use the recorded fid instead.
29 if((omode&3) == OWRITE){
31 werrstr("already have plumb send open");
34 pfd = open("/dev/null", OWRITE);
37 pfid = fsopen(fsplumb, name, omode);
46 return fsopenfd(fsplumb, name, omode);
50 plumbopenfid(char *name, int mode)
53 fsplumb = nsmount("plumb", "");
55 werrstr("mount plumb: %r");
59 return fsopen(fsplumb, name, mode);
63 plumbsendtofid(CFid *fid, Plumbmsg *m)
69 werrstr("invalid fid");
72 buf = plumbpack(m, &n);
75 n = fswrite(fid, buf, n);
81 plumbsend(int fd, Plumbmsg *m)
84 werrstr("invalid fd");
88 werrstr("fd is not the plumber");
91 return plumbsendtofid(pfid, m);
104 n = read(fd, buf, 8192);
107 m = plumbunpackpartial(buf, n, &more);
108 if(m==nil && more>0){
109 /* we now know how many more bytes to read for complete message */
110 buf = realloc(buf, n+more);
113 if(readn(fd, buf+n, more) == more)
114 m = plumbunpackpartial(buf, n+more, nil);
122 plumbrecvfid(CFid *fid)
131 n = fsread(fid, buf, 8192);
134 m = plumbunpackpartial(buf, n, &more);
135 if(m==nil && more>0){
136 /* we now know how many more bytes to read for complete message */
137 buf = realloc(buf, n+more);
140 if(fsreadn(fid, buf+n, more) == more)
141 m = plumbunpackpartial(buf, n+more, nil);