Close all connections on exit
This commit is contained in:
@@ -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)
|
||||
|
@@ -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);
|
||||
|
@@ -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;
|
||||
|
Reference in New Issue
Block a user