Rename functions and nghttp2_debug.h to move debug macro there

This commit is contained in:
Tatsuhiro Tsujikawa 2016-10-14 22:31:46 +09:00
parent b8f7b474b4
commit bef3d47c16
9 changed files with 62 additions and 34 deletions

View File

@ -64,7 +64,8 @@ HFILES = nghttp2_pq.h nghttp2_int.h nghttp2_map.h nghttp2_queue.h \
nghttp2_callbacks.h \ nghttp2_callbacks.h \
nghttp2_mem.h \ nghttp2_mem.h \
nghttp2_http.h \ nghttp2_http.h \
nghttp2_rcbuf.h nghttp2_rcbuf.h \
nghttp2_debug.h
libnghttp2_la_SOURCES = $(HFILES) $(OBJECTS) libnghttp2_la_SOURCES = $(HFILES) $(OBJECTS)
libnghttp2_la_LDFLAGS = -no-undefined \ libnghttp2_la_LDFLAGS = -no-undefined \

View File

@ -5239,15 +5239,38 @@ NGHTTP2_EXTERN int32_t nghttp2_stream_get_weight(nghttp2_stream *stream);
NGHTTP2_EXTERN int32_t NGHTTP2_EXTERN int32_t
nghttp2_stream_get_sum_dependency_weight(nghttp2_stream *stream); 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 * @function
* *
* Sets a debug callback called by nghttp2 when built when DEBUGBUILD is * Sets a debug output callback called by the library when built with
* defined. The function is called with arguments suitable for vfprintf. * ``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.
*/ */
NGHTTP2_EXTERN void nghttp2_set_debug_vprintf_callback(
typedef void (*nghttp2_debug_cb)(const char *format, va_list args); nghttp2_debug_vprintf_callback debug_vprintf_callback);
NGHTTP2_EXTERN void set_nghttp2_debug_callback(nghttp2_debug_cb cb);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -27,6 +27,7 @@
#include <stdio.h> #include <stdio.h>
#include "nghttp2_helper.h" #include "nghttp2_helper.h"
#include "nghttp2_debug.h"
void nghttp2_buf_init(nghttp2_buf *buf) { void nghttp2_buf_init(nghttp2_buf *buf) {
buf->begin = NULL; buf->begin = NULL;

View File

@ -1,7 +1,7 @@
/* /*
* nghttp2 - HTTP/2 C Library * 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 * Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the * 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 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
#include <time.h> #include "nghttp2_debug.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) #include <stdio.h>
{
vfprintf(stderr, fmt, args);
}
static nghttp2_debug_cb static_debug_callback = &nghttp2_debug_cb_default;
#ifdef DEBUGBUILD #ifdef DEBUGBUILD
void nghttp2_debug(const char *format, ...)
{ static void nghttp2_default_debug_vfprintf_callback(const char *fmt,
if (static_debug_callback) { 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_list args;
va_start(args, format); va_start(args, format);
static_debug_callback(format, args); static_debug_vprintf_callback(format, args);
va_end(args); va_end(args);
} }
} }
#endif
void set_nghttp2_debug_callback(nghttp2_debug_cb cb) void nghttp2_set_debug_vprintf_callback(
{ nghttp2_debug_vprintf_callback debug_vprintf_callback) {
static_debug_callback = cb; 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 */

View File

@ -32,6 +32,7 @@
#include "nghttp2_helper.h" #include "nghttp2_helper.h"
#include "nghttp2_net.h" #include "nghttp2_net.h"
#include "nghttp2_priority_spec.h" #include "nghttp2_priority_spec.h"
#include "nghttp2_debug.h"
void nghttp2_frame_pack_frame_hd(uint8_t *buf, const nghttp2_frame_hd *hd) { void nghttp2_frame_pack_frame_hd(uint8_t *buf, const nghttp2_frame_hd *hd) {
nghttp2_put_uint32be(&buf[0], (uint32_t)(hd->length << 8)); nghttp2_put_uint32be(&buf[0], (uint32_t)(hd->length << 8));

View File

@ -30,6 +30,7 @@
#include "nghttp2_helper.h" #include "nghttp2_helper.h"
#include "nghttp2_int.h" #include "nghttp2_int.h"
#include "nghttp2_debug.h"
/* Make scalar initialization form of nghttp2_hd_entry */ /* Make scalar initialization form of nghttp2_hd_entry */
#define MAKE_STATIC_ENT(N, V, T, H) \ #define MAKE_STATIC_ENT(N, V, T, H) \

View File

@ -29,16 +29,9 @@
#include <config.h> #include <config.h>
#endif /* HAVE_CONFIG_H */ #endif /* HAVE_CONFIG_H */
/* Macros, types and constants for internal use */ #include <nghttp2/nghttp2.h>
#ifdef DEBUGBUILD /* Macros, types and constants for internal use */
void nghttp2_debug(const char *format, ...);
#define DEBUGF(...) nghttp2_debug(__VA_ARGS__)
#else
#define DEBUGF(...) \
do { \
} while (0)
#endif
/* "less" function, return nonzero if |lhs| is less than |rhs|. */ /* "less" function, return nonzero if |lhs| is less than |rhs|. */
typedef int (*nghttp2_less)(const void *lhs, const void *rhs); typedef int (*nghttp2_less)(const void *lhs, const void *rhs);

View File

@ -36,6 +36,7 @@
#include "nghttp2_option.h" #include "nghttp2_option.h"
#include "nghttp2_http.h" #include "nghttp2_http.h"
#include "nghttp2_pq.h" #include "nghttp2_pq.h"
#include "nghttp2_debug.h"
/* /*
* Returns non-zero if the number of outgoing opened streams is larger * Returns non-zero if the number of outgoing opened streams is larger

View File

@ -29,6 +29,7 @@
#include "nghttp2_session.h" #include "nghttp2_session.h"
#include "nghttp2_helper.h" #include "nghttp2_helper.h"
#include "nghttp2_debug.h"
/* Maximum distance between any two stream's cycle in the same /* Maximum distance between any two stream's cycle in the same
prirority queue. Imagine stream A's cycle is A, and stream B's prirority queue. Imagine stream A's cycle is A, and stream B's