commit - a02335e9fc52e4a0360aef25ca3e97943fba8e41
commit + 1304bbdd971edc6bf8cd0c8794ebe5c2dc098bb3
blob - 58ffb2dfc41727a43ccedd0bfb3bd72658309012
blob + 52f9de718c26583b514690d60d90ce3205be586d
--- fs.c
+++ fs.c
static void handle_get(struct imsg*, size_t);
static void handle_quit(struct imsg*, size_t);
static void handle_bookmark_page(struct imsg*, size_t);
-static void dispatch_imsg(int, short, void*);
+static void handle_dispatch_imsg(int, short, void*);
static struct event imsgev;
static struct imsgbuf *ibuf;
}
static void
-dispatch_imsg(int fd, short ev, void *d)
+handle_dispatch_imsg(int fd, short ev, void *d)
{
struct imsgbuf *ibuf = d;
- struct imsg imsg;
- ssize_t n;
- size_t datalen;
-
- if ((n = imsg_read(ibuf)) == -1) {
- if (errno == EAGAIN || errno == EWOULDBLOCK)
- return;
- _exit(1);
- }
-
- if (n == 0)
- _exit(1);
-
- for (;;) {
- if ((n = imsg_get(ibuf, &imsg)) == -1)
- _exit(1);
- if (n == 0)
- return;
- datalen = imsg.hdr.len - IMSG_HEADER_SIZE;
- handlers[imsg.hdr.type](&imsg, datalen);
- imsg_free(&imsg);
- }
+ dispatch_imsg(ibuf, handlers, sizeof(handlers));
}
int
event_init();
- event_set(&imsgev, ibuf->fd, EV_READ | EV_PERSIST, dispatch_imsg, ibuf);
+ event_set(&imsgev, ibuf->fd, EV_READ | EV_PERSIST, handle_dispatch_imsg, ibuf);
event_add(&imsgev, NULL);
sandbox_fs_process();
blob - 4bef3c890fb6df6ded60bc904986713de9b7566e
blob + cd30080724e0fd247b0e1054a84c0870ca3af214
--- gemini.c
+++ gemini.c
static void handle_proceed(struct imsg*, size_t);
static void handle_stop(struct imsg*, size_t);
static void handle_quit(struct imsg*, size_t);
+static void handle_dispatch_imsg(int, short, void*);
/* TODO: making this customizable */
struct timeval timeout_for_handshake = { 5, 0 };
}
static void
-dispatch_imsg(int fd, short ev, void *d)
+handle_dispatch_imsg(int fd, short ev, void *d)
{
struct imsgbuf *ibuf = d;
- struct imsg imsg;
- ssize_t n;
- size_t datalen;
-
- if ((n = imsg_read(ibuf)) == -1) {
- if (errno == EAGAIN || errno == EWOULDBLOCK)
- return;
- _exit(1);
- }
-
- if (n == 0)
- _exit(1);
-
- for (;;) {
- if ((n = imsg_get(ibuf, &imsg)) == -1)
- _exit(1);
- if (n == 0)
- return;
- datalen = imsg.hdr.len - IMSG_HEADER_SIZE;
- handlers[imsg.hdr.type](&imsg, datalen);
- imsg_free(&imsg);
- }
+ dispatch_imsg(ibuf, handlers, sizeof(handlers));
}
int
event_init();
- event_set(&imsgev, ibuf->fd, EV_READ | EV_PERSIST, dispatch_imsg, ibuf);
+ event_set(&imsgev, ibuf->fd, EV_READ | EV_PERSIST, handle_dispatch_imsg, ibuf);
event_add(&imsgev, NULL);
sandbox_network_process();
blob - ab42757ef107f8dfba32453dfe47be2b3fd4547f
blob + 09318ad060eb6efd5e010a2b7cb65e248cdbd584
--- telescope.c
+++ telescope.c
static void handle_imsg_buf(struct imsg*, size_t);
static void handle_imsg_eof(struct imsg*, size_t);
static void handle_imsg_bookmark_ok(struct imsg*, size_t);
-static void dispatch_imsg(int, short, void*);
+static void handle_dispatch_imsg(int, short, void*);
static void load_page_from_str(struct tab*, const char*);
static void do_load_url(struct tab*, const char*);
}
static void
-dispatch_imsg(int fd, short ev, void *d)
+handle_dispatch_imsg(int fd, short ev, void *d)
{
struct imsgbuf *ibuf = d;
- struct imsg imsg;
- size_t datalen;
- ssize_t n;
-
- if ((n = imsg_read(ibuf)) == -1) {
- if (errno == EAGAIN || errno == EWOULDBLOCK)
- return;
- die();
- }
-
- if (n == 0)
- _exit(1);
-
- for (;;) {
- if ((n = imsg_get(ibuf, &imsg)) == -1)
- die();
- if (n == 0)
- return;
- datalen = imsg.hdr.len - IMSG_HEADER_SIZE;
- handlers[imsg.hdr.type](&imsg, datalen);
- imsg_free(&imsg);
- }
+ dispatch_imsg(ibuf, handlers, sizeof(handlers));
}
static void
event_init();
- event_set(&netev, netibuf->fd, EV_READ | EV_PERSIST, dispatch_imsg, netibuf);
+ event_set(&netev, netibuf->fd, EV_READ | EV_PERSIST, handle_dispatch_imsg, netibuf);
event_add(&netev, NULL);
- event_set(&fsev, fsibuf->fd, EV_READ | EV_PERSIST, dispatch_imsg, fsibuf);
+ event_set(&fsev, fsibuf->fd, EV_READ | EV_PERSIST, handle_dispatch_imsg, fsibuf);
event_add(&fsev, NULL);
ui_init();
blob - 001356474322b9cfcdef015a3b66b65180539d89
blob + 3d5ab2a21f1e15e285b036c264f739ae47504d60
--- telescope.h
+++ telescope.h
int mark_nonblock(int);
char *telescope_strnchr(char*, char, size_t);
int has_prefix(const char*, const char*);
+void dispatch_imsg(struct imsgbuf*, imsg_handlerfn**, size_t);
/* wrap.c */
void wrap_text(struct tab*, const char*, struct line*, size_t);
blob - de341c4a62cbca4427a2e90cf9c9b046663291d6
blob + 02c5eb25c86c8e390673c2ac8b62264ca1f8edd8
--- util.c
+++ util.c
#include "telescope.h"
+#include <errno.h>
#include <fcntl.h>
#include <stdlib.h>
+#include <unistd.h>
int
mark_nonblock(int fd)
return 0;
return prfx[i] == '\0';
}
+
+void
+dispatch_imsg(struct imsgbuf *ibuf, imsg_handlerfn **handlers, size_t size)
+{
+ struct imsg imsg;
+ size_t datalen, i;
+ ssize_t n;
+
+ if ((n = imsg_read(ibuf)) == -1) {
+ if (errno == EAGAIN || errno == EWOULDBLOCK)
+ return;
+ _exit(1);
+ }
+
+ if (n == 0)
+ _exit(1);
+
+ for (;;) {
+ if ((n = imsg_get(ibuf, &imsg)) == -1)
+ _exit(1);
+ if (n == 0)
+ return;
+ datalen = imsg.hdr.len - IMSG_HEADER_SIZE;
+ i = imsg.hdr.type;
+ if (i >= (size / sizeof(imsg_handlerfn*)) || handlers[i] == NULL)
+ abort();
+ handlers[i](&imsg, datalen);
+ imsg_free(&imsg);
+ }
+}