From bef3d47c160e2eafffb2e2479f819238362c75d3 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Fri, 14 Oct 2016 22:31:46 +0900 Subject: [PATCH] Rename functions and nghttp2_debug.h to move debug macro there --- lib/Makefile.am | 3 ++- lib/includes/nghttp2/nghttp2.h | 33 +++++++++++++++++++++---- lib/nghttp2_buf.c | 1 + lib/nghttp2_debug.c | 44 +++++++++++++++++++--------------- lib/nghttp2_frame.c | 1 + lib/nghttp2_hd.c | 1 + lib/nghttp2_int.h | 11 ++------- lib/nghttp2_session.c | 1 + lib/nghttp2_stream.c | 1 + 9 files changed, 62 insertions(+), 34 deletions(-) diff --git a/lib/Makefile.am b/lib/Makefile.am index 449282c6..3e2b6014 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -64,7 +64,8 @@ HFILES = nghttp2_pq.h nghttp2_int.h nghttp2_map.h nghttp2_queue.h \ nghttp2_callbacks.h \ nghttp2_mem.h \ nghttp2_http.h \ - nghttp2_rcbuf.h + nghttp2_rcbuf.h \ + nghttp2_debug.h libnghttp2_la_SOURCES = $(HFILES) $(OBJECTS) libnghttp2_la_LDFLAGS = -no-undefined \ diff --git a/lib/includes/nghttp2/nghttp2.h b/lib/includes/nghttp2/nghttp2.h index 31b341d5..572b1763 100644 --- a/lib/includes/nghttp2/nghttp2.h +++ b/lib/includes/nghttp2/nghttp2.h @@ -5239,15 +5239,38 @@ NGHTTP2_EXTERN int32_t nghttp2_stream_get_weight(nghttp2_stream *stream); NGHTTP2_EXTERN int32_t nghttp2_stream_get_sum_dependency_weight(nghttp2_stream *stream); +/** + * @functypedef + * + * Callback function invoked when the library outputs debug logging. + * The function is called with arguments suitable for ``vfprintf(3)`` + * + * The debug output is only enabled if the library is built with + * ``DEBUGBUILD`` macro defined. + */ +typedef void (*nghttp2_debug_vprintf_callback)(const char *format, + va_list args); + /** * @function * - * Sets a debug callback called by nghttp2 when built when DEBUGBUILD is - * defined. The function is called with arguments suitable for vfprintf. + * Sets a debug output callback called by the library when built with + * ``DEBUGBUILD`` macro defined. If this option is not used, debug + * log is written into standard error output. + * + * Note that building with ``DEBUGBUILD`` may cause significant + * performance penalty to libnghttp2 because of extra processing. It + * should be used for debugging purpose only. + * + * .. Warning:: + * + * Building with ``DEBUGBUILD`` may cause significant performance + * penalty to libnghttp2 because of extra processing. It should be + * used for debugging purpose only. We write this two times because + * this is important. */ - -typedef void (*nghttp2_debug_cb)(const char *format, va_list args); -NGHTTP2_EXTERN void set_nghttp2_debug_callback(nghttp2_debug_cb cb); +NGHTTP2_EXTERN void nghttp2_set_debug_vprintf_callback( + nghttp2_debug_vprintf_callback debug_vprintf_callback); #ifdef __cplusplus } diff --git a/lib/nghttp2_buf.c b/lib/nghttp2_buf.c index ce14872a..2a435beb 100644 --- a/lib/nghttp2_buf.c +++ b/lib/nghttp2_buf.c @@ -27,6 +27,7 @@ #include #include "nghttp2_helper.h" +#include "nghttp2_debug.h" void nghttp2_buf_init(nghttp2_buf *buf) { buf->begin = NULL; diff --git a/lib/nghttp2_debug.c b/lib/nghttp2_debug.c index 84da8ab2..3514ded0 100644 --- a/lib/nghttp2_debug.c +++ b/lib/nghttp2_debug.c @@ -1,7 +1,7 @@ /* * nghttp2 - HTTP/2 C Library * - * Copyright (c) 2012 Tatsuhiro Tsujikawa + * Copyright (c) 2016 Tatsuhiro Tsujikawa * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -22,31 +22,37 @@ * 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 -#include -#include "config.h" -#include -#include "nghttp2_int.h" +#include "nghttp2_debug.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; +#include #ifdef DEBUGBUILD -void nghttp2_debug(const char *format, ...) -{ - if (static_debug_callback) { + +static void nghttp2_default_debug_vfprintf_callback(const char *fmt, + va_list args) { + vfprintf(stderr, fmt, args); +} + +static nghttp2_debug_vprintf_callback static_debug_vprintf_callback = + nghttp2_default_debug_vfprintf_callback; + +void nghttp2_debug_vprintf(const char *format, ...) { + if (static_debug_vprintf_callback) { va_list args; va_start(args, format); - static_debug_callback(format, args); + static_debug_vprintf_callback(format, args); va_end(args); } } -#endif -void set_nghttp2_debug_callback(nghttp2_debug_cb cb) -{ - static_debug_callback = cb; +void nghttp2_set_debug_vprintf_callback( + nghttp2_debug_vprintf_callback debug_vprintf_callback) { + static_debug_vprintf_callback = debug_vprintf_callback; } + +#else /* !DEBUGBUILD */ + +void nghttp2_set_debug_vprintf_callback( + nghttp2_debug_vprintf_callback debug_vprintf_callback _U_) {} + +#endif /* !DEBUGBUILD */ diff --git a/lib/nghttp2_frame.c b/lib/nghttp2_frame.c index 789ed306..5079dfd4 100644 --- a/lib/nghttp2_frame.c +++ b/lib/nghttp2_frame.c @@ -32,6 +32,7 @@ #include "nghttp2_helper.h" #include "nghttp2_net.h" #include "nghttp2_priority_spec.h" +#include "nghttp2_debug.h" void nghttp2_frame_pack_frame_hd(uint8_t *buf, const nghttp2_frame_hd *hd) { nghttp2_put_uint32be(&buf[0], (uint32_t)(hd->length << 8)); diff --git a/lib/nghttp2_hd.c b/lib/nghttp2_hd.c index 62d00e44..8c9c10a5 100644 --- a/lib/nghttp2_hd.c +++ b/lib/nghttp2_hd.c @@ -30,6 +30,7 @@ #include "nghttp2_helper.h" #include "nghttp2_int.h" +#include "nghttp2_debug.h" /* Make scalar initialization form of nghttp2_hd_entry */ #define MAKE_STATIC_ENT(N, V, T, H) \ diff --git a/lib/nghttp2_int.h b/lib/nghttp2_int.h index c3513c85..9ea8c820 100644 --- a/lib/nghttp2_int.h +++ b/lib/nghttp2_int.h @@ -29,16 +29,9 @@ #include #endif /* HAVE_CONFIG_H */ -/* Macros, types and constants for internal use */ +#include -#ifdef DEBUGBUILD -void nghttp2_debug(const char *format, ...); -#define DEBUGF(...) nghttp2_debug(__VA_ARGS__) -#else -#define DEBUGF(...) \ - do { \ - } while (0) -#endif +/* Macros, types and constants for internal use */ /* "less" function, return nonzero if |lhs| is less than |rhs|. */ typedef int (*nghttp2_less)(const void *lhs, const void *rhs); diff --git a/lib/nghttp2_session.c b/lib/nghttp2_session.c index 3d3aa76b..4bd35959 100644 --- a/lib/nghttp2_session.c +++ b/lib/nghttp2_session.c @@ -36,6 +36,7 @@ #include "nghttp2_option.h" #include "nghttp2_http.h" #include "nghttp2_pq.h" +#include "nghttp2_debug.h" /* * Returns non-zero if the number of outgoing opened streams is larger diff --git a/lib/nghttp2_stream.c b/lib/nghttp2_stream.c index d77df66d..4c1a1715 100644 --- a/lib/nghttp2_stream.c +++ b/lib/nghttp2_stream.c @@ -29,6 +29,7 @@ #include "nghttp2_session.h" #include "nghttp2_helper.h" +#include "nghttp2_debug.h" /* Maximum distance between any two stream's cycle in the same prirority queue. Imagine stream A's cycle is A, and stream B's