Import LIST_FOREACH_SAFE macro from FreeBSD.

This commit is contained in:
Emil Mikulic
2003-11-18 08:28:33 +00:00
parent 34db7c9e68
commit 1e3b874dca

View File

@@ -22,7 +22,6 @@
* x Detect Content-Type from a list of content types. * x Detect Content-Type from a list of content types.
* x Log Referer, User-Agent. * x Log Referer, User-Agent.
* x Ensure URIs requested are safe. * x Ensure URIs requested are safe.
* . Import new LIST_macros, use FOREACH
*/ */
#ifdef __linux #ifdef __linux
@@ -58,7 +57,7 @@
/* --------------------------------------------------------------------------- /* ---------------------------------------------------------------------------
* LIST_* macros taken from FreeBSD's src/sys/sys/queue.h,v 1.32.2.7 * LIST_* macros taken from FreeBSD's src/sys/sys/queue.h,v 1.56
* Copyright (c) 1991, 1993 * Copyright (c) 1991, 1993
* The Regents of the University of California. All rights reserved. * The Regents of the University of California. All rights reserved.
* *
@@ -88,6 +87,11 @@ struct { \
(var); \ (var); \
(var) = LIST_NEXT((var), field)) (var) = LIST_NEXT((var), field))
#define LIST_FOREACH_SAFE(var, head, field, tvar) \
for ((var) = LIST_FIRST((head)); \
(var) && ((tvar) = LIST_NEXT((var), field), 1); \
(var) = (tvar))
#define LIST_INIT(head) do { \ #define LIST_INIT(head) do { \
LIST_FIRST((head)) = NULL; \ LIST_FIRST((head)) = NULL; \
} while (0) } while (0)
@@ -1615,7 +1619,7 @@ static void httpd_poll(void)
{ {
fd_set recv_set, send_set; fd_set recv_set, send_set;
int max_fd, select_ret; int max_fd, select_ret;
struct connection *conn; struct connection *conn, *next;
int bother_with_timeout = 0; int bother_with_timeout = 0;
struct timeval timeout; struct timeval timeout;
@@ -1632,11 +1636,8 @@ static void httpd_poll(void)
MAX_FD_SET(sockin, &recv_set); MAX_FD_SET(sockin, &recv_set);
conn = LIST_FIRST(&connlist); LIST_FOREACH_SAFE(conn, &connlist, entries, next)
while (conn != NULL)
{ {
struct connection *next = LIST_NEXT(conn, entries);
poll_check_timeout(conn); poll_check_timeout(conn);
switch (conn->state) switch (conn->state)
{ {
@@ -1661,8 +1662,6 @@ static void httpd_poll(void)
default: errx(1, "invalid state"); default: errx(1, "invalid state");
} }
conn = next;
} }
#undef MAX_FD_SET #undef MAX_FD_SET
@@ -1708,20 +1707,17 @@ static void httpd_poll(void)
*/ */
static void exit_quickly(int sig) static void exit_quickly(int sig)
{ {
struct connection *conn; struct connection *conn, *next;
size_t i; size_t i;
printf("\ncaught %s, cleaning up...", strsignal(sig)); fflush(stdout); printf("\ncaught %s, cleaning up...", strsignal(sig)); fflush(stdout);
/* close and free connections */ /* close and free connections */
conn = LIST_FIRST(&connlist); LIST_FOREACH_SAFE(conn, &connlist, entries, next)
while (conn != NULL)
{ {
struct connection *next = LIST_NEXT(conn, entries);
LIST_REMOVE(conn, entries); LIST_REMOVE(conn, entries);
log_connection(conn); log_connection(conn);
free_connection(conn); free_connection(conn);
free(conn); free(conn);
conn = next;
} }
close(sockin); close(sockin);
if (logfile != NULL) fclose(logfile); if (logfile != NULL) fclose(logfile);