receive.c (479B)
1 #include <u.h> 2 #include <libc.h> 3 #include <plumb.h> 4 5 #include "sendreceive.h" 6 7 char buf[BufSize]; 8 9 char *port = DefaultPort; 10 11 void 12 main(int argc, char **argv) 13 { 14 ARGBEGIN { 15 case 'p': 16 port = ARGF(); 17 break; 18 } ARGEND 19 20 21 22 Plumbmsg *msg; 23 int pd; 24 pd = plumbopen(port, OREAD); 25 if (pd <= 0) sysfatal("no plumber: %r"); 26 27 while (1) { 28 msg = plumbrecv(pd); 29 if (msg == nil) sysfatal("%r"); 30 if (write(1, msg->data, msg->ndata) <= 0) break; 31 plumbfree(msg); 32 } 33 close(pd); 34 }