|
10 | 10 | #include <string>
|
11 | 11 | #include <sstream>
|
12 | 12 |
|
| 13 | +#ifdef DEBUG |
13 | 14 | #define CHECK(status, msg) \
|
14 | 15 | if (status != 0) { \
|
15 | 16 | fprintf(stderr, "%s: %s\n", msg, uv_err_name(status)); \
|
|
19 | 20 | #define LOG_ERROR(msg) puts(msg);
|
20 | 21 | #define LOG(msg) puts(msg);
|
21 | 22 | #define LOGF(fmt, params...) printf(fmt "\n", params);
|
22 |
| - |
| 23 | +#else |
| 24 | +#define CHECK(status, msg) |
| 25 | +#define UVERR(err, msg) |
| 26 | +#define LOG_ERROR(msg) |
| 27 | +#define LOG(msg) |
| 28 | +#define LOGF(fmt, params...) |
| 29 | +#endif |
23 | 30 | static int request_num = 1;
|
24 | 31 | static uv_loop_t* uv_loop;
|
25 | 32 | static uv_tcp_t server;
|
@@ -120,36 +127,36 @@ void after_render(uv_work_t* req) {
|
120 | 127 | }
|
121 | 128 |
|
122 | 129 | int on_message_begin(http_parser* /*parser*/) {
|
123 |
| - printf("\n***MESSAGE BEGIN***\n\n"); |
| 130 | + LOGF("\n***MESSAGE BEGIN***\n\n"); |
124 | 131 | return 0;
|
125 | 132 | }
|
126 | 133 |
|
127 | 134 | int on_headers_complete(http_parser* /*parser*/) {
|
128 |
| - printf("\n***HEADERS COMPLETE***\n\n"); |
| 135 | + LOGF("\n***HEADERS COMPLETE***\n\n"); |
129 | 136 | return 0;
|
130 | 137 | }
|
131 | 138 |
|
132 | 139 | int on_url(http_parser* /*parser*/, const char* at, size_t length) {
|
133 |
| - printf("Url: %.*s\n", (int)length, at); |
| 140 | + LOGF("Url: %.*s\n", (int)length, at); |
134 | 141 | return 0;
|
135 | 142 | }
|
136 | 143 |
|
137 | 144 | int on_header_field(http_parser* /*parser*/, const char* at, size_t length) {
|
138 |
| - printf("Header field: %.*s\n", (int)length, at); |
| 145 | + LOGF("Header field: %.*s\n", (int)length, at); |
139 | 146 | return 0;
|
140 | 147 | }
|
141 | 148 |
|
142 | 149 | int on_header_value(http_parser* /*parser*/, const char* at, size_t length) {
|
143 |
| - printf("Header value: %.*s\n", (int)length, at); |
| 150 | + LOGF("Header value: %.*s\n", (int)length, at); |
144 | 151 | return 0;
|
145 | 152 | }
|
146 | 153 |
|
147 | 154 | int on_body(http_parser* /*parser*/, const char* at, size_t length) {
|
148 |
| - printf("Body: %.*s\n", (int)length, at); |
| 155 | + LOGF("Body: %.*s\n", (int)length, at); |
149 | 156 | return 0;
|
150 | 157 | }
|
151 | 158 | int on_message_complete(http_parser* parser) {
|
152 |
| - printf("\n***MESSAGE COMPLETE***\n\n"); |
| 159 | + LOGF("\n***MESSAGE COMPLETE***\n\n"); |
153 | 160 |
|
154 | 161 | client_t* client = (client_t*) parser->data;
|
155 | 162 |
|
|
0 commit comments