shithub: mq

Download patch

ref: a43e93c246dbb5743927d132cb726a61ffb9f35f
parent: 72923348e0383cdc4b1756f90bd41d0054e34433
author: kvik <kvik@a-b.xyz>
date: Mon Aug 31 10:22:51 EDT 2020

rearrange code; group Srv handlers together

--- a/src/mq.c
+++ b/src/mq.c
@@ -176,57 +176,8 @@
 	return f;
 }
 
-void
-xcreate(Req *r)
-{
-	char *name = r->ifcall.name;
-	char *uid = r->fid->uid;
-	ulong perm = r->ifcall.perm;
-	File *parent = r->fid->file;
-	File *f = nil;
 
-	switch(filetype(parent)){
-	case Qroot:
-		if(!(perm&DMDIR)){
-			respond(r, "forbidden");
-			return;
-		}
-		/* fallthrough */
-	case Qmq:
-		if(perm&DMDIR)
-			f = mqcreate(parent, name, uid, perm);
-		else
-			f = pipecreate(parent, name, uid, perm);
-		break;
-	}
-	if(f == nil)
-		responderror(r);
-	else
-		respond(r, nil);
-}
-
 void
-xopen(Req *r)
-{
-	File *f = r->fid->file;
-
-	switch(filetype(f)){
-	case Qpipe:
-	case Qorder: {
-		Pipe *p = f->aux;
-		Client *c;
-
-		c = r->fid->aux = emalloc(sizeof(Client));
-		if(p->group->replay)
-			c->cursor = (Write*)p->history;
-		else
-			c->cursor = (Write*)p->history->tail;
-		break;
-	}}
-	respond(r, nil);
-}
-
-void
 respondread(Req *r, Write *w)
 {
 	r->ofcall.count = w->count;
@@ -376,6 +327,56 @@
 }
 
 void
+xcreate(Req *r)
+{
+	char *name = r->ifcall.name;
+	char *uid = r->fid->uid;
+	ulong perm = r->ifcall.perm;
+	File *parent = r->fid->file;
+	File *f = nil;
+
+	switch(filetype(parent)){
+	case Qroot:
+		if(!(perm&DMDIR)){
+			respond(r, "forbidden");
+			return;
+		}
+		/* fallthrough */
+	case Qmq:
+		if(perm&DMDIR)
+			f = mqcreate(parent, name, uid, perm);
+		else
+			f = pipecreate(parent, name, uid, perm);
+		break;
+	}
+	if(f == nil)
+		responderror(r);
+	else
+		respond(r, nil);
+}
+
+void
+xopen(Req *r)
+{
+	File *f = r->fid->file;
+
+	switch(filetype(f)){
+	case Qpipe:
+	case Qorder: {
+		Pipe *p = f->aux;
+		Client *c;
+
+		c = r->fid->aux = emalloc(sizeof(Client));
+		if(p->group->replay)
+			c->cursor = (Write*)p->history;
+		else
+			c->cursor = (Write*)p->history->tail;
+		break;
+	}}
+	respond(r, nil);
+}
+
+void
 xwrite(Req *r)
 {
 	File *f = r->fid->file;
@@ -457,8 +458,8 @@
 Srv fs = {
 	.create = xcreate,
 	.open = xopen,
-	.read = xread,
 	.write = xwrite,
+	.read = xread,
 	.flush = xflush,
 	.destroyfid = xdestroyfid,
 };