summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorratchov <ratchov@openbsd.org>2015-07-17 10:15:24 +0000
committerratchov <ratchov@openbsd.org>2015-07-17 10:15:24 +0000
commit1e4c42ba3912a188ca6acb01b8aa2cac1c06bbb9 (patch)
tree346d427b356aab37138fec7e28bdafeb7e75e200
parentrename nfds to max_nfds, no object change (diff)
downloadwireguard-openbsd-1e4c42ba3912a188ca6acb01b8aa2cac1c06bbb9.tar.xz
wireguard-openbsd-1e4c42ba3912a188ca6acb01b8aa2cac1c06bbb9.zip
Use an offsets in the array of pollfd structures instead of pointers. No
behaviour change.
-rw-r--r--usr.bin/sndiod/file.c43
-rw-r--r--usr.bin/sndiod/file.h4
2 files changed, 24 insertions, 23 deletions
diff --git a/usr.bin/sndiod/file.c b/usr.bin/sndiod/file.c
index fbd2bf42603..18dc7611f85 100644
--- a/usr.bin/sndiod/file.c
+++ b/usr.bin/sndiod/file.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: file.c,v 1.10 2015/07/17 09:51:18 ratchov Exp $ */
+/* $OpenBSD: file.c,v 1.11 2015/07/17 10:15:24 ratchov Exp $ */
/*
* Copyright (c) 2008-2012 Alexandre Ratchov <alex@caoua.org>
*
@@ -272,7 +272,7 @@ file_del(struct file *f)
int
file_poll(void)
{
- struct pollfd pfds[MAXFDS];
+ struct pollfd pfds[MAXFDS], *pfd;
struct file *f, **pf;
struct timespec ts;
#ifdef DEBUG
@@ -282,7 +282,7 @@ file_poll(void)
int i;
#endif
long long delta_nsec;
- int n, nfds, revents, res, immed;
+ int nfds, revents, res, immed;
/*
* cleanup zombies
@@ -308,30 +308,30 @@ file_poll(void)
nfds = 0;
immed = 0;
for (f = file_list; f != NULL; f = f->next) {
- n = f->ops->pollfd(f->arg, pfds + nfds);
- if (n == 0) {
- f->pfd = NULL;
+ f->nfds = f->ops->pollfd(f->arg, pfds + nfds);
+ if (f->nfds == 0)
continue;
- }
- if (n < 0) {
+ if (f->nfds < 0) {
immed = 1;
- n = 0;
+ continue;
}
- f->pfd = pfds + nfds;
- nfds += n;
+ nfds += f->nfds;
}
#ifdef DEBUG
if (log_level >= 4) {
log_puts("poll:");
- for (i = 0; i < nfds; i++) {
+ pfd = pfds;
+ for (f = file_list; f != NULL; f = f->next) {
+ if (f->nfds <= 0)
+ continue;
log_puts(" ");
- for (f = file_list; f != NULL; f = f->next) {
- if (f->pfd == &pfds[i]) {
- log_puts(f->ops->name);
- log_puts(": ");
- }
+ log_puts(f->ops->name);
+ log_puts(":");
+ for (i = 0; i < f->nfds; i++) {
+ log_puts(" ");
+ log_putx(pfd->events);
+ pfd++;
}
- log_putx(pfds[i].events);
}
log_puts("\n");
}
@@ -365,16 +365,16 @@ file_poll(void)
}
if (!immed && res <= 0)
return 1;
-
+ pfd = pfds;
for (f = file_list; f != NULL; f = f->next) {
- if (f->pfd == NULL)
+ if (f->nfds <= 0)
continue;
#ifdef DEBUG
if (log_level >= 3)
clock_gettime(CLOCK_MONOTONIC, &ts0);
#endif
revents = (f->state != FILE_ZOMB) ?
- f->ops->revents(f->arg, f->pfd) : 0;
+ f->ops->revents(f->arg, pfd) : 0;
if ((revents & POLLHUP) && (f->state != FILE_ZOMB))
f->ops->hup(f->arg);
if ((revents & POLLIN) && (f->state != FILE_ZOMB))
@@ -394,6 +394,7 @@ file_poll(void)
}
}
#endif
+ pfd += f->nfds;
}
return 1;
}
diff --git a/usr.bin/sndiod/file.h b/usr.bin/sndiod/file.h
index 41636947971..b9b39c7bb04 100644
--- a/usr.bin/sndiod/file.h
+++ b/usr.bin/sndiod/file.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: file.h,v 1.2 2015/07/17 09:51:18 ratchov Exp $ */
+/* $OpenBSD: file.h,v 1.3 2015/07/17 10:15:24 ratchov Exp $ */
/*
* Copyright (c) 2008-2012 Alexandre Ratchov <alex@caoua.org>
*
@@ -47,13 +47,13 @@ struct fileops {
struct file {
struct file *next; /* next in file_list */
- struct pollfd *pfd; /* arg to poll(2) syscall */
struct fileops *ops; /* event handlers */
void *arg; /* argument to event handlers */
#define FILE_INIT 0 /* ready */
#define FILE_ZOMB 1 /* closed, but not free()d yet */
unsigned int state; /* one of above */
unsigned int max_nfds; /* max number of descriptors */
+ int nfds; /* number of descriptors polled */
char *name; /* for debug purposes */
};