Commit bc3dc6b7 authored by Anders Bakken's avatar Anders Bakken

Add set_nghttp2_debug_callback to take advantage of DEBUGF statements in

when building DEBUGBUILD.
parent 3c3267ea
......@@ -23,6 +23,7 @@ set(NGHTTP2_SOURCES
nghttp2_mem.c
nghttp2_http.c
nghttp2_rcbuf.c
nghttp2_debug.c
)
# Public shared library
......
......@@ -45,6 +45,7 @@ extern "C" {
#include <inttypes.h>
#endif /* !defined(_MSC_VER) || (_MSC_VER >= 1800) */
#include <sys/types.h>
#include <stdarg.h>
#include <nghttp2/nghttp2ver.h>
......@@ -5238,6 +5239,16 @@ NGHTTP2_EXTERN int32_t nghttp2_stream_get_weight(nghttp2_stream *stream);
NGHTTP2_EXTERN int32_t
nghttp2_stream_get_sum_dependency_weight(nghttp2_stream *stream);
/**
* @function
*
* Sets a debug callback called by nghttp2 when built when DEBUGBUILD is
* defined. The function is called with arguments suitable for vfprintf.
*/
typedef void (*nghttp2_debug_cb)(const char *format, va_list args);
NGHTTP2_EXTERN void set_nghttp2_debug_callback(nghttp2_debug_cb cb);
#ifdef __cplusplus
}
#endif
......
......@@ -316,9 +316,8 @@ static int bufs_alloc_chain(nghttp2_bufs *bufs) {
return rv;
}
DEBUGF(fprintf(stderr,
"new buffer %zu bytes allocated for bufs %p, used %zu\n",
bufs->chunk_length, bufs, bufs->chunk_used));
DEBUGF("new buffer %zu bytes allocated for bufs %p, used %zu\n",
bufs->chunk_length, bufs, bufs->chunk_used);
++bufs->chunk_used;
......
/*
* nghttp2 - HTTP/2 C Library
*
* Copyright (c) 2012 Tatsuhiro Tsujikawa
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <time.h>
#include <stdio.h>
#include "config.h"
#include <nghttp2/nghttp2.h>
#include "nghttp2_int.h"
static void nghttp2_debug_cb_default(const char *fmt, va_list args)
{
vfprintf(stderr, fmt, args);
}
static nghttp2_debug_cb static_debug_callback = &nghttp2_debug_cb_default;
#ifdef DEBUGBUILD
void nghttp2_debug(const char *format, ...)
{
if (static_debug_callback) {
va_list args;
va_start(args, format);
static_debug_callback(format, args);
va_end(args);
}
}
#endif
void set_nghttp2_debug_callback(nghttp2_debug_cb cb)
{
static_debug_callback = cb;
}
......@@ -252,8 +252,7 @@ static int frame_pack_headers_shared(nghttp2_bufs *bufs,
hd = *frame_hd;
hd.length = nghttp2_buf_len(buf);
DEBUGF(fprintf(stderr, "send: HEADERS/PUSH_PROMISE, payloadlen=%zu\n",
hd.length));
DEBUGF("send: HEADERS/PUSH_PROMISE, payloadlen=%zu\n", hd.length);
/* We have multiple frame buffers, which means one or more
CONTINUATION frame is involved. Remove END_HEADERS flag from the
......@@ -278,8 +277,7 @@ static int frame_pack_headers_shared(nghttp2_bufs *bufs,
hd.length = nghttp2_buf_len(buf);
DEBUGF(fprintf(stderr, "send: int CONTINUATION, payloadlen=%zu\n",
hd.length));
DEBUGF("send: int CONTINUATION, payloadlen=%zu\n", hd.length);
buf->pos -= NGHTTP2_FRAME_HDLEN;
nghttp2_frame_pack_frame_hd(buf->pos, &hd);
......@@ -290,8 +288,7 @@ static int frame_pack_headers_shared(nghttp2_bufs *bufs,
/* Set END_HEADERS flag for last CONTINUATION */
hd.flags = NGHTTP2_FLAG_END_HEADERS;
DEBUGF(fprintf(stderr, "send: last CONTINUATION, payloadlen=%zu\n",
hd.length));
DEBUGF("send: last CONTINUATION, payloadlen=%zu\n", hd.length);
buf->pos -= NGHTTP2_FRAME_HDLEN;
nghttp2_frame_pack_frame_hd(buf->pos, &hd);
......@@ -930,7 +927,7 @@ static void frame_set_pad(nghttp2_buf *buf, size_t padlen, int framehd_only) {
size_t trail_padlen;
size_t newlen;
DEBUGF(fprintf(stderr, "send: padlen=%zu, shift left 1 bytes\n", padlen));
DEBUGF("send: padlen=%zu, shift left 1 bytes\n", padlen);
memmove(buf->pos - 1, buf->pos, NGHTTP2_FRAME_HDLEN);
......@@ -960,7 +957,7 @@ int nghttp2_frame_add_pad(nghttp2_bufs *bufs, nghttp2_frame_hd *hd,
nghttp2_buf *buf;
if (padlen == 0) {
DEBUGF(fprintf(stderr, "send: padlen = 0, nothing to do\n"));
DEBUGF("send: padlen = 0, nothing to do\n");
return 0;
}
......@@ -994,8 +991,7 @@ int nghttp2_frame_add_pad(nghttp2_bufs *bufs, nghttp2_frame_hd *hd,
hd->length += padlen;
hd->flags |= NGHTTP2_FLAG_PADDED;
DEBUGF(fprintf(stderr, "send: final payloadlen=%zu, padlen=%zu\n", hd->length,
padlen));
DEBUGF("send: final payloadlen=%zu, padlen=%zu\n", hd->length, padlen);
return 0;
}
This diff is collapsed.
......@@ -32,11 +32,12 @@
/* Macros, types and constants for internal use */
#ifdef DEBUGBUILD
#define DEBUGF(x) x
void nghttp2_debug(const char *format, ...);
#define DEBUGF(...) nghttp2_debug(__VA_ARGS__)
#else
#define DEBUGF(x) \
do { \
} while (0)
#define DEBUGF(...) \
do { \
} while (0)
#endif
/* "less" function, return nonzero if |lhs| is less than |rhs|. */
......
This diff is collapsed.
......@@ -152,11 +152,10 @@ static int stream_obq_push(nghttp2_stream *dep_stream, nghttp2_stream *stream) {
stream_next_cycle(stream, dep_stream->descendant_last_cycle);
stream->seq = dep_stream->descendant_next_seq++;
DEBUGF(fprintf(stderr, "stream: stream=%d obq push cycle=%d\n",
stream->stream_id, stream->cycle));
DEBUGF("stream: stream=%d obq push cycle=%d\n", stream->stream_id, stream->cycle);
DEBUGF(fprintf(stderr, "stream: push stream %d to stream %d\n",
stream->stream_id, dep_stream->stream_id));
DEBUGF("stream: push stream %d to stream %d\n",
stream->stream_id, dep_stream->stream_id);
rv = nghttp2_pq_push(&dep_stream->obq, &stream->pq_entry);
if (rv != 0) {
......@@ -183,8 +182,8 @@ static void stream_obq_remove(nghttp2_stream *stream) {
}
for (; dep_stream; stream = dep_stream, dep_stream = dep_stream->dep_prev) {
DEBUGF(fprintf(stderr, "stream: remove stream %d from stream %d\n",
stream->stream_id, dep_stream->stream_id));
DEBUGF("stream: remove stream %d from stream %d\n",
stream->stream_id, dep_stream->stream_id);
nghttp2_pq_remove(&dep_stream->obq, &stream->pq_entry);
......@@ -214,8 +213,8 @@ static int stream_obq_move(nghttp2_stream *dest, nghttp2_stream *src,
return 0;
}
DEBUGF(fprintf(stderr, "stream: remove stream %d from stream %d (move)\n",
stream->stream_id, src->stream_id));
DEBUGF("stream: remove stream %d from stream %d (move)\n",
stream->stream_id, src->stream_id);
nghttp2_pq_remove(&src->obq, &stream->pq_entry);
stream->queued = 0;
......@@ -238,8 +237,8 @@ void nghttp2_stream_reschedule(nghttp2_stream *stream) {
nghttp2_pq_push(&dep_stream->obq, &stream->pq_entry);
DEBUGF(fprintf(stderr, "stream: stream=%d obq resched cycle=%d\n",
stream->stream_id, stream->cycle));
DEBUGF("stream: stream=%d obq resched cycle=%d\n",
stream->stream_id, stream->cycle);
dep_stream->last_writelen = stream->last_writelen;
}
......@@ -298,8 +297,8 @@ void nghttp2_stream_change_weight(nghttp2_stream *stream, int32_t weight) {
nghttp2_pq_push(&dep_stream->obq, &stream->pq_entry);
DEBUGF(fprintf(stderr, "stream: stream=%d obq resched cycle=%d\n",
stream->stream_id, stream->cycle));
DEBUGF("stream: stream=%d obq resched cycle=%d\n",
stream->stream_id, stream->cycle);
}
static nghttp2_stream *stream_last_sib(nghttp2_stream *stream) {
......@@ -481,8 +480,7 @@ int nghttp2_stream_attach_item(nghttp2_stream *stream,
assert((stream->flags & NGHTTP2_STREAM_FLAG_DEFERRED_ALL) == 0);
assert(stream->item == NULL);
DEBUGF(fprintf(stderr, "stream: stream=%d attach item=%p\n",
stream->stream_id, item));
DEBUGF("stream: stream=%d attach item=%p\n", stream->stream_id, item);
stream->item = item;
......@@ -500,8 +498,7 @@ int nghttp2_stream_attach_item(nghttp2_stream *stream,
}
int nghttp2_stream_detach_item(nghttp2_stream *stream) {
DEBUGF(fprintf(stderr, "stream: stream=%d detach item=%p\n",
stream->stream_id, stream->item));
DEBUGF("stream: stream=%d detach item=%p\n", stream->stream_id, stream->item);
stream->item = NULL;
stream->flags = (uint8_t)(stream->flags & ~NGHTTP2_STREAM_FLAG_DEFERRED_ALL);
......@@ -512,8 +509,8 @@ int nghttp2_stream_detach_item(nghttp2_stream *stream) {
int nghttp2_stream_defer_item(nghttp2_stream *stream, uint8_t flags) {
assert(stream->item);
DEBUGF(fprintf(stderr, "stream: stream=%d defer item=%p cause=%02x\n",
stream->stream_id, stream->item, flags));
DEBUGF("stream: stream=%d defer item=%p cause=%02x\n",
stream->stream_id, stream->item, flags);
stream->flags |= flags;
......@@ -523,8 +520,8 @@ int nghttp2_stream_defer_item(nghttp2_stream *stream, uint8_t flags) {
int nghttp2_stream_resume_deferred_item(nghttp2_stream *stream, uint8_t flags) {
assert(stream->item);
DEBUGF(fprintf(stderr, "stream: stream=%d resume item=%p flags=%02x\n",
stream->stream_id, stream->item, flags));
DEBUGF("stream: stream=%d resume item=%p flags=%02x\n",
stream->stream_id, stream->item, flags);
stream->flags = (uint8_t)(stream->flags & ~flags);
......@@ -593,9 +590,8 @@ int nghttp2_stream_dep_insert(nghttp2_stream *dep_stream,
nghttp2_stream *si;
int rv;
DEBUGF(fprintf(stderr,
"stream: dep_insert dep_stream(%p)=%d, stream(%p)=%d\n",
dep_stream, dep_stream->stream_id, stream, stream->stream_id));
DEBUGF("stream: dep_insert dep_stream(%p)=%d, stream(%p)=%d\n",
dep_stream, dep_stream->stream_id, stream, stream->stream_id);
stream->sum_dep_weight = dep_stream->sum_dep_weight;
dep_stream->sum_dep_weight = stream->weight;
......@@ -740,8 +736,8 @@ static void unlink_dep(nghttp2_stream *stream) {
void nghttp2_stream_dep_add(nghttp2_stream *dep_stream,
nghttp2_stream *stream) {
DEBUGF(fprintf(stderr, "stream: dep_add dep_stream(%p)=%d, stream(%p)=%d\n",
dep_stream, dep_stream->stream_id, stream, stream->stream_id));
DEBUGF("stream: dep_add dep_stream(%p)=%d, stream(%p)=%d\n",
dep_stream, dep_stream->stream_id, stream, stream->stream_id);
dep_stream->sum_dep_weight += stream->weight;
......@@ -759,8 +755,7 @@ int nghttp2_stream_dep_remove(nghttp2_stream *stream) {
int32_t sum_dep_weight_delta;
int rv;
DEBUGF(fprintf(stderr, "stream: dep_remove stream(%p)=%d\n", stream,
stream->stream_id));
DEBUGF("stream: dep_remove stream(%p)=%d\n", stream, stream->stream_id);
/* Distribute weight of |stream| to direct descendants */
sum_dep_weight_delta = -stream->weight;
......@@ -813,9 +808,9 @@ int nghttp2_stream_dep_insert_subtree(nghttp2_stream *dep_stream,
nghttp2_stream *si;
int rv;
DEBUGF(fprintf(stderr, "stream: dep_insert_subtree dep_stream(%p)=%d "
"stream(%p)=%d\n",
dep_stream, dep_stream->stream_id, stream, stream->stream_id));
DEBUGF("stream: dep_insert_subtree dep_stream(%p)=%d "
"stream(%p)=%d\n",
dep_stream, dep_stream->stream_id, stream, stream->stream_id);
stream->sum_dep_weight += dep_stream->sum_dep_weight;
dep_stream->sum_dep_weight = stream->weight;
......@@ -862,9 +857,9 @@ int nghttp2_stream_dep_add_subtree(nghttp2_stream *dep_stream,
nghttp2_stream *stream) {
int rv;
DEBUGF(fprintf(stderr, "stream: dep_add_subtree dep_stream(%p)=%d "
"stream(%p)=%d\n",
dep_stream, dep_stream->stream_id, stream, stream->stream_id));
DEBUGF("stream: dep_add_subtree dep_stream(%p)=%d "
"stream(%p)=%d\n",
dep_stream, dep_stream->stream_id, stream, stream->stream_id);
dep_stream->sum_dep_weight += stream->weight;
......@@ -889,8 +884,7 @@ int nghttp2_stream_dep_add_subtree(nghttp2_stream *dep_stream,
void nghttp2_stream_dep_remove_subtree(nghttp2_stream *stream) {
nghttp2_stream *next, *dep_prev;
DEBUGF(fprintf(stderr, "stream: dep_remove_subtree stream(%p)=%d\n", stream,
stream->stream_id));
DEBUGF("stream: dep_remove_subtree stream(%p)=%d\n", stream, stream->stream_id);
assert(stream->dep_prev);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment