aboutsummaryrefslogtreecommitdiff
path: root/src/libplumb
diff options
context:
space:
mode:
authorrsc <devnull@localhost>2004-03-21 04:33:13 +0000
committerrsc <devnull@localhost>2004-03-21 04:33:13 +0000
commit2277c5d7bbe1f9595fad512d8f790708473a9bf1 (patch)
tree4d653e13906f1971d3170dba6dbe0fbf92eb48d6 /src/libplumb
parenta770daa795754cb600ad3fab2fdd2961147006c4 (diff)
downloadplan9port-2277c5d7bbe1f9595fad512d8f790708473a9bf1.tar.gz
plan9port-2277c5d7bbe1f9595fad512d8f790708473a9bf1.tar.bz2
plan9port-2277c5d7bbe1f9595fad512d8f790708473a9bf1.zip
Small tweaks
Lots of new code imported.
Diffstat (limited to 'src/libplumb')
-rwxr-xr-xsrc/libplumb/mesg.c62
-rw-r--r--src/libplumb/thread.c1
2 files changed, 53 insertions, 10 deletions
diff --git a/src/libplumb/mesg.c b/src/libplumb/mesg.c
index fd95810b..c4094fa4 100755
--- a/src/libplumb/mesg.c
+++ b/src/libplumb/mesg.c
@@ -13,8 +13,6 @@ static Fid *pfid;
int
plumbopen(char *name, int omode)
{
- int fd;
-
if(fsplumb == nil)
fsplumb = nsmount("plumb", "");
if(fsplumb == nil)
@@ -47,28 +45,44 @@ plumbopen(char *name, int omode)
return pfd;
}
- fd = fsopenfd(fsplumb, name, omode);
- return fd;
+ return fsopenfd(fsplumb, name, omode);
+}
+
+Fid*
+plumbopenfid(char *name, int mode)
+{
+ if(fsplumb == nil)
+ fsplumb = nsmount("plumb", "");
+ if(fsplumb == nil)
+ return nil;
+ return fsopen(fsplumb, name, mode);
}
int
-plumbsend(int fd, Plumbmsg *m)
+plumbsendtofid(Fid *fid, 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);
+ n = fswrite(fid, buf, n);
+fprint(2, "fswrite %d\n", n);
free(buf);
return n;
}
+int
+plumbsend(int fd, Plumbmsg *m)
+{
+ if(fd != pfd){
+ werrstr("fd is not the plumber");
+ return -1;
+ }
+ return plumbsendtofid(pfid, m);
+}
+
static int
Strlen(char *s)
{
@@ -427,3 +441,31 @@ plumbrecv(int fd)
free(buf);
return m;
}
+
+Plumbmsg*
+plumbrecvfid(Fid *fid)
+{
+ char *buf;
+ Plumbmsg *m;
+ int n, more;
+
+ buf = malloc(8192);
+ if(buf == nil)
+ return nil;
+ n = fsread(fid, buf, 8192);
+ m = nil;
+ if(n > 0){
+ m = plumbunpackpartial(buf, n, &more);
+ if(m==nil && more>0){
+ /* we now know how many more bytes to read for complete message */
+ buf = realloc(buf, n+more);
+ if(buf == nil)
+ return nil;
+ if(fsreadn(fid, buf+n, more) == more)
+ m = plumbunpackpartial(buf, n+more, nil);
+ }
+ }
+ free(buf);
+ return m;
+}
+
diff --git a/src/libplumb/thread.c b/src/libplumb/thread.c
index c31fdfb1..5b375257 100644
--- a/src/libplumb/thread.c
+++ b/src/libplumb/thread.c
@@ -31,3 +31,4 @@ threadplumbrecv(int fd)
free(buf);
return m;
}
+