diff options
author | rsc <devnull@localhost> | 2004-02-29 23:11:52 +0000 |
---|---|---|
committer | rsc <devnull@localhost> | 2004-02-29 23:11:52 +0000 |
commit | c3a72d77dc9e59e2498d68692feb098bf565e119 (patch) | |
tree | 93f59cc539a42dfcc469dbaf49958e8716f56da9 /src/libplumb | |
parent | e04d5bee6949d103a588659ee155f13f755cc2e2 (diff) | |
download | plan9port-c3a72d77dc9e59e2498d68692feb098bf565e119.tar.gz plan9port-c3a72d77dc9e59e2498d68692feb098bf565e119.tar.bz2 plan9port-c3a72d77dc9e59e2498d68692feb098bf565e119.zip |
Threadplumbrecv.
Diffstat (limited to 'src/libplumb')
-rw-r--r-- | src/libplumb/thread.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/libplumb/thread.c b/src/libplumb/thread.c new file mode 100644 index 00000000..c31fdfb1 --- /dev/null +++ b/src/libplumb/thread.c @@ -0,0 +1,33 @@ +#include <u.h> +#include <libc.h> +#include <thread.h> +#include <fcall.h> +#include <fs.h> +#include "plumb.h" + +Plumbmsg* +threadplumbrecv(int fd) +{ + char *buf; + Plumbmsg *m; + int n, more; + + buf = malloc(8192); + if(buf == nil) + return nil; + n = threadread(fd, 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(threadreadn(fd, buf+n, more) == more) + m = plumbunpackpartial(buf, n+more, nil); + } + } + free(buf); + return m; +} |