remove arg from mod_etype, fix auto if TFO enabled

This commit is contained in:
ruti 2024-05-04 22:18:43 +03:00
parent 0f67d56be4
commit 6651427f3a
4 changed files with 21 additions and 41 deletions

30
conev.c
View File

@ -55,18 +55,15 @@ struct eval *add_event(struct poolhd *pool, enum eid type,
val->type = type;
#ifndef NOEPOLL
struct epoll_event ev = {
EPOLLIN | EPOLLERR | EPOLLRDHUP | e, {val}
};
struct epoll_event ev = { .events = e, .data = {val} };
if (epoll_ctl(pool->efd, EPOLL_CTL_ADD, fd, &ev)) {
return 0;
}
val->events = ev.events;
#else
struct pollfd *pfd = &(pool->pevents[pool->count]);
pfd->fd = fd;
pfd->events = POLLIN | e;
pfd->events = e;
pfd->revents = 0;
#endif
@ -123,15 +120,9 @@ void destroy_pool(struct poolhd *pool)
val->buff.data = 0;
}
}
if (pool->items) {
free(pool->items);
}
if (pool->links) {
free(pool->links);
}
if (pool->pevents) {
free(pool->pevents);
}
#ifndef NOEPOLL
if (pool->efd)
close(pool->efd);
@ -167,16 +158,11 @@ struct eval *next_event(struct poolhd *pool, int *offs, int *type)
}
int mod_etype(struct poolhd *pool, struct eval *val, int type, char add)
int mod_etype(struct poolhd *pool, struct eval *val, int type)
{
struct epoll_event ev = {
.events = val->events, .data = {val}
.events = type, .data = {val}
};
if (add)
ev.events |= type;
else
ev.events &= ~type;
val->events = ev.events;
return epoll_ctl(pool->efd, EPOLL_CTL_MOD, val->fd, &ev);
}
@ -210,13 +196,9 @@ struct eval *next_event(struct poolhd *pool, int *offs, int *typel)
}
int mod_etype(struct poolhd *pool, struct eval *val, int type, char add)
int mod_etype(struct poolhd *pool, struct eval *val, int type)
{
int index = val->index;
if (add)
pool->pevents[index].events |= type;
else
pool->pevents[index].events &= ~type;
pool->pevents[val->index].events = type;
return 0;
}
#endif

View File

@ -66,6 +66,7 @@ struct buffer {
struct eval {
int fd;
int index;
unsigned int mod_iter;
enum eid type;
struct eval *pair;
struct buffer buff;
@ -77,10 +78,6 @@ struct eval {
ssize_t recv_count;
int attempt;
char cache;
#ifndef NOEPOLL
uint32_t events;
#endif
unsigned int mod_iter;
};
struct poolhd {
@ -109,4 +106,4 @@ void destroy_pool(struct poolhd *pool);
struct eval *next_event(struct poolhd *pool, int *offs, int *type);
int mod_etype(struct poolhd *pool, struct eval *val, int type, char rm);
int mod_etype(struct poolhd *pool, struct eval *val, int type);

View File

@ -244,6 +244,7 @@ int on_tunnel_check(struct poolhd *pool, struct eval *val,
uniperror("recv");
switch (get_e()) {
case ECONNRESET:
case ECONNREFUSED:
case ETIMEDOUT:
break;
default: return -1;
@ -291,7 +292,7 @@ int on_desync(struct poolhd *pool, struct eval *val,
char *buffer, size_t bfsize)
{
if (val->flag == FLAG_CONN) {
if (mod_etype(pool, val, POLLOUT, 0)) {
if (mod_etype(pool, val, POLLIN)) {
uniperror("mod_etype");
return -1;
}
@ -349,7 +350,7 @@ int on_desync(struct poolhd *pool, struct eval *val,
}
if (sn < n) {
val->buff.offset = sn;
if (mod_etype(pool, val->pair, POLLOUT, 1)) {
if (mod_etype(pool, val->pair, POLLOUT)) {
uniperror("mod_etype");
return -1;
}

14
proxy.c
View File

@ -520,7 +520,7 @@ static inline int on_accept(struct poolhd *pool, struct eval *val)
close(c);
continue;
}
if (!(rval = add_event(pool, EV_REQUEST, c, 0))) {
if (!(rval = add_event(pool, EV_REQUEST, c, POLLIN))) {
close(c);
continue;
}
@ -556,8 +556,8 @@ int on_tunnel(struct poolhd *pool, struct eval *val,
val->buff.data = 0;
val->buff.size = 0;
if (mod_etype(pool, val, POLLIN, 1) ||
mod_etype(pool, pair, POLLOUT, 0)) {
if (mod_etype(pool, val, POLLIN) ||
mod_etype(pool, pair, POLLIN)) {
uniperror("mod_etype");
return -1;
}
@ -590,8 +590,8 @@ int on_tunnel(struct poolhd *pool, struct eval *val,
}
memcpy(val->buff.data, buffer + sn, val->buff.size);
if (mod_etype(pool, val, POLLIN, 0) ||
mod_etype(pool, pair, POLLOUT, 1)) {
if (mod_etype(pool, val, 0) ||
mod_etype(pool, pair, POLLOUT)) {
uniperror("mod_etype");
return -1;
}
@ -757,7 +757,7 @@ static inline int on_connect(struct poolhd *pool, struct eval *val, int e)
}
}
else {
if (mod_etype(pool, val, POLLOUT, 0)) {
if (mod_etype(pool, val, POLLIN)) {
uniperror("mod_etype");
return -1;
}
@ -783,7 +783,7 @@ int event_loop(int srvfd)
close(srvfd);
return -1;
}
if (!add_event(pool, EV_ACCEPT, srvfd, 0)) {
if (!add_event(pool, EV_ACCEPT, srvfd, POLLIN)) {
uniperror("add event");
destroy_pool(pool);
close(srvfd);