Close all connections on exit

This commit is contained in:
2023-01-04 00:40:09 +01:00
parent d8fd552b40
commit c67edd4195
8 changed files with 54 additions and 22 deletions

View File

@@ -46,6 +46,22 @@ void proxy_unload(void) {
free(proxies);
}
void proxy_close_all(void) {
int n = 0;
for (int i = 0; i < CONFIG_MAX_HOST_CONFIG; i++) {
host_config_t *hc = &config.hosts[i];
if (hc->type == CONFIG_TYPE_UNSET) break;
if (hc->type != CONFIG_TYPE_REVERSE_PROXY) continue;
n++;
}
proxy_ctx_t *ptr = proxies;
for (int i = 0; i < MAX_PROXY_CNX_PER_HOST * n; i++, ptr++) {
if (ptr->initialized)
proxy_close(ptr);
}
}
static proxy_ctx_t *proxy_get_by_conf(host_config_t *conf) {
// TODO locking void *proxies
int n = 0;
@@ -225,6 +241,7 @@ int proxy_init(proxy_ctx_t **proxy_ptr, http_req *req, http_res *res, http_statu
*proxy_ptr = proxy_get_by_conf(conf);
proxy_ctx_t *proxy = *proxy_ptr;
proxy->client = NULL;
proxy->in_use = 1;
if (proxy->initialized && sock_has_pending(&proxy->proxy) == 0)

View File

@@ -25,12 +25,15 @@ typedef struct {
unsigned char initialized:1, in_use:1;
sock proxy;
char *host;
void *client;
} proxy_ctx_t;
int proxy_preload(void);
void proxy_unload(void);
void proxy_close_all(void);
int proxy_request_header(http_req *req, sock *sock);
int proxy_response_header(http_req *req, http_res *res, host_config_t *conf);

View File

@@ -14,7 +14,6 @@
#include <string.h>
#include <sys/socket.h>
#include <unistd.h>
#include <poll.h>
int sock_enc_error(sock *s) {
@@ -142,7 +141,7 @@ long sock_splice_chunked(sock *dst, sock *src, void *buf, unsigned long buf_len)
int sock_close(sock *s) {
int e = errno;
if ((int) s->enc && s->ssl != NULL) {
if (s->enc && s->ssl != NULL) {
if (s->_last_ret >= 0) SSL_shutdown(s->ssl);
SSL_free(s->ssl);
s->ssl = NULL;