Browse Source

Tidy up receiver loop

master
Con Kolivas 10 years ago
parent
commit
d42185a5eb
  1. 35
      src/connector.c

35
src/connector.c

@ -296,8 +296,7 @@ reparse:
void *receiver(void *arg) void *receiver(void *arg)
{ {
conn_instance_t *ci = (conn_instance_t *)arg; conn_instance_t *ci = (conn_instance_t *)arg;
struct epoll_event *events, event; struct epoll_event event;
client_instance_t *client;
bool maxconn = true; bool maxconn = true;
int ret, epfd; int ret, epfd;
@ -310,19 +309,21 @@ void *receiver(void *arg)
} }
event.data.fd = ci->serverfd; event.data.fd = ci->serverfd;
event.events = EPOLLIN; event.events = EPOLLIN;
events = ckalloc(sizeof(struct epoll_event));
ret = epoll_ctl(epfd, EPOLL_CTL_ADD, ci->serverfd, &event); ret = epoll_ctl(epfd, EPOLL_CTL_ADD, ci->serverfd, &event);
if (ret < 0) { if (ret < 0) {
LOGEMERG("FATAL: Failed to add epfd %d to epoll_ctl", epfd); LOGEMERG("FATAL: Failed to add epfd %d to epoll_ctl", epfd);
goto out; return NULL;
} }
repoll:
while (!ci->accept) while (42) {
client_instance_t *client;
while (unlikely(!ci->accept))
cksleep_ms(100); cksleep_ms(100);
ret = epoll_wait(epfd, events, 1, 1000); ret = epoll_wait(epfd, &event, 1, 1000);
if (unlikely(ret == -1)) { if (unlikely(ret == -1)) {
LOGEMERG("FATAL: Failed to epoll_wait in receiver"); LOGEMERG("FATAL: Failed to epoll_wait in receiver");
goto out; break;
} }
if (unlikely(!ret)) { if (unlikely(!ret)) {
if (unlikely(maxconn)) { if (unlikely(maxconn)) {
@ -334,27 +335,25 @@ repoll:
maxconn = false; maxconn = false;
listen(ci->serverfd, 0); listen(ci->serverfd, 0);
} }
goto repoll; continue;
} }
if (events->data.fd == ci->serverfd) { if (event.data.fd == ci->serverfd) {
ret = accept_client(ci, epfd); ret = accept_client(ci, epfd);
if (unlikely(ret < 0)) { if (unlikely(ret < 0)) {
LOGEMERG("FATAL: Failed to accept_client in receiver"); LOGEMERG("FATAL: Failed to accept_client in receiver");
goto out; break;
} }
goto repoll; continue;
} }
client = events->data.ptr; client = event.data.ptr;
if ((events->events & EPOLLERR) || (events->events & EPOLLHUP)) { if ((event.events & EPOLLERR) || (event.events & EPOLLHUP)) {
/* Client disconnected */ /* Client disconnected */
LOGDEBUG("Client fd %d HUP in epoll", client->fd); LOGDEBUG("Client fd %d HUP in epoll", client->fd);
invalidate_client(ci->pi->ckp, ci, client); invalidate_client(ci->pi->ckp, ci, client);
goto repoll; continue;
} }
parse_client_msg(ci, client); parse_client_msg(ci, client);
goto repoll; }
out:
free(events);
return NULL; return NULL;
} }

Loading…
Cancel
Save