commit 02d8ae9b2760083c25ff79c37e169611dbbce6f4
parent 0eca388bd6b162d1a5a7946919000cb7c66cbd68
Author: Renev Pavel <an2qzavok@gmail.com>
Date: Fri, 28 Oct 2022 09:57:53 +0000
src/sendreceive
Diffstat:
4 files changed, 83 insertions(+), 0 deletions(-)
diff --git a/src/sendreceive/mkfile b/src/sendreceive/mkfile
@@ -0,0 +1,9 @@
+</$objtype/mkfile
+
+TARG=send receive
+
+BIN=/$objtype/bin
+
+HFILES=sendreceive.h
+
+</sys/src/cmd/mkmany
diff --git a/src/sendreceive/receive.c b/src/sendreceive/receive.c
@@ -0,0 +1,34 @@
+#include <u.h>
+#include <libc.h>
+#include <plumb.h>
+
+#include "sendreceive.h"
+
+char buf[BufSize];
+
+char *port = DefaultPort;
+
+void
+main(int argc, char **argv)
+{
+ ARGBEGIN {
+ case 'p':
+ port = ARGF();
+ break;
+ } ARGEND
+
+
+
+ Plumbmsg *msg;
+ int pd;
+ pd = plumbopen(port, OREAD);
+ if (pd <= 0) sysfatal("no plumber: %r");
+
+ while (1) {
+ msg = plumbrecv(pd);
+ if (msg == nil) sysfatal("%r");
+ if (write(1, msg->data, msg->ndata) <= 0) break;
+ plumbfree(msg);
+ }
+ close(pd);
+}
diff --git a/src/sendreceive/send.c b/src/sendreceive/send.c
@@ -0,0 +1,38 @@
+#include <u.h>
+#include <libc.h>
+#include <plumb.h>
+
+#include "sendreceive.h"
+
+char buf[BufSize];
+
+char *port = DefaultPort;
+
+void
+main(int argc, char **argv)
+{
+ ARGBEGIN {
+ case 'p':
+ port = ARGF();
+ break;
+ } ARGEND
+
+ int pd;
+
+ Plumbmsg msg = (Plumbmsg){
+ "send",
+ port,
+ nil,
+ "text",
+ nil,
+ 0,
+ buf
+ };
+
+ pd = plumbopen("send", OWRITE);
+ if (pd <= 0) sysfatal("no plumber: %r");
+ while ((msg.ndata = read(0, buf, BufSize)) > 0) {
+ if (plumbsend(pd, &msg) != 0) sysfatal("%r");
+ }
+ close(pd);
+}
diff --git a/src/sendreceive/sendreceive.h b/src/sendreceive/sendreceive.h
@@ -0,0 +1,2 @@
+#define BufSize (4 * 1024 * 1024)
+#define DefaultPort "sendreceive"