| Date: Sun, 29 Feb 2004 23:11:52 +0000
Threadplumbrecv.
Diffstat:
A src/libplumb/thread.c | 33 +++++++++++++++++++++++++++++++
1 file changed, 33 insertions(+), 0 deletions(-)
--- |
| t@@ -0,0 +1,33 @@
+#include
+#include
+#include
+#include
+#include
+#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;
+} |