~foura/libacme

e29aea8358355e6e195ec2782ec0d7b67eac4f1c — james palmer 6 months ago 27e0890
don't hold some fds open. add function for opening file with bio
3 files changed, 26 insertions(+), 10 deletions(-)

M acme.h
M event.c
M window.c
M acme.h => acme.h +3 -3
@@ 11,10 11,8 @@ struct AWin {
	int id;
	
	int ctlfd;
	int eventfd;
	int addrfd;
	int datafd;
	int bodyfd;
	
	Channel *eventc;
	


@@ 35,7 33,9 @@ struct AEvent {
	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 *);

M event.c => event.c +9 -4
@@ 78,8 78,7 @@ aeventproc(void *aux)
	
	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 @@ aeventstop(AWin *w)
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);
}

M window.c => window.c +14 -3
@@ 1,6 1,7 @@
#include <u.h>
#include <libc.h>
#include <thread.h>
#include <bio.h>

#include "acme.h"



@@ 19,6 20,19 @@ awinfsopen(AWin *w, char *file, int mode)
	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 @@ awincreate(void)
		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 @@ awinclose(AWin *w)
	
	fprint(w->ctlfd, "delete");

	close(w->eventfd);
	close(w->addrfd);
	close(w->datafd);
	


@@ 75,7 87,6 @@ awincloseall(void)
	while(temp) {
		fprint(temp->ctlfd, "delete");
		
		close(temp->eventfd);
		close(temp->addrfd);
		close(temp->datafd);