mirror of
https://github.com/hufrea/byedpi.git
synced 2024-11-28 11:18:53 +03:00
fix: ignore closed connection, don't use mmap in ftob
This commit is contained in:
parent
74e90e9568
commit
e1b952cef6
4 changed files with 29 additions and 22 deletions
22
conev.c
22
conev.c
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
|
||||
|
||||
struct poolhd *init_pool(int count)
|
||||
|
@ -33,6 +34,7 @@ struct poolhd *init_pool(int count)
|
|||
for (int i = 0; i < count; i++) {
|
||||
pool->links[i] = &(pool->items[i]);
|
||||
}
|
||||
memset(pool->items, 0, sizeof(*pool->items));
|
||||
return pool;
|
||||
}
|
||||
|
||||
|
@ -40,9 +42,14 @@ struct poolhd *init_pool(int count)
|
|||
struct eval *add_event(struct poolhd *pool, enum eid type,
|
||||
int fd, int e)
|
||||
{
|
||||
if (pool->count >= pool->max)
|
||||
if (pool->count >= pool->max) {
|
||||
return 0;
|
||||
}
|
||||
struct eval *val = pool->links[pool->count];
|
||||
if (pool->iters &&
|
||||
val->del_iter == pool->iters) {
|
||||
return 0;
|
||||
}
|
||||
memset(val, 0, sizeof(*val));
|
||||
|
||||
val->fd = fd;
|
||||
|
@ -72,7 +79,7 @@ struct eval *add_event(struct poolhd *pool, enum eid type,
|
|||
|
||||
void del_event(struct poolhd *pool, struct eval *val)
|
||||
{
|
||||
if (!val->fd) {
|
||||
if (val->del_iter) {
|
||||
return;
|
||||
}
|
||||
if (val->buff.data) {
|
||||
|
@ -81,6 +88,7 @@ void del_event(struct poolhd *pool, struct eval *val)
|
|||
}
|
||||
close(val->fd);
|
||||
val->fd = 0;
|
||||
val->del_iter = pool->iters;
|
||||
pool->count--;
|
||||
|
||||
struct eval *ev = pool->links[pool->count];
|
||||
|
@ -147,6 +155,11 @@ struct eval *next_event(struct poolhd *pool, int *offs, int *type)
|
|||
}
|
||||
*offs = i - 1;
|
||||
*type = pool->pevents[i].events;
|
||||
|
||||
if (pool->iters == UINT_MAX) {
|
||||
pool->iters = 0;
|
||||
}
|
||||
pool->iters++;
|
||||
return pool->pevents[i].data.ptr;
|
||||
}
|
||||
|
||||
|
@ -181,6 +194,11 @@ struct eval *next_event(struct poolhd *pool, int *offs, int *typel)
|
|||
pool->pevents[i].revents = 0;
|
||||
*offs = i - 1;
|
||||
*typel = type;
|
||||
|
||||
if (pool->iters == UINT_MAX) {
|
||||
pool->iters = 0;
|
||||
}
|
||||
pool->iters++;
|
||||
return pool->links[i];
|
||||
}
|
||||
}
|
||||
|
|
2
conev.h
2
conev.h
|
@ -80,6 +80,7 @@ struct eval {
|
|||
#ifndef NOEPOLL
|
||||
uint32_t events;
|
||||
#endif
|
||||
unsigned int del_iter;
|
||||
};
|
||||
|
||||
struct poolhd {
|
||||
|
@ -93,6 +94,7 @@ struct poolhd {
|
|||
#else
|
||||
struct pollfd *pevents;
|
||||
#endif
|
||||
unsigned int iters;
|
||||
};
|
||||
|
||||
struct poolhd *init_pool(int count);
|
||||
|
|
23
main.c
23
main.c
|
@ -221,13 +221,6 @@ char *ftob(const char *str, ssize_t *sl)
|
|||
if (fseek(file, 0, SEEK_SET)) {
|
||||
break;
|
||||
}
|
||||
#ifndef _WIN32
|
||||
buffer = mmap(0, size, PROT_READ, MAP_PRIVATE, fileno(file), 0);
|
||||
if (buffer == MAP_FAILED) {
|
||||
buffer = 0;
|
||||
break;
|
||||
}
|
||||
#else
|
||||
if (!(buffer = malloc(size))) {
|
||||
break;
|
||||
}
|
||||
|
@ -235,7 +228,6 @@ char *ftob(const char *str, ssize_t *sl)
|
|||
free(buffer);
|
||||
buffer = 0;
|
||||
}
|
||||
#endif
|
||||
} while (0);
|
||||
if (buffer) {
|
||||
*sl = size;
|
||||
|
@ -390,11 +382,6 @@ void *add(void **root, int *n, size_t ss)
|
|||
return p;
|
||||
}
|
||||
|
||||
#ifndef _WIN32
|
||||
#define FREE_MAP(p, s) munmap(p, s)
|
||||
#else
|
||||
#define FREE_MAP(p, s) free(p)
|
||||
#endif
|
||||
|
||||
void clear_params(void)
|
||||
{
|
||||
|
@ -420,12 +407,12 @@ void clear_params(void)
|
|||
free(s.tlsrec);
|
||||
s.tlsrec = 0;
|
||||
}
|
||||
if (s.fake_data.data) {
|
||||
FREE_MAP(s.fake_data.data, s.fake_data.size);
|
||||
if (s.fake_data.data != 0) {
|
||||
free(s.fake_data.data);
|
||||
s.fake_data.data = 0;
|
||||
}
|
||||
if (s.file_ptr) {
|
||||
FREE_MAP(s.file_ptr, s.file_size);
|
||||
if (s.file_ptr != 0) {
|
||||
free(s.file_ptr);
|
||||
s.file_ptr = 0;
|
||||
}
|
||||
}
|
||||
|
@ -433,7 +420,7 @@ void clear_params(void)
|
|||
params.dp = 0;
|
||||
}
|
||||
if (oob_data.data != oob_char) {
|
||||
FREE_MAP(oob_data.data, oob_data.size);
|
||||
free(oob_data.data);
|
||||
oob_data.data = oob_char;
|
||||
}
|
||||
}
|
||||
|
|
2
proxy.c
2
proxy.c
|
@ -809,7 +809,7 @@ int event_loop(int srvfd)
|
|||
}
|
||||
LOG(LOG_L, "new event: fd: %d, evt: %s\n", val->fd, eid_name[val->type]);
|
||||
|
||||
if (!val->fd) {
|
||||
if (val->del_iter) {
|
||||
continue;
|
||||
}
|
||||
switch (val->type) {
|
||||
|
|
Loading…
Reference in a new issue