mirror of
https://github.com/hufrea/byedpi.git
synced 2024-12-21 22:05:32 +00:00
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:
parent
9b685ecbb9
commit
193737173b
15
conev.c
15
conev.c
@ -4,18 +4,20 @@
|
|||||||
#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;
|
||||||
pool->count = 0;
|
pool->count = 0;
|
||||||
pool->iters = 0;
|
pool->iters = 0;
|
||||||
|
|
||||||
#ifndef NOEPOLL
|
#ifndef NOEPOLL
|
||||||
int efd = epoll_create(count);
|
int efd = epoll_create(count);
|
||||||
if (efd < 0) {
|
if (efd < 0) {
|
||||||
@ -27,8 +29,9 @@ struct poolhd *init_pool(int count)
|
|||||||
pool->pevents = malloc(sizeof(*pool->pevents) * count);
|
pool->pevents = malloc(sizeof(*pool->pevents) * count);
|
||||||
pool->links = malloc(sizeof(*pool->links) * count);
|
pool->links = malloc(sizeof(*pool->links) * 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,19 +48,21 @@ 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];
|
||||||
memset(val, 0, sizeof(*val));
|
memset(val, 0, sizeof(*val));
|
||||||
|
|
||||||
val->mod_iter = pool->iters;
|
val->mod_iter = pool->iters;
|
||||||
val->fd = fd;
|
val->fd = fd;
|
||||||
val->index = pool->count;
|
val->index = pool->count;
|
||||||
val->type = type;
|
val->type = 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
|
||||||
@ -67,7 +72,7 @@ struct eval *add_event(struct poolhd *pool, enum eid type,
|
|||||||
pfd->events = POLLRDHUP | e;
|
pfd->events = POLLRDHUP | e;
|
||||||
pfd->revents = 0;
|
pfd->revents = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
pool->count++;
|
pool->count++;
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
2
error.h
2
error.h
@ -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())
|
||||||
|
4
proxy.c
4
proxy.c
@ -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;
|
||||||
|
Loading…
Reference in New Issue
Block a user