mirror of
https://github.com/hufrea/byedpi.git
synced 2025-07-04 21:14:18 +00:00
Limite buffers count in pool
This commit is contained in:
parent
02c1918621
commit
c1bef73d42
18
conev.c
18
conev.c
@ -331,12 +331,13 @@ void loop_event(struct poolhd *pool)
|
|||||||
|
|
||||||
struct buffer *buff_pop(struct poolhd *pool, size_t size)
|
struct buffer *buff_pop(struct poolhd *pool, size_t size)
|
||||||
{
|
{
|
||||||
struct buffer *root = pool->root_buff;
|
struct buffer *buff = pool->root_buff;
|
||||||
if (root) {
|
if (buff) {
|
||||||
pool->root_buff = root->next;
|
pool->root_buff = buff->next;
|
||||||
return root;
|
pool->buff_count--;
|
||||||
}
|
}
|
||||||
struct buffer *buff = malloc(sizeof(struct buffer) + size);
|
else {
|
||||||
|
buff = malloc(sizeof(struct buffer) + size);
|
||||||
if (!buff) {
|
if (!buff) {
|
||||||
uniperror("malloc");
|
uniperror("malloc");
|
||||||
return 0;
|
return 0;
|
||||||
@ -345,6 +346,7 @@ struct buffer *buff_pop(struct poolhd *pool, size_t size)
|
|||||||
|
|
||||||
memset(buff, 0, sizeof(struct buffer));
|
memset(buff, 0, sizeof(struct buffer));
|
||||||
buff->size = size;
|
buff->size = size;
|
||||||
|
}
|
||||||
return buff;
|
return buff;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -354,10 +356,16 @@ void buff_push(struct poolhd *pool, struct buffer *buff)
|
|||||||
if (!buff) {
|
if (!buff) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (pool->buff_count >= MAX_BUFF_INP) {
|
||||||
|
free(buff);
|
||||||
|
return;
|
||||||
|
}
|
||||||
buff->lock = 0;
|
buff->lock = 0;
|
||||||
buff->offset = 0;
|
buff->offset = 0;
|
||||||
buff->next = pool->root_buff;
|
buff->next = pool->root_buff;
|
||||||
|
|
||||||
pool->root_buff = buff;
|
pool->root_buff = buff;
|
||||||
|
pool->buff_count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
3
conev.h
3
conev.h
@ -40,6 +40,8 @@
|
|||||||
#endif
|
#endif
|
||||||
#define POLLTIMEOUT 0
|
#define POLLTIMEOUT 0
|
||||||
|
|
||||||
|
#define MAX_BUFF_INP 8
|
||||||
|
|
||||||
struct poolhd;
|
struct poolhd;
|
||||||
struct eval;
|
struct eval;
|
||||||
typedef int (*evcb_t)(struct poolhd *, struct eval *, int);
|
typedef int (*evcb_t)(struct poolhd *, struct eval *, int);
|
||||||
@ -101,6 +103,7 @@ struct poolhd {
|
|||||||
|
|
||||||
struct eval *tv_start, *tv_end;
|
struct eval *tv_start, *tv_end;
|
||||||
struct buffer *root_buff;
|
struct buffer *root_buff;
|
||||||
|
int buff_count;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct poolhd *init_pool(int count);
|
struct poolhd *init_pool(int count);
|
||||||
|
Loading…
Reference in New Issue
Block a user