Always compact the buffer if it has reached MAXBUFSIZE.
This commit is contained in:
parent
90c7fafe59
commit
931e30f91a
3 changed files with 5 additions and 5 deletions
|
@ -22,8 +22,8 @@
|
||||||
#include "buffer.h"
|
#include "buffer.h"
|
||||||
#include "xalloc.h"
|
#include "xalloc.h"
|
||||||
|
|
||||||
void buffer_compact(buffer_t *buffer) {
|
void buffer_compact(buffer_t *buffer, int maxsize) {
|
||||||
if(buffer->offset / 7 > buffer->len / 8) {
|
if(buffer->len >= maxsize || buffer->offset / 7 > buffer->len / 8) {
|
||||||
memmove(buffer->data, buffer->data + buffer->offset, buffer->len - buffer->offset);
|
memmove(buffer->data, buffer->data + buffer->offset, buffer->len - buffer->offset);
|
||||||
buffer->len -= buffer->offset;
|
buffer->len -= buffer->offset;
|
||||||
buffer->offset = 0;
|
buffer->offset = 0;
|
||||||
|
|
|
@ -8,7 +8,7 @@ typedef struct buffer_t {
|
||||||
int offset;
|
int offset;
|
||||||
} buffer_t;
|
} buffer_t;
|
||||||
|
|
||||||
extern void buffer_compact(buffer_t *buffer);
|
extern void buffer_compact(buffer_t *buffer, int maxsize);
|
||||||
extern char *buffer_prepare(buffer_t *buffer, int size);
|
extern char *buffer_prepare(buffer_t *buffer, int size);
|
||||||
extern void buffer_add(buffer_t *buffer, const char *data, int size);
|
extern void buffer_add(buffer_t *buffer, const char *data, int size);
|
||||||
extern char *buffer_readline(buffer_t *buffer);
|
extern char *buffer_readline(buffer_t *buffer);
|
||||||
|
|
|
@ -85,10 +85,10 @@ bool receive_meta(connection_t *c) {
|
||||||
- If not, keep stuff in buffer and exit.
|
- If not, keep stuff in buffer and exit.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
buffer_compact(&c->inbuf);
|
buffer_compact(&c->inbuf, MAXBUFSIZE);
|
||||||
|
|
||||||
if(sizeof inbuf <= c->inbuf.len) {
|
if(sizeof inbuf <= c->inbuf.len) {
|
||||||
logger(LOG_ERR, "Input buffer full for %s (%s)\n");
|
logger(LOG_ERR, "Input buffer full for %s (%s)\n", c, c->hostname);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue