mirror of
https://github.com/hufrea/byedpi.git
synced 2025-06-30 02:31:15 +00:00
Limite buffers count in pool
This commit is contained in:
parent
02c1918621
commit
c1bef73d42
32
conev.c
32
conev.c
@ -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;
|
||||
}
|
||||
LOG(LOG_S, "alloc new buffer\n");
|
||||
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;
|
||||
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++;
|
||||
}
|
||||
|
||||
|
||||
|
3
conev.h
3
conev.h
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user