use O_ASYNC + SIGIO instead of polling for input

This commit is contained in:
jmcneill 2011-12-30 11:06:18 +00:00
parent 023645c4d8
commit fc3088ac6d
2 changed files with 26 additions and 14 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: vncfb.c,v 1.3 2011/12/30 09:31:44 jmcneill Exp $ */
/* $NetBSD: vncfb.c,v 1.4 2011/12/30 11:06:18 jmcneill Exp $ */
/*-
* Copyright (c) 2011 Jared D. McNeill <jmcneill@invisible.ca>
@ -35,7 +35,7 @@
#include "opt_wsemul.h"
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: vncfb.c,v 1.3 2011/12/30 09:31:44 jmcneill Exp $");
__KERNEL_RCSID(0, "$NetBSD: vncfb.c,v 1.4 2011/12/30 11:06:18 jmcneill Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -80,7 +80,7 @@ struct vncfb_softc {
int sc_kbd_enable;
callout_t sc_callout;
void *sc_ih;
void *sc_sih;
};
@ -103,7 +103,7 @@ static paddr_t vncfb_mmap(void *, void *, off_t, int);
static void vncfb_init_screen(void *, struct vcons_screen *, int, long *);
static void vncfb_update(struct vncfb_softc *, int, int, int, int);
static void vncfb_poll(void *);
static int vncfb_intr(void *);
static void vncfb_softintr(void *);
static int vncfb_kbd_enable(void *, int);
@ -188,9 +188,6 @@ vncfb_attach(device_t parent, device_t self, void *priv)
(sc->sc_depth / 8), KM_SLEEP);
KASSERT(sc->sc_framebuf != NULL);
callout_init(&sc->sc_callout, 0);
callout_setfunc(&sc->sc_callout, vncfb_poll, sc);
aprint_naive("\n");
aprint_normal(": %ux%u %ubpp (port %u)\n",
sc->sc_width, sc->sc_height, sc->sc_depth, taa->u.vnc.port);
@ -208,7 +205,7 @@ vncfb_attach(device_t parent, device_t self, void *priv)
panic("couldn't open rfb server");
sc->sc_sih = softint_establish(SOFTINT_SERIAL, vncfb_softintr, sc);
callout_schedule(&sc->sc_callout, 1);
sc->sc_ih = sigio_intr_establish(vncfb_intr, sc);
vcons_init(&sc->sc_vd, sc, &vncfb_defaultscreen, &vncfb_accessops);
sc->sc_vd.init_screen = vncfb_init_screen;
@ -455,14 +452,17 @@ static void
vncfb_update(struct vncfb_softc *sc, int x, int y, int w, int h)
{
thunk_rfb_update(&sc->sc_rfb, x, y, w, h);
softint_schedule(sc->sc_sih);
}
static void
vncfb_poll(void *priv)
static int
vncfb_intr(void *priv)
{
struct vncfb_softc *sc = priv;
softint_schedule(sc->sc_sih);
return 0;
}
static void
@ -486,8 +486,6 @@ vncfb_softintr(void *priv)
break;
}
}
callout_schedule(&sc->sc_callout, 1);
}
static int

View File

@ -1,4 +1,4 @@
/* $NetBSD: thunk.c,v 1.59 2011/12/30 11:05:07 reinoud Exp $ */
/* $NetBSD: thunk.c,v 1.60 2011/12/30 11:06:18 jmcneill Exp $ */
/*-
* Copyright (c) 2011 Jared D. McNeill <jmcneill@invisible.ca>
@ -28,7 +28,7 @@
#include <sys/cdefs.h>
#ifdef __NetBSD__
__RCSID("$NetBSD: thunk.c,v 1.59 2011/12/30 11:05:07 reinoud Exp $");
__RCSID("$NetBSD: thunk.c,v 1.60 2011/12/30 11:06:18 jmcneill Exp $");
#endif
#include <sys/types.h>
@ -1077,6 +1077,7 @@ thunk_rfb_poll(thunk_rfb_t *rfb, thunk_rfb_event_t *event)
struct sockaddr_in sin;
struct pollfd fds[1];
socklen_t sinlen;
int flags;
/* poll for connections */
fds[0].fd = rfb->sockfd;
@ -1103,6 +1104,19 @@ thunk_rfb_poll(thunk_rfb_t *rfb, thunk_rfb_event_t *event)
}
rfb->connected = true;
/* enable sigio on input */
flags = fcntl(rfb->clientfd, F_GETFL, 0);
fcntl(rfb->clientfd, F_SETFL, flags | O_ASYNC);
error = fcntl(rfb->clientfd, F_SETOWN, getpid());
if (error) {
fprintf(stdout, "rfb: setown failed: %s\n",
strerror(errno));
close(rfb->clientfd);
rfb->clientfd = -1;
return -1;
}
rfb->nupdates = 0;
thunk_rfb_update(rfb, 0, 0, rfb->width, rfb->height);
}