shithub: rd

Download patch

ref: 65f684770c3d89be3f728b18cff4edae53c2859d
parent: a112d0361572e29c183c468b7d1177bcb169360e
author: Yaroslav Kolomiiets <yarikos@gmail.com>
date: Tue Aug 9 12:56:34 EDT 2016

languange

--- a/dat.h
+++ b/dat.h
@@ -188,9 +188,7 @@
 Msgget	getlicensemsg;
 Msgput	putlicensemsg;
 void 	respondlicense(Rdp*,Msg*);
-
-void	scanvc(Rdp*, Msg*);
-void	scanupdates(Rdp*, Msg*);
+void	apply(Rdp* c, Msg* m);
 
 enum /* Share.type */
 {
--- a/msg.c
+++ b/msg.c
@@ -434,6 +434,8 @@
 	if((n = readpdu(fd, buf, nb)) < 0 || getmsg(m, buf, n) <= 0)
 		return -1;
 
+	if(m->type == Mclosing)
+		return 0;
 	return n;
 }
 
--- a/rd-thread.c
+++ b/rd-thread.c
@@ -212,3 +212,15 @@
 	pollsnarf(c);
 	threadexits("snarf eof");
 }
+
+void
+readnet(Rdp* c)
+{
+	Msg r;
+
+	for(;;){
+		if(readmsg(c, &r) <= 0)
+			break;
+		apply(c, &r);
+	}
+}
--- a/rd.c
+++ b/rd.c
@@ -210,6 +210,18 @@
 }
 
 void
+readnet(Rdp* c)
+{
+	Msg r;
+
+	for(;;){
+		if(readmsg(c, &r) <= 0)
+			break;
+		apply(c, &r);
+	}
+}
+
+void
 readkbd(Rdp* c)
 {
 	char buf[256], k[10];
--- a/rpc.c
+++ b/rpc.c
@@ -4,10 +4,18 @@
 #include "dat.h"
 #include "fns.h"
 
-int	mcsconnect(Rdp*);
-int	attachuser(Rdp*);
-int	joinchannel(Rdp*,int,int);
+static void	applyvc(Rdp*, Msg*);
+static void	applyupdates(Rdp*, Msg*);
 
+extern
+	int	mcsconnect(Rdp*);
+	int	attachuser(Rdp*);
+	int	joinchannel(Rdp*,int,int);
+
+	int	defragvc(Rdp*,Msg*);
+	void	callvcfunc(Rdp*,Msg*);
+
+
 int
 x224handshake(Rdp* c)
 {
@@ -388,35 +396,26 @@
 }
 
 void
-readnet(Rdp* c)
+apply(Rdp* c, Msg* m)
 {
-	Msg r;
-
-	for(;;){
-		if(readmsg(c, &r) <= 0)
-			return;
-
-		switch(r.type){
-		case Mclosing:
-			return;
-		case Mvchan:
-			scanvc(c, &r);
-			break;
-		case Aupdate:
-			scanupdates(c, &r);
-			break;
-		case 0:
-			fprint(2, "unsupported PDU\n");
-			break;
-		default:
-			fprint(2, "r.type %d is not expected\n", r.type);
-		}
+	switch(m->type){
+	default:	fprint(2, "type %d is not expected\n", m->type); break;
+	case 0:	fprint(2, "unsupported PDU\n"); break;
+	case Mvchan:	applyvc(c, m); break;
+	case Aupdate:	applyupdates(c, m); break;
 	}
 }
 
-void
-scanupdates(Rdp* c, Msg* m)
+static void
+applyvc(Rdp* c, Msg* m)
 {
+	if(defragvc(c, m) > 0)
+		callvcfunc(c, m);
+}
+
+static void
+applyupdates(Rdp* c, Msg* m)
+{
 	int n;
 	uchar *p, *ep;
 	Share u;
@@ -427,12 +426,12 @@
 	for(; p < ep; p += n){
 		n = m->getshare(&u, p, ep-p);
 		if(n < 0)
-			sysfatal("scanupdates: %r");
+			sysfatal("applyupdates: %r");
 
 		switch(u.type){
 		default:
 			if(u.type != 0)
-				fprint(2, "scanupdates: unhandled %d\n", u.type);
+				fprint(2, "applyupdates: unhandled %d\n", u.type);
 			break;
 		case ShDeactivate:
 			deactivate(c, &u);
--- a/vchan.c
+++ b/vchan.c
@@ -61,7 +61,7 @@
 	return nil;
 }
 
-static int
+int
 defragvc(Rdp*, Msg* m)
 {
 	Vchan* vc;
@@ -92,7 +92,7 @@
 	return 0;
 }
 
-static void
+void
 callvcfunc(Rdp *c, Msg* m)
 {
 	Vchan* vc;
@@ -100,13 +100,6 @@
 	if(vc == nil)
 		return;
 	vc->fn(c, m->data, m->ndata);
-}
-
-void
-scanvc(Rdp* c, Msg* m)
-{
-	if(defragvc(c, m) > 0)
-		callvcfunc(c, m);
 }
 
 int