mirror of
https://github.com/hufrea/byedpi.git
synced 2024-12-22 14:25:44 +00:00
remove arg from mod_etype, fix auto if TFO enabled
This commit is contained in:
parent
0f67d56be4
commit
6651427f3a
36
conev.c
36
conev.c
@ -55,18 +55,15 @@ struct eval *add_event(struct poolhd *pool, enum eid type,
|
|||||||
val->type = type;
|
val->type = type;
|
||||||
|
|
||||||
#ifndef NOEPOLL
|
#ifndef NOEPOLL
|
||||||
struct epoll_event ev = {
|
struct epoll_event ev = { .events = e, .data = {val} };
|
||||||
EPOLLIN | EPOLLERR | EPOLLRDHUP | e, {val}
|
|
||||||
};
|
|
||||||
if (epoll_ctl(pool->efd, EPOLL_CTL_ADD, fd, &ev)) {
|
if (epoll_ctl(pool->efd, EPOLL_CTL_ADD, fd, &ev)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
val->events = ev.events;
|
|
||||||
#else
|
#else
|
||||||
struct pollfd *pfd = &(pool->pevents[pool->count]);
|
struct pollfd *pfd = &(pool->pevents[pool->count]);
|
||||||
|
|
||||||
pfd->fd = fd;
|
pfd->fd = fd;
|
||||||
pfd->events = POLLIN | e;
|
pfd->events = e;
|
||||||
pfd->revents = 0;
|
pfd->revents = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -123,15 +120,9 @@ void destroy_pool(struct poolhd *pool)
|
|||||||
val->buff.data = 0;
|
val->buff.data = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (pool->items) {
|
free(pool->items);
|
||||||
free(pool->items);
|
free(pool->links);
|
||||||
}
|
free(pool->pevents);
|
||||||
if (pool->links) {
|
|
||||||
free(pool->links);
|
|
||||||
}
|
|
||||||
if (pool->pevents) {
|
|
||||||
free(pool->pevents);
|
|
||||||
}
|
|
||||||
#ifndef NOEPOLL
|
#ifndef NOEPOLL
|
||||||
if (pool->efd)
|
if (pool->efd)
|
||||||
close(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 = {
|
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);
|
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;
|
pool->pevents[val->index].events = type;
|
||||||
if (add)
|
|
||||||
pool->pevents[index].events |= type;
|
|
||||||
else
|
|
||||||
pool->pevents[index].events &= ~type;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
7
conev.h
7
conev.h
@ -66,6 +66,7 @@ struct buffer {
|
|||||||
struct eval {
|
struct eval {
|
||||||
int fd;
|
int fd;
|
||||||
int index;
|
int index;
|
||||||
|
unsigned int mod_iter;
|
||||||
enum eid type;
|
enum eid type;
|
||||||
struct eval *pair;
|
struct eval *pair;
|
||||||
struct buffer buff;
|
struct buffer buff;
|
||||||
@ -77,10 +78,6 @@ struct eval {
|
|||||||
ssize_t recv_count;
|
ssize_t recv_count;
|
||||||
int attempt;
|
int attempt;
|
||||||
char cache;
|
char cache;
|
||||||
#ifndef NOEPOLL
|
|
||||||
uint32_t events;
|
|
||||||
#endif
|
|
||||||
unsigned int mod_iter;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct poolhd {
|
struct poolhd {
|
||||||
@ -109,4 +106,4 @@ void destroy_pool(struct poolhd *pool);
|
|||||||
|
|
||||||
struct eval *next_event(struct poolhd *pool, int *offs, int *type);
|
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);
|
||||||
|
5
extend.c
5
extend.c
@ -244,6 +244,7 @@ int on_tunnel_check(struct poolhd *pool, struct eval *val,
|
|||||||
uniperror("recv");
|
uniperror("recv");
|
||||||
switch (get_e()) {
|
switch (get_e()) {
|
||||||
case ECONNRESET:
|
case ECONNRESET:
|
||||||
|
case ECONNREFUSED:
|
||||||
case ETIMEDOUT:
|
case ETIMEDOUT:
|
||||||
break;
|
break;
|
||||||
default: return -1;
|
default: return -1;
|
||||||
@ -291,7 +292,7 @@ int on_desync(struct poolhd *pool, struct eval *val,
|
|||||||
char *buffer, size_t bfsize)
|
char *buffer, size_t bfsize)
|
||||||
{
|
{
|
||||||
if (val->flag == FLAG_CONN) {
|
if (val->flag == FLAG_CONN) {
|
||||||
if (mod_etype(pool, val, POLLOUT, 0)) {
|
if (mod_etype(pool, val, POLLIN)) {
|
||||||
uniperror("mod_etype");
|
uniperror("mod_etype");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -349,7 +350,7 @@ int on_desync(struct poolhd *pool, struct eval *val,
|
|||||||
}
|
}
|
||||||
if (sn < n) {
|
if (sn < n) {
|
||||||
val->buff.offset = sn;
|
val->buff.offset = sn;
|
||||||
if (mod_etype(pool, val->pair, POLLOUT, 1)) {
|
if (mod_etype(pool, val->pair, POLLOUT)) {
|
||||||
uniperror("mod_etype");
|
uniperror("mod_etype");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
14
proxy.c
14
proxy.c
@ -520,7 +520,7 @@ static inline int on_accept(struct poolhd *pool, struct eval *val)
|
|||||||
close(c);
|
close(c);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!(rval = add_event(pool, EV_REQUEST, c, 0))) {
|
if (!(rval = add_event(pool, EV_REQUEST, c, POLLIN))) {
|
||||||
close(c);
|
close(c);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -556,8 +556,8 @@ int on_tunnel(struct poolhd *pool, struct eval *val,
|
|||||||
val->buff.data = 0;
|
val->buff.data = 0;
|
||||||
val->buff.size = 0;
|
val->buff.size = 0;
|
||||||
|
|
||||||
if (mod_etype(pool, val, POLLIN, 1) ||
|
if (mod_etype(pool, val, POLLIN) ||
|
||||||
mod_etype(pool, pair, POLLOUT, 0)) {
|
mod_etype(pool, pair, POLLIN)) {
|
||||||
uniperror("mod_etype");
|
uniperror("mod_etype");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -590,8 +590,8 @@ int on_tunnel(struct poolhd *pool, struct eval *val,
|
|||||||
}
|
}
|
||||||
memcpy(val->buff.data, buffer + sn, val->buff.size);
|
memcpy(val->buff.data, buffer + sn, val->buff.size);
|
||||||
|
|
||||||
if (mod_etype(pool, val, POLLIN, 0) ||
|
if (mod_etype(pool, val, 0) ||
|
||||||
mod_etype(pool, pair, POLLOUT, 1)) {
|
mod_etype(pool, pair, POLLOUT)) {
|
||||||
uniperror("mod_etype");
|
uniperror("mod_etype");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -757,7 +757,7 @@ static inline int on_connect(struct poolhd *pool, struct eval *val, int e)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (mod_etype(pool, val, POLLOUT, 0)) {
|
if (mod_etype(pool, val, POLLIN)) {
|
||||||
uniperror("mod_etype");
|
uniperror("mod_etype");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -783,7 +783,7 @@ int event_loop(int srvfd)
|
|||||||
close(srvfd);
|
close(srvfd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (!add_event(pool, EV_ACCEPT, srvfd, 0)) {
|
if (!add_event(pool, EV_ACCEPT, srvfd, POLLIN)) {
|
||||||
uniperror("add event");
|
uniperror("add event");
|
||||||
destroy_pool(pool);
|
destroy_pool(pool);
|
||||||
close(srvfd);
|
close(srvfd);
|
||||||
|
Loading…
Reference in New Issue
Block a user