ref: 4009eb2feecfa4722d5cb22be4f5db9f26d15be3
parent: a36f997368057fe298524de52310cc4e98bddba8
author: Jacob Moody <moody@posixcafe.org>
date: Fri Aug 19 19:35:41 EDT 2022
rio: correct tap code Remove tapmesg, allow the reads to accept flushes, accept writes of multiple messages, move open/close to Xfid code.
--- a/sys/src/cmd/rio/dat.h
+++ b/sys/src/cmd/rio/dat.h
@@ -122,15 +122,9 @@
};
enum{
- Fon = 'b',
- Foff = 'e',
- Freset = 'r',
-};
-
-struct Tapmesg
-{
- char type;
- char *s;
+ Tapon = 'b',
+ Tapoff = 'e',
+ Tapreset = 'r',
};
struct Window
--- a/sys/src/cmd/rio/fsys.c
+++ b/sys/src/cmd/rio/fsys.c
@@ -116,16 +116,6 @@
return 0;
}
-void
-toggletap(char mode)
-{
- Tapmesg m;
-
- m.type = mode;
- m.s = nil;
- send(fromtap, &m);
-}
-
Filsys*
filsysinit(Channel *cxfidalloc)
{
@@ -518,8 +508,6 @@
if(((f->dir->perm&~(DMDIR|DMAPPEND))&m) != m)
goto Deny;
- if(FILE(f->qid) == Qtap)
- toggletap(Fon);
sendp(x->c, xfidopen);
return nil;
@@ -629,8 +617,6 @@
if(f->open){
f->busy = FALSE;
f->open = FALSE;
- if(FILE(f->qid) == Qtap)
- toggletap(Foff);
sendp(x->c, xfidclose);
return nil;
}
--- a/sys/src/cmd/rio/rio.c
+++ b/sys/src/cmd/rio/rio.c
@@ -197,7 +197,7 @@
if(kbdchan == nil)
error("can't find keyboard");
totap = chancreate(sizeof(char*), 0);
- fromtap = chancreate(sizeof(Tapmesg), 0);
+ fromtap = chancreate(sizeof(char*), 0);
wscreen = allocscreen(screen, background, 0);
if(wscreen == nil)
@@ -340,11 +340,10 @@
keyboardthread(void*)
{
char *s;
- Tapmesg m;
Channel *out;
int mode;
enum { Kdev, Ktap, NALT};
- enum { Mnorm, Mfilt };
+ enum { Mnorm, Mtap };
threadsetname("keyboardthread");
@@ -353,7 +352,7 @@
alts[Kdev].v = &s;
alts[Kdev].op = CHANRCV;
alts[Ktap].c = fromtap;
- alts[Ktap].v = &m;
+ alts[Ktap].v = &s;
alts[Ktap].op = CHANRCV;
alts[NALT].op = CHANEND;
@@ -362,24 +361,24 @@
for(;;)
switch(alt(alts)){
case Ktap:
- switch(m.type){
+ switch(*s){
case 'K': case 'k': case 'c':
break;
- case Freset:
- if(mode != Mfilt)
- continue;
- s = smprint("%c", m.type);
+ case Tapreset:
+ if(mode != Mtap)
+ goto Next;
goto Send;
- case Foff:
+ case Tapoff:
mode = Mnorm;
- continue;
- case Fon:
- mode = Mfilt;
- continue;
+ goto Next;
+ case Tapon:
+ mode = Mtap;
+ /* fallthrough */
default:
+ Next:
+ free(s);
continue;
}
- s = smprint("%c%s", m.type, m.s);
out = input == nil ? nil : input->ck;
goto Send;
case Kdev:
@@ -387,7 +386,7 @@
case Mnorm:
out = input == nil ? nil : input->ck;
break;
- case Mfilt:
+ case Mtap:
out = totap;
break;
}
--- a/sys/src/cmd/rio/wind.c
+++ b/sys/src/cmd/rio/wind.c
@@ -81,7 +81,6 @@
wcurrent(Window *w)
{
Channel *c;
- Tapmesg m;
if(input == nil){
input = w;
@@ -89,9 +88,7 @@
}
if(w == input)
return;
- m.type = Freset;
- m.s = nil;
- send(fromtap, &m);
+ chanprint(fromtap, "%c", Tapreset);
incref(input);
c = chancreate(sizeof(Window*), 0);
wsendctlmesg(input, Repaint, ZR, c);
--- a/sys/src/cmd/rio/xfid.c
+++ b/sys/src/cmd/rio/xfid.c
@@ -307,6 +307,9 @@
wsendctlmesg(w, Wakeup, ZR, nil);
}
break;
+ case Qtap:
+ chanprint(fromtap, "%c", Tapon);
+ break;
}
t.qid = x->f->qid;
t.iounit = messagesize-IOHDRSZ;
@@ -361,6 +364,9 @@
if(x->f->mode==OREAD || x->f->mode==ORDWR)
w->wctlopen = FALSE;
break;
+ case Qtap:
+ chanprint(fromtap, "%c", Tapoff);
+ break;
}
wclose(w);
filsysrespond(x->fs, x, &t, nil);
@@ -371,12 +377,11 @@
{
Fcall fc;
int cnt, qid, nb, off, nr;
- char err[ERRMAX], *p;
+ char err[ERRMAX], *p, *e;
Point pt;
Window *w;
Rune *r;
Conswritemesg cwm;
- Tapmesg fmsg;
Stringpair pair;
enum { CWdata, CWgone, CWflush, NCW };
Alt alts[NCW+1];
@@ -574,9 +579,9 @@
filsysrespond(x->fs, x, &fc, "malformed key");
return;
}
- fmsg.type = x->data[0];
- fmsg.s = strdup(x->data+1);
- send(fromtap, &fmsg);
+ e = x->data + cnt;
+ for(p = x->data; p < e; p += strlen(p)+1)
+ chanprint(fromtap, "%s", p);
break;
default:
@@ -694,7 +699,26 @@
break;
case Qtap:
- recv(totap, &t);
+ alts[Adata].c = totap;
+ alts[Adata].v = &t;
+ alts[Adata].op = CHANRCV;
+ alts[Agone].c = w->gone;
+ alts[Agone].v = nil;
+ alts[Agone].op = CHANRCV;
+ alts[Aflush].c = x->flushc;
+ alts[Aflush].v = nil;
+ alts[Aflush].op = CHANRCV;
+ alts[Aend].op = CHANEND;
+ switch(alt(alts)){
+ case Adata:
+ break;
+ case Agone:
+ filsysrespond(x->fs, x, &fc, Edeleted);
+ return;
+ case Aflush:
+ filsyscancel(x);
+ return;
+ }
fc.data = t;
fc.count = strlen(t)+1;
filsysrespond(x->fs, x, &fc, nil);