ref: e29aea8358355e6e195ec2782ec0d7b67eac4f1c
parent: 27e08900d5716c2b3bb909fdc6cbe0bcfbb137ee
author: james palmer <[email protected]>
date: Mon Jun 7 15:16:14 EDT 2021
don't hold some fds open. add function for opening file with bio
--- a/acme.h
+++ b/acme.h
@@ -11,10 +11,8 @@
int id;
int ctlfd;
- int eventfd;
int addrfd;
int datafd;
- int bodyfd;
Channel *eventc;
@@ -35,7 +33,9 @@
char text[AEventSz + 1];
};
-int awinfsopen(AWin *, char *, int);
+int awinfsopen(AWin *, char *, int);
+Biobuf * awinfsbopen(AWin *, char *, int);
+
AWin * awincreate(void);
void awinclose(AWin *);
--- a/event.c
+++ b/event.c
@@ -78,8 +78,7 @@
w = aux;
c = w->eventc;
- bio = mallocz(sizeof(Biobuf), 1);
- Binit(bio, w->eventfd, OREAD);
+ bio = awinfsbopen(w, "event", OREAD);
while(aeventnext(bio, &ev)) {
if(send(c, &ev) < 0) {
@@ -114,8 +113,14 @@
void
aeventsend(AWin *w, AEvent *ev)
{
+ int fd;
+
+ fd = awinfsopen(w, "event", OWRITE);
+
if(ev->flags & 0x2)
- fprint(w->eventfd, "%c%c%d %d\n", ev->origin, ev->type, ev->p, ev->p);
+ fprint(fd, "%c%c%d %d\n", ev->origin, ev->type, ev->p, ev->p);
else
- fprint(w->eventfd, "%c%c%d %d\n", ev->origin, ev->type, ev->q0, ev->q1);
+ fprint(fd, "%c%c%d %d\n", ev->origin, ev->type, ev->q0, ev->q1);
+
+ close(fd);
}
--- a/window.c
+++ b/window.c
@@ -1,6 +1,7 @@
#include <u.h>
#include <libc.h>
#include <thread.h>
+#include <bio.h>
#include "acme.h"
@@ -19,6 +20,19 @@
return fd;
}
+Biobuf *
+awinfsbopen(AWin *w, char *file, int mode)
+{
+ char buf[128];
+ Biobuf *fd;
+
+ snprint(buf, sizeof(buf), "/mnt/wsys/%d/%s", w->id, file);
+ if((fd = Bopen(buf, mode)) == nil)
+ sysfatal("bopen %s: %r", file);
+
+ return fd;
+}
+
AWin *
awincreate(void)
{
@@ -33,7 +47,6 @@
sysfatal("read ctl: %r");
w->id = atoi(buf);
- w->eventfd = awinfsopen(w, "event", ORDWR);
w->addrfd = awinfsopen(w, "addr", ORDWR);
w->datafd = awinfsopen(w, "data", ORDWR);
@@ -50,7 +63,6 @@
fprint(w->ctlfd, "delete");
- close(w->eventfd);
close(w->addrfd);
close(w->datafd);
@@ -75,7 +87,6 @@
while(temp) {
fprint(temp->ctlfd, "delete");
- close(temp->eventfd);
close(temp->addrfd);
close(temp->datafd);