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
This commit is contained in:
Lurker00 2024-09-13 22:23:04 +03:00 committed by GitHub
parent 9b685ecbb9
commit 193737173b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 13 additions and 8 deletions

View file

@ -4,12 +4,14 @@
#include <string.h> #include <string.h>
#include <limits.h> #include <limits.h>
#include <assert.h> #include <assert.h>
#include "error.h"
struct poolhd *init_pool(int count) struct poolhd *init_pool(int count)
{ {
struct poolhd *pool = calloc(sizeof(struct poolhd), 1); struct poolhd *pool = calloc(sizeof(struct poolhd), 1);
if (!pool) { if (!pool) {
uniperror("init pool");
return 0; return 0;
} }
pool->max = count; pool->max = count;
@ -29,6 +31,7 @@ struct poolhd *init_pool(int count)
pool->items = malloc(sizeof(*pool->items) * count); pool->items = malloc(sizeof(*pool->items) * count);
if (!pool->pevents || !pool->links || !pool->items) { if (!pool->pevents || !pool->links || !pool->items) {
uniperror("init pool");
destroy_pool(pool); destroy_pool(pool);
return 0; return 0;
} }
@ -45,6 +48,7 @@ struct eval *add_event(struct poolhd *pool, enum eid type,
{ {
assert(fd > 0); assert(fd > 0);
if (pool->count >= pool->max) { if (pool->count >= pool->max) {
LOG(LOG_E, "add_event: pool is full\n");
return 0; return 0;
} }
struct eval *val = pool->links[pool->count]; struct eval *val = pool->links[pool->count];
@ -58,6 +62,7 @@ struct eval *add_event(struct poolhd *pool, enum eid type,
#ifndef NOEPOLL #ifndef NOEPOLL
struct epoll_event ev = { .events = EPOLLRDHUP | e, .data = {val} }; struct epoll_event ev = { .events = EPOLLRDHUP | e, .data = {val} };
if (epoll_ctl(pool->efd, EPOLL_CTL_ADD, fd, &ev)) { if (epoll_ctl(pool->efd, EPOLL_CTL_ADD, fd, &ev)) {
uniperror("add event");
return 0; return 0;
} }
#else #else

View file

@ -11,6 +11,8 @@
#include <android/log.h> #include <android/log.h>
#endif #endif
#include "params.h"
#ifdef _WIN32 #ifdef _WIN32
#define get_e() \ #define get_e() \
unie(WSAGetLastError()) unie(WSAGetLastError())

View file

@ -614,7 +614,7 @@ static inline int on_accept(struct poolhd *pool, struct eval *val)
rval->in6 = client.in6; rval->in6 = client.in6;
#ifdef __linux__ #ifdef __linux__
if (params.transparent && transp_conn(pool, rval) < 0) { if (params.transparent && transp_conn(pool, rval) < 0) {
close(c); del_event(pool, rval);
continue; continue;
} }
#endif #endif
@ -904,12 +904,10 @@ int event_loop(int srvfd)
struct poolhd *pool = init_pool(params.max_open * 2 + 1); struct poolhd *pool = init_pool(params.max_open * 2 + 1);
if (!pool) { if (!pool) {
uniperror("init pool");
close(srvfd); close(srvfd);
return -1; return -1;
} }
if (!add_event(pool, EV_ACCEPT, srvfd, POLLIN)) { if (!add_event(pool, EV_ACCEPT, srvfd, POLLIN)) {
uniperror("add event");
destroy_pool(pool); destroy_pool(pool);
close(srvfd); close(srvfd);
return -1; return -1;