From: claudio Date: Thu, 8 Apr 2021 16:56:34 +0000 (+0000) Subject: Change the order of the poll loop to first process active http connections X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=9b8c2dd80baa30a313dd2c9f2edfe21c2026e78e;p=openbsd Change the order of the poll loop to first process active http connections and then accept new ones. This way there is no risk of processing a new connection before poll() was called. OK tb@ as part of a larger diff --- diff --git a/usr.sbin/rpki-client/http.c b/usr.sbin/rpki-client/http.c index 7b6aa68e383..3b2f1099a68 100644 --- a/usr.sbin/rpki-client/http.c +++ b/usr.sbin/rpki-client/http.c @@ -1,4 +1,4 @@ -/* $OpenBSD: http.c,v 1.23 2021/04/08 16:46:59 claudio Exp $ */ +/* $OpenBSD: http.c,v 1.24 2021/04/08 16:56:34 claudio Exp $ */ /* * Copyright (c) 2020 Nils Fisher * Copyright (c) 2020 Claudio Jeker @@ -1222,6 +1222,18 @@ proc_http(char *bind_addr, int fd) err(1, "write"); } } + for (i = 0; i < MAX_CONNECTIONS; i++) { + struct http_connection *conn = http_conns[i]; + + if (conn == NULL) + continue; + /* event not ready */ + if (!(pfds[i].revents & (conn->events | POLLHUP))) + continue; + + if (http_do(conn) == -1) + http_conns[i] = NULL; + } if (pfds[MAX_CONNECTIONS].revents & POLLIN) { struct http_connection *h; size_t id; @@ -1245,18 +1257,6 @@ proc_http(char *bind_addr, int fd) } } } - for (i = 0; i < MAX_CONNECTIONS; i++) { - struct http_connection *conn = http_conns[i]; - - if (conn == NULL) - continue; - /* event not ready */ - if (!(pfds[i].revents & (conn->events | POLLHUP))) - continue; - - if (http_do(conn) == -1) - http_conns[i] = NULL; - } } exit(0);