plan9port/src/libplumb/thread.c

35 lines
621 B
C
Raw Normal View History

2004-02-29 23:11:52 +00:00
#include <u.h>
#include <libc.h>
#include <thread.h>
#include <fcall.h>
#include <fs.h>
#include "plumb.h"
Plumbmsg*
2004-12-27 19:13:15 +00:00
ioplumbrecv(Ioproc *io, int fd)
2004-02-29 23:11:52 +00:00
{
char *buf;
Plumbmsg *m;
int n, more;
buf = malloc(8192);
if(buf == nil)
return nil;
2004-12-27 19:13:15 +00:00
n = ioread(io, fd, buf, 8192);
2004-02-29 23:11:52 +00:00
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;
2004-12-27 19:13:15 +00:00
if(ioreadn(io, fd, buf+n, more) == more)
2004-02-29 23:11:52 +00:00
m = plumbunpackpartial(buf, n+more, nil);
}
}
free(buf);
return m;
}