summaryrefslogtreecommitdiffstats
path: root/libnetdata/buffer/buffer.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-07-20 04:50:01 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-07-20 04:50:01 +0000
commitcd4377fab21e0f500bef7f06543fa848a039c1e0 (patch)
treeba00a55e430c052d6bed0b61c0f8bbe8ebedd313 /libnetdata/buffer/buffer.c
parentReleasing debian version 1.40.1-1. (diff)
downloadnetdata-cd4377fab21e0f500bef7f06543fa848a039c1e0.tar.xz
netdata-cd4377fab21e0f500bef7f06543fa848a039c1e0.zip
Merging upstream version 1.41.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'libnetdata/buffer/buffer.c')
-rw-r--r--libnetdata/buffer/buffer.c30
1 files changed, 16 insertions, 14 deletions
diff --git a/libnetdata/buffer/buffer.c b/libnetdata/buffer/buffer.c
index 91bc4dd6..b4376286 100644
--- a/libnetdata/buffer/buffer.c
+++ b/libnetdata/buffer/buffer.c
@@ -107,7 +107,7 @@ void buffer_vsprintf(BUFFER *wb, const char *fmt, va_list args)
do {
need += space_remaining * 2;
- debug(D_WEB_BUFFER, "web_buffer_sprintf(): increasing web_buffer at position %zu, size = %zu, by %zu bytes (wrote = %zu)\n", wb->len, wb->size, need, wrote);
+ netdata_log_debug(D_WEB_BUFFER, "web_buffer_sprintf(): increasing web_buffer at position %zu, size = %zu, by %zu bytes (wrote = %zu)\n", wb->len, wb->size, need, wrote);
buffer_need_bytes(wb, need);
space_remaining = wb->size - wb->len - 1;
@@ -131,7 +131,7 @@ void buffer_sprintf(BUFFER *wb, const char *fmt, ...)
do {
need += space_remaining * 2;
- debug(D_WEB_BUFFER, "web_buffer_sprintf(): increasing web_buffer at position %zu, size = %zu, by %zu bytes (wrote = %zu)\n", wb->len, wb->size, need, wrote);
+ netdata_log_debug(D_WEB_BUFFER, "web_buffer_sprintf(): increasing web_buffer at position %zu, size = %zu, by %zu bytes (wrote = %zu)\n", wb->len, wb->size, need, wrote);
buffer_need_bytes(wb, need);
space_remaining = wb->size - wb->len - 1;
@@ -246,7 +246,7 @@ BUFFER *buffer_create(size_t size, size_t *statistics)
{
BUFFER *b;
- debug(D_WEB_BUFFER, "Creating new web buffer of size %zu.", size);
+ netdata_log_debug(D_WEB_BUFFER, "Creating new web buffer of size %zu.", size);
b = callocz(1, sizeof(BUFFER));
b->buffer = mallocz(size + sizeof(BUFFER_OVERFLOW_EOF) + 2);
@@ -268,7 +268,7 @@ void buffer_free(BUFFER *b) {
buffer_overflow_check(b);
- debug(D_WEB_BUFFER, "Freeing web buffer of size %zu.", b->size);
+ netdata_log_debug(D_WEB_BUFFER, "Freeing web buffer of size %zu.", b->size);
if(b->statistics)
__atomic_sub_fetch(b->statistics, b->size + sizeof(BUFFER) + sizeof(BUFFER_OVERFLOW_EOF) + 2, __ATOMIC_RELAXED);
@@ -290,7 +290,7 @@ void buffer_increase(BUFFER *b, size_t free_size_required) {
size_t optimal = (b->size > 5*1024*1024) ? b->size / 2 : b->size;
if(optimal > wanted) wanted = optimal;
- debug(D_WEB_BUFFER, "Increasing data buffer from size %zu to %zu.", b->size, b->size + wanted);
+ netdata_log_debug(D_WEB_BUFFER, "Increasing data buffer from size %zu to %zu.", b->size, b->size + wanted);
b->buffer = reallocz(b->buffer, b->size + wanted + sizeof(BUFFER_OVERFLOW_EOF) + 2);
b->size += wanted;
@@ -315,6 +315,8 @@ void buffer_json_initialize(BUFFER *wb, const char *key_quote, const char *value
if(add_anonymous_object)
buffer_fast_strcat(wb, "{", 1);
+
+ wb->content_type = CT_APPLICATION_JSON;
}
void buffer_json_finalize(BUFFER *wb) {
@@ -365,8 +367,8 @@ static int buffer_expect(BUFFER *wb, const char *expected) {
const char *generated = buffer_tostring(wb);
if(strcmp(generated, expected) != 0) {
- error("BUFFER: mismatch.\nGenerated:\n%s\nExpected:\n%s\n",
- generated, expected);
+ netdata_log_error("BUFFER: mismatch.\nGenerated:\n%s\nExpected:\n%s\n",
+ generated, expected);
return 1;
}
@@ -383,8 +385,8 @@ static int buffer_uint64_roundtrip(BUFFER *wb, NUMBER_ENCODING encoding, uint64_
uint64_t v = str2ull_encoded(buffer_tostring(wb));
if(v != value) {
- error("BUFFER: string '%s' does resolves to %llu, expected %llu",
- buffer_tostring(wb), (unsigned long long)v, (unsigned long long)value);
+ netdata_log_error("BUFFER: string '%s' does resolves to %llu, expected %llu",
+ buffer_tostring(wb), (unsigned long long)v, (unsigned long long)value);
errors++;
}
buffer_flush(wb);
@@ -401,8 +403,8 @@ static int buffer_int64_roundtrip(BUFFER *wb, NUMBER_ENCODING encoding, int64_t
int64_t v = str2ll_encoded(buffer_tostring(wb));
if(v != value) {
- error("BUFFER: string '%s' does resolves to %lld, expected %lld",
- buffer_tostring(wb), (long long)v, (long long)value);
+ netdata_log_error("BUFFER: string '%s' does resolves to %lld, expected %lld",
+ buffer_tostring(wb), (long long)v, (long long)value);
errors++;
}
buffer_flush(wb);
@@ -419,8 +421,8 @@ static int buffer_double_roundtrip(BUFFER *wb, NUMBER_ENCODING encoding, NETDATA
NETDATA_DOUBLE v = str2ndd_encoded(buffer_tostring(wb), NULL);
if(v != value) {
- error("BUFFER: string '%s' does resolves to %.12f, expected %.12f",
- buffer_tostring(wb), v, value);
+ netdata_log_error("BUFFER: string '%s' does resolves to %.12f, expected %.12f",
+ buffer_tostring(wb), v, value);
errors++;
}
buffer_flush(wb);
@@ -503,7 +505,7 @@ int buffer_unittest(void) {
return errors;
}
-#ifdef ENABLE_HTTPD
+#ifdef ENABLE_H2O
h2o_iovec_t buffer_to_h2o_iovec(BUFFER *wb) {
h2o_iovec_t ret;
ret.base = wb->buffer;