You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.1 KiB
59 lines
1.1 KiB
#define POLLFD(ptr) ((struct pollfd *)(ptr))
|
|
|
|
static
|
|
inline
|
|
int
|
|
sortEvents(const void * a, const void * b)
|
|
{
|
|
return POLLFD(a)->events > POLLFD(b)->events ?
|
|
-1 : POLLFD(a)->events < POLLFD(b)->events ?
|
|
1 : 0;
|
|
}
|
|
|
|
static
|
|
inline
|
|
int
|
|
sortRevents(const void * a, const void * b)
|
|
{
|
|
return POLLFD(a)->revents > POLLFD(b)->revents ?
|
|
-1 : POLLFD(a)->revents < POLLFD(b)->revents ?
|
|
1 : 0;
|
|
}
|
|
|
|
static
|
|
int
|
|
serverPoll(Server this) {
|
|
int events;
|
|
|
|
qsort(this->fds, this->nfds, sizeof(struct pollfd), sortEvents);
|
|
while((this->fds)[this->nfds].fd == 0 && this->nfds > 0) this->nfds--;
|
|
this->nfds++;
|
|
|
|
/*
|
|
* wait for handles to become ready
|
|
*/
|
|
if (-1 == (events = poll(this->fds, this->nfds, -1))) {
|
|
switch (errno) {
|
|
default:
|
|
case EBADF:
|
|
case EINVAL:
|
|
case ENOMEM:
|
|
doShutdown = 1;
|
|
/* Fallthrough */
|
|
|
|
case EINTR:
|
|
loggerLog(this->logger, LOGGER_CRIT,
|
|
"poll systemcall failed: [%s] - service terminated",
|
|
strerror(errno));
|
|
//exit(EXIT_FAILURE); /* @TODO do real shutdown here */
|
|
}
|
|
}
|
|
|
|
if (-1 != events) {
|
|
qsort(this->fds, this->nfds, sizeof(struct pollfd), sortRevents);
|
|
}
|
|
|
|
return events;
|
|
}
|
|
|
|
// vim: set ts=4 sw=4:
|