shithub: orca

Download patch

ref: 8dc5d00e9e157ed86b4c98326ea09ea920080c3f
parent: 99dcd9586d4485fcdfcbe2d9511214b6bbbba7c5
author: Sigrid Haflínudóttir <ftrvxmtrx@gmail.com>
date: Fri Feb 21 15:52:57 EST 2020

plan9: udp

--- a/plan9.c
+++ b/plan9.c
@@ -81,6 +81,8 @@
 static bool altdown, pause, forward;
 static int mode = Minsert;
 static long framedev; /* frame deviation in ms */
+static char *ip, *udpport;
+static int udp = -1;
 
 static struct {
 	struct {
@@ -257,6 +259,17 @@
 }
 
 static void
+netdial(void)
+{
+	if (udp >= 0)
+		close(udp);
+	if (udp < 0 && (udp = dial(netmkaddr(ip, "udp", udpport), nil, nil, nil)) < 0) {
+		fprint(2, "udp failed: %r\n");
+		/* FIXME display error */
+	}
+}
+
+static void
 command(char *s)
 {
 	char *a;
@@ -302,6 +315,13 @@
 			tick = MAX(0, tick+x);
 		else if (strcmp(s, "rewind") == 0)
 			tick = MAX(0, tick-x);
+		else if (strcmp(s, "ip") == 0) {
+			free(ip);
+			ip = strdup(a);
+			close(udp);
+			udp = -1;
+			netdial();
+		}
 
 		/* FIXME color, find, select, inject, write, time */
 	}
@@ -334,6 +354,12 @@
 			memmove(tmp, c->chars, c->count);
 			tmp[c->count] = 0;
 			command(tmp);
+		} else if (e->any.oevent_type = Oevent_type_udp_string) {
+			Oevent_udp_string *u = &e->udp_string;
+			if (udp >= 0 && (i = write(udp, u->chars, u->count)) != u->count)
+				fprint(2, "udp write: %r\n");
+			else
+				fprint(2, "udp: %d\n", i);
 		}
 	}
 
@@ -1082,6 +1108,10 @@
 	move.y = 1;
 	oldbuttons = 0;
 
+	ip = strdup("127.0.0.1");
+	udpport = strdup("49160");
+	netdial();
+
 	for (;;) {
 		redraw(complete);
 		complete = false;
@@ -1396,6 +1426,7 @@
 	field_deinit(&fscr);
 	field_deinit(&fsel);
 	free(linebuf);
+	close(udp);
 
 	threadexitsall(nil);
 }