|
server 0.0.1
basicserverinfrastructure
|
00001 #define POLLFD(ptr) ((struct pollfd *)(ptr)) 00002 00003 static 00004 inline 00005 int 00006 sortEvents(const void * a, const void * b) 00007 { 00008 return POLLFD(a)->events > POLLFD(b)->events ? 00009 -1 : POLLFD(a)->events < POLLFD(b)->events ? 00010 1 : 0; 00011 } 00012 00013 static 00014 inline 00015 int 00016 sortRevents(const void * a, const void * b) 00017 { 00018 return POLLFD(a)->revents > POLLFD(b)->revents ? 00019 -1 : POLLFD(a)->revents < POLLFD(b)->revents ? 00020 1 : 0; 00021 } 00022 00023 static 00024 int 00025 serverPoll(Server this) { 00026 int events; 00027 00028 qsort(this->fds, this->nfds, sizeof(struct pollfd), sortEvents); 00029 this->nfds -= this->ndel; 00030 this->ndel = 0; 00031 00032 /* 00033 * wait for handles to become ready 00034 */ 00035 if (-1 == (events = poll(this->fds, this->nfds, -1))) { 00036 switch (errno) { 00037 default: 00038 case EBADF: 00039 case EINVAL: 00040 case ENOMEM: 00041 doShutdown = 1; 00042 /* Fallthrough */ 00043 00044 case EINTR: 00045 loggerLog(this->logger, LOGGER_CRIT, 00046 "poll systemcall failed: [%s] - service terminated", 00047 strerror(errno)); 00048 //exit(EXIT_FAILURE); /* @TODO do real shutdown here */ 00049 } 00050 } 00051 00052 qsort(this->fds, this->nfds, sizeof(struct pollfd), sortRevents); 00053 00054 return events; 00055 } 00056 00057 // vim: set ts=4 sw=4: