Fix some of the queue logic

This commit is contained in:
Christopher Wellons 2019-02-05 23:56:40 -05:00
parent 31b5d6b832
commit 9900764488

View File

@ -140,13 +140,19 @@ queue_remove(struct queue *q, int fd)
* is virtually always one of the first few elements. * is virtually always one of the first few elements.
*/ */
struct client *c; struct client *c;
struct client **prev = &q->head; struct client *prev = 0;
for (c = q->head; c; prev = &c->next, c = c->next) { for (c = q->head; c; prev = c, c = c->next) {
if (c->fd == fd) { if (c->fd == fd) {
q->length--; if (!--q->length) {
if (q->tail == c) q->head = q->tail = 0;
q->tail = 0; } else if (q->tail == c) {
*prev = c->next; q->tail = prev;
prev->next = 0;
} else if (prev) {
prev->next = c->next;
} else {
q->head = c->next;
}
c->next = 0; c->next = 0;
break; break;
} }
@ -666,10 +672,10 @@ main(int argc, char **argv)
fprintf(stderr, "endlessh: warning: out of memory\n"); fprintf(stderr, "endlessh: warning: out of memory\n");
close(fd); close(fd);
} }
queue_append(queue, client);
logmsg(LOG_INFO, "ACCEPT host=%s port=%d fd=%d n=%d/%d", logmsg(LOG_INFO, "ACCEPT host=%s port=%d fd=%d n=%d/%d",
client->ipaddr, client->port, client->fd, client->ipaddr, client->port, client->fd,
queue->length, config.max_clients); queue->length, config.max_clients);
queue_append(queue, client);
} }
} }