diff options
author | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2020-09-20 16:28:07 +0300 |
---|---|---|
committer | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2020-09-20 16:28:07 +0300 |
commit | 41c097c15e2d49006847779773aeb9823a6d44d7 (patch) | |
tree | c72d90e093e798efa141baaf8a96b91d2b721840 | |
parent | 8a731a26ae3c5ed5387b933f039569a6f4a8e3e4 (diff) | |
download | libmicrohttpd-41c097c15e2d49006847779773aeb9823a6d44d7.tar.gz libmicrohttpd-41c097c15e2d49006847779773aeb9823a6d44d7.zip |
Re-factor debugging macros.
'MHD_NO' is meaningless for precompiler, used special macro instead
-rw-r--r-- | src/microhttpd/connection.c | 14 | ||||
-rw-r--r-- | src/microhttpd/daemon.c | 22 | ||||
-rw-r--r-- | src/microhttpd/internal.h | 40 |
3 files changed, 44 insertions, 32 deletions
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c index f9f15cec..cf2bfaa1 100644 --- a/src/microhttpd/connection.c +++ b/src/microhttpd/connection.c | |||
@@ -114,16 +114,6 @@ | |||
114 | #define INTERNAL_ERROR "" | 114 | #define INTERNAL_ERROR "" |
115 | #endif | 115 | #endif |
116 | 116 | ||
117 | /** | ||
118 | * Add extra debug messages with reasons for closing connections | ||
119 | * (non-error reasons). | ||
120 | */ | ||
121 | #define DEBUG_CLOSE MHD_NO | ||
122 | |||
123 | /** | ||
124 | * Should all data send be printed to stderr? | ||
125 | */ | ||
126 | #define DEBUG_SEND_DATA MHD_NO | ||
127 | 117 | ||
128 | 118 | ||
129 | /** | 119 | /** |
@@ -2933,7 +2923,7 @@ MHD_connection_handle_write (struct MHD_Connection *connection) | |||
2933 | NULL); | 2923 | NULL); |
2934 | return; | 2924 | return; |
2935 | } | 2925 | } |
2936 | #if DEBUG_SEND_DATA | 2926 | #if _MHD_DEBUG_SEND_DATA |
2937 | fprintf (stderr, | 2927 | fprintf (stderr, |
2938 | _ ("Sent 100 continue response: `%.*s'\n"), | 2928 | _ ("Sent 100 continue response: `%.*s'\n"), |
2939 | (int) ret, | 2929 | (int) ret, |
@@ -3037,7 +3027,7 @@ MHD_connection_handle_write (struct MHD_Connection *connection) | |||
3037 | response->data_size | 3027 | response->data_size |
3038 | - (size_t) data_write_offset, | 3028 | - (size_t) data_write_offset, |
3039 | MHD_SSO_NO_CORK); | 3029 | MHD_SSO_NO_CORK); |
3040 | #if DEBUG_SEND_DATA | 3030 | #if _MHD_DEBUG_SEND_DATA |
3041 | if (ret > 0) | 3031 | if (ret > 0) |
3042 | fprintf (stderr, | 3032 | fprintf (stderr, |
3043 | _ ("Sent %d-byte DATA response: `%.*s'\n"), | 3033 | _ ("Sent %d-byte DATA response: `%.*s'\n"), |
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c index 775faa0b..a9151fc5 100644 --- a/src/microhttpd/daemon.c +++ b/src/microhttpd/daemon.c | |||
@@ -77,18 +77,6 @@ | |||
77 | */ | 77 | */ |
78 | #define MHD_POOL_SIZE_DEFAULT (32 * 1024) | 78 | #define MHD_POOL_SIZE_DEFAULT (32 * 1024) |
79 | 79 | ||
80 | /** | ||
81 | * Print extra messages with reasons for closing | ||
82 | * sockets? (only adds non-error messages). | ||
83 | */ | ||
84 | #define DEBUG_CLOSE MHD_NO | ||
85 | |||
86 | /** | ||
87 | * Print extra messages when establishing | ||
88 | * connections? (only adds non-error messages). | ||
89 | */ | ||
90 | #define DEBUG_CONNECT MHD_NO | ||
91 | |||
92 | 80 | ||
93 | /* Forward declarations. */ | 81 | /* Forward declarations. */ |
94 | 82 | ||
@@ -1081,7 +1069,7 @@ internal_get_fdset2 (struct MHD_Daemon *daemon, | |||
1081 | } | 1069 | } |
1082 | } | 1070 | } |
1083 | #endif | 1071 | #endif |
1084 | #if DEBUG_CONNECT | 1072 | #if _MHD_DEBUG_CONNECT |
1085 | #ifdef HAVE_MESSAGES | 1073 | #ifdef HAVE_MESSAGES |
1086 | if (NULL != max_fd) | 1074 | if (NULL != max_fd) |
1087 | MHD_DLOG (daemon, | 1075 | MHD_DLOG (daemon, |
@@ -2178,7 +2166,7 @@ thread_main_handle_connection (void *data) | |||
2178 | } | 2166 | } |
2179 | #endif /* UPGRADE_SUPPORT */ | 2167 | #endif /* UPGRADE_SUPPORT */ |
2180 | } | 2168 | } |
2181 | #if DEBUG_CLOSE | 2169 | #if _MHD_DEBUG_CLOSE |
2182 | #ifdef HAVE_MESSAGES | 2170 | #ifdef HAVE_MESSAGES |
2183 | MHD_DLOG (con->daemon, | 2171 | MHD_DLOG (con->daemon, |
2184 | _ ("Processing thread terminating. Closing connection.\n")); | 2172 | _ ("Processing thread terminating. Closing connection.\n")); |
@@ -2449,7 +2437,7 @@ internal_add_connection (struct MHD_Daemon *daemon, | |||
2449 | 2437 | ||
2450 | 2438 | ||
2451 | #ifdef HAVE_MESSAGES | 2439 | #ifdef HAVE_MESSAGES |
2452 | #if DEBUG_CONNECT | 2440 | #if _MHD_DEBUG_CONNECT |
2453 | MHD_DLOG (daemon, | 2441 | MHD_DLOG (daemon, |
2454 | _ ("Accepted connection on socket %d.\n"), | 2442 | _ ("Accepted connection on socket %d.\n"), |
2455 | client_socket); | 2443 | client_socket); |
@@ -2479,7 +2467,7 @@ internal_add_connection (struct MHD_Daemon *daemon, | |||
2479 | addr, | 2467 | addr, |
2480 | addrlen)) ) | 2468 | addrlen)) ) |
2481 | { | 2469 | { |
2482 | #if DEBUG_CLOSE | 2470 | #if _MHD_DEBUG_CLOSE |
2483 | #ifdef HAVE_MESSAGES | 2471 | #ifdef HAVE_MESSAGES |
2484 | MHD_DLOG (daemon, | 2472 | MHD_DLOG (daemon, |
2485 | _ ("Connection rejected by application. Closing connection.\n")); | 2473 | _ ("Connection rejected by application. Closing connection.\n")); |
@@ -3310,7 +3298,7 @@ MHD_accept_connection (struct MHD_Daemon *daemon) | |||
3310 | } | 3298 | } |
3311 | #endif /* !USE_ACCEPT4 || !SOCK_CLOEXEC */ | 3299 | #endif /* !USE_ACCEPT4 || !SOCK_CLOEXEC */ |
3312 | #ifdef HAVE_MESSAGES | 3300 | #ifdef HAVE_MESSAGES |
3313 | #if DEBUG_CONNECT | 3301 | #if _MHD_DEBUG_CONNECT |
3314 | MHD_DLOG (daemon, | 3302 | MHD_DLOG (daemon, |
3315 | _ ("Accepted connection on socket %d\n"), | 3303 | _ ("Accepted connection on socket %d\n"), |
3316 | s); | 3304 | s); |
diff --git a/src/microhttpd/internal.h b/src/microhttpd/internal.h index 8f0e821a..cfaca9af 100644 --- a/src/microhttpd/internal.h +++ b/src/microhttpd/internal.h | |||
@@ -76,6 +76,18 @@ | |||
76 | 76 | ||
77 | 77 | ||
78 | /** | 78 | /** |
79 | * @def _MHD_MACRO_NO | ||
80 | * "Negative answer"/"false" for use in macros, meaningful for precompiler | ||
81 | */ | ||
82 | #define _MHD_MACRO_NO 0 | ||
83 | |||
84 | /** | ||
85 | * @def _MHD_MACRO_YES | ||
86 | * "Positive answer"/"true" for use in macros, meaningful for precompiler | ||
87 | */ | ||
88 | #define _MHD_MACRO_YES 1 | ||
89 | |||
90 | /** | ||
79 | * Close FD and abort execution if error is detected. | 91 | * Close FD and abort execution if error is detected. |
80 | * @param fd the FD to close | 92 | * @param fd the FD to close |
81 | */ | 93 | */ |
@@ -84,11 +96,33 @@ | |||
84 | MHD_PANIC (_ ("Failed to close FD.\n")); \ | 96 | MHD_PANIC (_ ("Failed to close FD.\n")); \ |
85 | } while (0) | 97 | } while (0) |
86 | 98 | ||
99 | /* | ||
100 | #define EXTRA_CHECKS _MHD_MACRO_NO | ||
101 | * Not used. Behaviour is controlled by _DEBUG/NDEBUG macros. | ||
102 | */ | ||
103 | |||
104 | #ifndef _MHD_DEBUG_CONNECT | ||
105 | /** | ||
106 | * Print extra messages when establishing | ||
107 | * connections? (only adds non-error messages). | ||
108 | */ | ||
109 | #define _MHD_DEBUG_CONNECT _MHD_MACRO_NO | ||
110 | #endif /* ! _MHD_DEBUG_CONNECT */ | ||
111 | |||
112 | #ifndef _MHD_DEBUG_SEND_DATA | ||
113 | /** | ||
114 | * Should all data send be printed to stderr? | ||
115 | */ | ||
116 | #define _MHD_DEBUG_SEND_DATA _MHD_MACRO_NO | ||
117 | #endif /* ! _MHD_DEBUG_SEND_DATA */ | ||
118 | |||
119 | #ifndef _MHD_DEBUG_CLOSE | ||
87 | /** | 120 | /** |
88 | * Should we perform additional sanity checks at runtime (on our internal | 121 | * Add extra debug messages with reasons for closing connections |
89 | * invariants)? This may lead to aborts, but can be useful for debugging. | 122 | * (non-error reasons). |
90 | */ | 123 | */ |
91 | #define EXTRA_CHECKS MHD_NO | 124 | #define _MHD_DEBUG_CLOSE _MHD_MACRO_NO |
125 | #endif /* ! _MHD_DEBUG_CLOSE */ | ||
92 | 126 | ||
93 | #define MHD_MAX(a,b) (((a)<(b)) ? (b) : (a)) | 127 | #define MHD_MAX(a,b) (((a)<(b)) ? (b) : (a)) |
94 | #define MHD_MIN(a,b) (((a)<(b)) ? (a) : (b)) | 128 | #define MHD_MIN(a,b) (((a)<(b)) ? (a) : (b)) |