Browse Source

Optimise receiver loop

master
Con Kolivas 11 years ago
parent
commit
bab86af441
  1. 14
      src/connector.c

14
src/connector.c

@ -173,18 +173,17 @@ 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;
client_instance_t *client, *tmp, *tmpa; client_instance_t *client;
struct pollfd fds[65536]; struct pollfd fds[65536];
int ret, nfds, i; int ret, nfds, i;
rename_proc("receiver"); rename_proc("receiver");
retry: retry:
memset(fds, 0, sizeof(fds));
nfds = 0; nfds = 0;
ck_rlock(&ci->lock); ck_rlock(&ci->lock);
HASH_ITER(hh, clients, client, tmp) { for (client = clients; client != NULL; client = client->hh.next) {
/* Invalid client */ /* Invalid client */
if (client->fd == -1) if (client->fd == -1)
continue; continue;
@ -198,10 +197,11 @@ retry:
cksleep_ms(100); cksleep_ms(100);
goto retry; goto retry;
} }
repoll:
ret = poll(fds, nfds, 1000); ret = poll(fds, nfds, 1000);
if (ret < 0) { if (ret < 0) {
if (interrupted()) if (interrupted())
goto retry; goto repoll;
LOGERR("Failed to poll in receiver"); LOGERR("Failed to poll in receiver");
goto out; goto out;
} }
@ -215,11 +215,9 @@ retry:
client = NULL; client = NULL;
ck_rlock(&ci->lock); ck_rlock(&ci->lock);
HASH_ITER(hh, clients, tmp, tmpa) { for (client = clients; client != NULL; client = client->hh.next) {
if (tmp->fd == fds[i].fd) { if (client->fd == fds[i].fd)
client = tmp;
break; break;
}
} }
ck_runlock(&ci->lock); ck_runlock(&ci->lock);

Loading…
Cancel
Save