Bump the client ETA timeout from 5s to 30s
[fio.git] / lib / output_buffer.c
CommitLineData
a666cab8
JA
1#include <stdio.h>
2#include <string.h>
3#include <stdlib.h>
4
5#include "output_buffer.h"
6#include "../log.h"
7
8#define BUF_INC 1024
9
e250c0a9 10void buf_output_init(struct buf_output *out)
a666cab8 11{
e250c0a9 12 out->max_buflen = 0;
a666cab8 13 out->buflen = 0;
e250c0a9 14 out->buf = NULL;
a666cab8
JA
15}
16
17void buf_output_free(struct buf_output *out)
18{
19 free(out->buf);
20}
21
5768cc2b 22size_t buf_output_add(struct buf_output *out, const char *buf, size_t len)
a666cab8
JA
23{
24 while (out->max_buflen - out->buflen < len) {
e250c0a9 25 size_t old_max = out->max_buflen;
a666cab8 26
a666cab8 27 out->max_buflen += BUF_INC;
5768cc2b 28 out->buf = realloc(out->buf, out->max_buflen);
e250c0a9 29 memset(&out->buf[old_max], 0, BUF_INC);
a666cab8
JA
30 }
31
32 memcpy(&out->buf[out->buflen], buf, len);
33 out->buflen += len;
5768cc2b 34 return len;
a666cab8
JA
35}
36
5768cc2b 37size_t buf_output_flush(struct buf_output *out)
a666cab8 38{
5768cc2b
JA
39 size_t ret = 0;
40
a666cab8 41 if (out->buflen) {
ee92054f 42 ret = log_info_buf(out->buf, out->buflen);
a666cab8
JA
43 memset(out->buf, 0, out->max_buflen);
44 out->buflen = 0;
45 }
5768cc2b
JA
46
47 return ret;
a666cab8 48}