|
Server 0.0.1
HTTP/REST server implementation
|
00001 00023 #include <poll.h> 00024 #include <errno.h> 00025 00026 #include "server.h" 00027 #include "logger.h" 00028 00029 #include "utils/signalHandling.h" 00030 00031 #define POLLFD(ptr) ((struct pollfd *)(ptr)) 00032 00033 int 00034 serverPoll(Server this) { 00035 int events; 00036 00040 struct pollfd * fda = &(this->fds[2]); 00041 struct pollfd * fdb = &(this->fds[this->nfds-1]); 00042 00043 while (fda <= fdb) { 00044 while (0 == fdb->fd && fda <= fdb) { 00045 fdb--; 00046 this->nfds--; 00047 } 00048 00049 while (0 != fda->fd && fda <= fdb) fda++; 00050 00051 if (fda < fdb) { 00052 memcpy(fda, fdb, sizeof(struct pollfd)); 00053 fdb--; 00054 this->nfds--; 00055 } 00056 } 00057 00058 /* 00059 * wait for handles to become ready 00060 */ 00061 if (-1 == (events = poll(this->fds, this->nfds, -1))) { 00062 switch (errno) { 00063 default: 00064 case EBADF: 00065 case EINVAL: 00066 case ENOMEM: 00067 doShutdown = 1; 00068 // DROP THROUGH 00069 00070 case EINTR: 00071 loggerLog(this->logger, LOGGER_CRIT, 00072 "poll systemcall failed: [%s] - service terminated", 00073 strerror(errno)); 00074 } 00075 } 00076 00077 return events; 00078 } 00079 00080 // vim: set ts=4 sw=4: