diff options
author | rsc <devnull@localhost> | 2003-12-17 04:34:52 +0000 |
---|---|---|
committer | rsc <devnull@localhost> | 2003-12-17 04:34:52 +0000 |
commit | 49588d5d9089589ccda28c41aae90c29d6f72787 (patch) | |
tree | 48cbc911e34b71977b7b98b4d0b94b27d4454081 /src/libplumb | |
parent | 7f11104a5737adf261d10bc1a7b85e740f2eb491 (diff) | |
download | plan9port-49588d5d9089589ccda28c41aae90c29d6f72787.tar.gz plan9port-49588d5d9089589ccda28c41aae90c29d6f72787.tar.bz2 plan9port-49588d5d9089589ccda28c41aae90c29d6f72787.zip |
Tweaks to various bits.
Until I hear otherwise, Refs aren't used enough to
merit their own assembly. They are now implemented with locks.
Diffstat (limited to 'src/libplumb')
-rwxr-xr-x | src/libplumb/mesg.c | 73 |
1 files changed, 53 insertions, 20 deletions
diff --git a/src/libplumb/mesg.c b/src/libplumb/mesg.c index fcade7f4..fd95810b 100755 --- a/src/libplumb/mesg.c +++ b/src/libplumb/mesg.c @@ -7,21 +7,68 @@ static char attrbuf[4096]; char *home; - +static Fsys *fsplumb; +static int pfd = -1; +static Fid *pfid; int plumbopen(char *name, int omode) { - Fsys *fs; int fd; - fs = nsmount("plumb", ""); - if(fs == nil) + if(fsplumb == nil) + fsplumb = nsmount("plumb", ""); + if(fsplumb == nil) return -1; - fd = fsopenfd(fs, name, omode); - fsunmount(fs); + /* + * It's important that when we send something, + * we find out whether it was a valid plumb write. + * (If it isn't, the client might fall back to some + * other mechanism or indicate to the user what happened.) + * We can't use a pipe for this, so we have to use the + * fid interface. But we need to return a fd. + * Return a fd for /dev/null so that we return a unique + * file descriptor. In plumbsend we'll look for pfd + * and use the recorded fid instead. + */ + if((omode&3) == OWRITE){ + if(pfd != -1){ + werrstr("already have plumb send open"); + return -1; + } + pfd = open("/dev/null", OWRITE); + if(pfd < 0) + return -1; + pfid = fsopen(fsplumb, name, omode); + if(pfid == nil){ + close(pfd); + pfd = -1; + return -1; + } + return pfd; + } + + fd = fsopenfd(fsplumb, name, omode); return fd; } +int +plumbsend(int fd, Plumbmsg *m) +{ + char *buf; + int n; + + if(fd != pfd){ + werrstr("fd is not the plumber"); + return -1; + } + buf = plumbpack(m, &n); + if(buf == nil) + return -1; + n = fswrite(pfid, buf, n); + free(buf); + return n; +} + static int Strlen(char *s) { @@ -144,20 +191,6 @@ plumbpack(Plumbmsg *m, int *np) return buf; } -int -plumbsend(int fd, Plumbmsg *m) -{ - char *buf; - int n; - - buf = plumbpack(m, &n); - if(buf == nil) - return -1; - n = write(fd, buf, n); - free(buf); - return n; -} - static int plumbline(char **linep, char *buf, int i, int n, int *bad) { |