4 changed files with 106 additions and 96 deletions
@ -0,0 +1,25 @@ |
|||
static |
|||
void |
|||
serverHandleAccept(Server this) |
|||
{ |
|||
if (0 != ((this->fds)[0].revents & POLLIN)) { |
|||
char remoteAddr[16] = ""; |
|||
Sock acc; |
|||
|
|||
acc = socketAccept(this->sock, remoteAddr); |
|||
|
|||
if (-1 != acc->handle) { |
|||
(this->conns)[this->nfds].sock = acc; // save the socket handle |
|||
(this->conns)[this->nfds].reader = clone(this->reader); // clone reader |
|||
(this->fds)[this->nfds].fd = acc->handle; |
|||
(this->fds)[this->nfds].events = POLLIN; |
|||
this->nfds++; |
|||
} else { |
|||
delete(&acc); |
|||
} |
|||
|
|||
(this->fds)[0].revents |= POLLIN; |
|||
} |
|||
} |
|||
|
|||
// vim: set ts=4 sw=4: |
|||
@ -0,0 +1,29 @@ |
|||
static |
|||
int |
|||
serverPoll(Server this) { |
|||
int events; |
|||
|
|||
/* |
|||
* 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 */ |
|||
} |
|||
} |
|||
|
|||
return events; |
|||
} |
|||
|
|||
// vim: set ts=4 sw=4: |
|||
@ -0,0 +1,42 @@ |
|||
static |
|||
int |
|||
serverRead(Server this) |
|||
{ |
|||
unsigned int i; |
|||
|
|||
for (i=1; i<this->nfds; i++) { |
|||
if (0 != ((this->fds)[i].revents & POLLIN)) { |
|||
if (NULL == (this->conns)[i].reader) { |
|||
loggerLog( |
|||
this->logger, |
|||
LOGGER_INFO, |
|||
"initialization error: NULL reader"); |
|||
serverCloseConn(this, i); |
|||
} |
|||
|
|||
switch (streamReaderRead((this->conns)[i].reader, (this->fds)[i].fd)) { |
|||
case 0: |
|||
/* |
|||
* normal close: write remaining data |
|||
* @TODO: actually we have no remaining data here.... |
|||
*/ |
|||
/* DROP-THROUGH */ |
|||
|
|||
case -1: |
|||
/* |
|||
* read failure / close connection |
|||
*/ |
|||
loggerLog(this->logger, LOGGER_INFO, "connection closed..."); |
|||
serverCloseConn(this, i); |
|||
break; |
|||
|
|||
default: |
|||
break; |
|||
} |
|||
} |
|||
} |
|||
|
|||
return 0; |
|||
} |
|||
|
|||
// vim: set ts=4 sw=4: |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue