From 193737173b418f5a4f7173e2062d69d59c0dd0e9 Mon Sep 17 00:00:00 2001 From: Lurker00 Date: Fri, 13 Sep 2024 22:23:04 +0300 Subject: [PATCH] Delete broken event, log "pull is full" error (#132) * Delete event with closed socket * Log "pull is full" error * Error logging inside add_event and init_pool --- conev.c | 15 ++++++++++----- error.h | 2 ++ proxy.c | 4 +--- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/conev.c b/conev.c index e826ee2..41fa47a 100644 --- a/conev.c +++ b/conev.c @@ -4,18 +4,20 @@ #include #include #include +#include "error.h" struct poolhd *init_pool(int count) { struct poolhd *pool = calloc(sizeof(struct poolhd), 1); if (!pool) { + uniperror("init pool"); return 0; } pool->max = count; pool->count = 0; pool->iters = 0; - + #ifndef NOEPOLL int efd = epoll_create(count); if (efd < 0) { @@ -27,8 +29,9 @@ struct poolhd *init_pool(int count) pool->pevents = malloc(sizeof(*pool->pevents) * count); pool->links = malloc(sizeof(*pool->links) * count); pool->items = malloc(sizeof(*pool->items) * count); - + if (!pool->pevents || !pool->links || !pool->items) { + uniperror("init pool"); destroy_pool(pool); return 0; } @@ -45,19 +48,21 @@ struct eval *add_event(struct poolhd *pool, enum eid type, { assert(fd > 0); if (pool->count >= pool->max) { + LOG(LOG_E, "add_event: pool is full\n"); return 0; } struct eval *val = pool->links[pool->count]; memset(val, 0, sizeof(*val)); - + val->mod_iter = pool->iters; val->fd = fd; val->index = pool->count; val->type = type; - + #ifndef NOEPOLL struct epoll_event ev = { .events = EPOLLRDHUP | e, .data = {val} }; if (epoll_ctl(pool->efd, EPOLL_CTL_ADD, fd, &ev)) { + uniperror("add event"); return 0; } #else @@ -67,7 +72,7 @@ struct eval *add_event(struct poolhd *pool, enum eid type, pfd->events = POLLRDHUP | e; pfd->revents = 0; #endif - + pool->count++; return val; } diff --git a/error.h b/error.h index bd5e372..5eea82b 100644 --- a/error.h +++ b/error.h @@ -11,6 +11,8 @@ #include #endif +#include "params.h" + #ifdef _WIN32 #define get_e() \ unie(WSAGetLastError()) diff --git a/proxy.c b/proxy.c index 66c8efc..ed9e343 100644 --- a/proxy.c +++ b/proxy.c @@ -614,7 +614,7 @@ static inline int on_accept(struct poolhd *pool, struct eval *val) rval->in6 = client.in6; #ifdef __linux__ if (params.transparent && transp_conn(pool, rval) < 0) { - close(c); + del_event(pool, rval); continue; } #endif @@ -904,12 +904,10 @@ int event_loop(int srvfd) struct poolhd *pool = init_pool(params.max_open * 2 + 1); if (!pool) { - uniperror("init pool"); close(srvfd); return -1; } if (!add_event(pool, EV_ACCEPT, srvfd, POLLIN)) { - uniperror("add event"); destroy_pool(pool); close(srvfd); return -1;