version 1.10, 2015/07/17 09:51:18 |
version 1.11, 2015/07/17 10:15:24 |
|
|
int |
int |
file_poll(void) |
file_poll(void) |
{ |
{ |
struct pollfd pfds[MAXFDS]; |
struct pollfd pfds[MAXFDS], *pfd; |
struct file *f, **pf; |
struct file *f, **pf; |
struct timespec ts; |
struct timespec ts; |
#ifdef DEBUG |
#ifdef DEBUG |
|
|
int i; |
int i; |
#endif |
#endif |
long long delta_nsec; |
long long delta_nsec; |
int n, nfds, revents, res, immed; |
int nfds, revents, res, immed; |
|
|
/* |
/* |
* cleanup zombies |
* cleanup zombies |
|
|
nfds = 0; |
nfds = 0; |
immed = 0; |
immed = 0; |
for (f = file_list; f != NULL; f = f->next) { |
for (f = file_list; f != NULL; f = f->next) { |
n = f->ops->pollfd(f->arg, pfds + nfds); |
f->nfds = f->ops->pollfd(f->arg, pfds + nfds); |
if (n == 0) { |
if (f->nfds == 0) |
f->pfd = NULL; |
|
continue; |
continue; |
} |
if (f->nfds < 0) { |
if (n < 0) { |
|
immed = 1; |
immed = 1; |
n = 0; |
continue; |
} |
} |
f->pfd = pfds + nfds; |
nfds += f->nfds; |
nfds += n; |
|
} |
} |
#ifdef DEBUG |
#ifdef DEBUG |
if (log_level >= 4) { |
if (log_level >= 4) { |
log_puts("poll:"); |
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(" "); |
log_puts(" "); |
for (f = file_list; f != NULL; f = f->next) { |
log_puts(f->ops->name); |
if (f->pfd == &pfds[i]) { |
log_puts(":"); |
log_puts(f->ops->name); |
for (i = 0; i < f->nfds; i++) { |
log_puts(": "); |
log_puts(" "); |
} |
log_putx(pfd->events); |
|
pfd++; |
} |
} |
log_putx(pfds[i].events); |
|
} |
} |
log_puts("\n"); |
log_puts("\n"); |
} |
} |
|
|
} |
} |
if (!immed && res <= 0) |
if (!immed && res <= 0) |
return 1; |
return 1; |
|
pfd = pfds; |
for (f = file_list; f != NULL; f = f->next) { |
for (f = file_list; f != NULL; f = f->next) { |
if (f->pfd == NULL) |
if (f->nfds <= 0) |
continue; |
continue; |
#ifdef DEBUG |
#ifdef DEBUG |
if (log_level >= 3) |
if (log_level >= 3) |
clock_gettime(CLOCK_MONOTONIC, &ts0); |
clock_gettime(CLOCK_MONOTONIC, &ts0); |
#endif |
#endif |
revents = (f->state != FILE_ZOMB) ? |
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)) |
if ((revents & POLLHUP) && (f->state != FILE_ZOMB)) |
f->ops->hup(f->arg); |
f->ops->hup(f->arg); |
if ((revents & POLLIN) && (f->state != FILE_ZOMB)) |
if ((revents & POLLIN) && (f->state != FILE_ZOMB)) |
|
|
} |
} |
} |
} |
#endif |
#endif |
|
pfd += f->nfds; |
} |
} |
return 1; |
return 1; |
} |
} |