mirror of
https://github.com/9fans/plan9port.git
synced 2025-01-27 11:52:03 +00:00
Threaded read9pmsg.
This commit is contained in:
parent
2517c38a8c
commit
b4705757e5
1 changed files with 32 additions and 0 deletions
32
src/libthread/read9pmsg.c
Normal file
32
src/libthread/read9pmsg.c
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
#include <u.h>
|
||||||
|
#include <libc.h>
|
||||||
|
#include <fcall.h>
|
||||||
|
#include <thread.h>
|
||||||
|
|
||||||
|
int
|
||||||
|
threadread9pmsg(int fd, void *abuf, uint n)
|
||||||
|
{
|
||||||
|
int m, len;
|
||||||
|
uchar *buf;
|
||||||
|
|
||||||
|
buf = abuf;
|
||||||
|
|
||||||
|
/* read count */
|
||||||
|
m = threadreadn(fd, buf, BIT32SZ);
|
||||||
|
if(m != BIT32SZ){
|
||||||
|
if(m < 0)
|
||||||
|
return -1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
len = GBIT32(buf);
|
||||||
|
if(len <= BIT32SZ || len > n){
|
||||||
|
werrstr("bad length in 9P2000 message header");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
len -= BIT32SZ;
|
||||||
|
m = threadreadn(fd, buf+BIT32SZ, len);
|
||||||
|
if(m < len)
|
||||||
|
return 0;
|
||||||
|
return BIT32SZ+m;
|
||||||
|
}
|
Loading…
Reference in a new issue