0
0
mirror of https://github.com/hufrea/byedpi.git synced 2025-06-29 18:21:14 +00:00

Limite buffers count in pool

This commit is contained in:
ruti 2025-02-24 21:02:02 +03:00
parent 02c1918621
commit c1bef73d42
2 changed files with 23 additions and 12 deletions

32
conev.c
View File

@ -331,20 +331,22 @@ void loop_event(struct poolhd *pool)
struct buffer *buff_pop(struct poolhd *pool, size_t size)
{
struct buffer *root = pool->root_buff;
if (root) {
pool->root_buff = root->next;
return root;
struct buffer *buff = pool->root_buff;
if (buff) {
pool->root_buff = buff->next;
pool->buff_count--;
}
struct buffer *buff = malloc(sizeof(struct buffer) + size);
if (!buff) {
uniperror("malloc");
return 0;
else {
buff = malloc(sizeof(struct buffer) + size);
if (!buff) {
uniperror("malloc");
return 0;
}
LOG(LOG_S, "alloc new buffer\n");
memset(buff, 0, sizeof(struct buffer));
buff->size = size;
}
LOG(LOG_S, "alloc new buffer\n");
memset(buff, 0, sizeof(struct buffer));
buff->size = size;
return buff;
}
@ -354,10 +356,16 @@ void buff_push(struct poolhd *pool, struct buffer *buff)
if (!buff) {
return;
}
if (pool->buff_count >= MAX_BUFF_INP) {
free(buff);
return;
}
buff->lock = 0;
buff->offset = 0;
buff->next = pool->root_buff;
pool->root_buff = buff;
pool->buff_count++;
}

View File

@ -40,6 +40,8 @@
#endif
#define POLLTIMEOUT 0
#define MAX_BUFF_INP 8
struct poolhd;
struct eval;
typedef int (*evcb_t)(struct poolhd *, struct eval *, int);
@ -101,6 +103,7 @@ struct poolhd {
struct eval *tv_start, *tv_end;
struct buffer *root_buff;
int buff_count;
};
struct poolhd *init_pool(int count);