aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2007-08-19 08:45:43 +0000
committerChristian Grothoff <christian@grothoff.org>2007-08-19 08:45:43 +0000
commitfc6a31231af76afb7e6c4dfe15a3e009f2e518fc (patch)
tree042112a34429393bc2ac338ba8f41b5a5e573d7d
parent806387b6052d1892b511a9701117a33591c1aa05 (diff)
downloadlibmicrohttpd-fc6a31231af76afb7e6c4dfe15a3e009f2e518fc.tar.gz
libmicrohttpd-fc6a31231af76afb7e6c4dfe15a3e009f2e518fc.zip
more logging and fix in usec calculation
-rw-r--r--src/daemon/connection.c51
-rw-r--r--src/daemon/daemon.c28
2 files changed, 76 insertions, 3 deletions
diff --git a/src/daemon/connection.c b/src/daemon/connection.c
index 6735147a..864e1190 100644
--- a/src/daemon/connection.c
+++ b/src/daemon/connection.c
@@ -43,6 +43,19 @@
43#define REQUEST_TOO_BIG "" 43#define REQUEST_TOO_BIG ""
44 44
45/** 45/**
46 * Add extra debug messages with reasons for closing connections
47 * (non-error reasons).
48 */
49#define DEBUG_CLOSE 0
50
51
52/**
53 * Should all data send be printed to stderr?
54 */
55#define DEBUG_SEND_DATA 0
56
57
58/**
46 * Get all of the headers from the request. 59 * Get all of the headers from the request.
47 * 60 *
48 * @param iterator callback to call on each header; 61 * @param iterator callback to call on each header;
@@ -179,6 +192,10 @@ ready_response (struct MHD_Connection *connection)
179 if (ret == -1) 192 if (ret == -1)
180 { 193 {
181 /* end of message, signal other side by closing! */ 194 /* end of message, signal other side by closing! */
195#if DEBUG_CLOSE
196 MHD_DLOG (connection->daemon,
197 "Closing connection (end of response)\n");
198#endif
182 response->total_size = connection->messagePos; 199 response->total_size = connection->messagePos;
183 CLOSE (connection->socket_fd); 200 CLOSE (connection->socket_fd);
184 connection->socket_fd = -1; 201 connection->socket_fd = -1;
@@ -693,6 +710,8 @@ MHD_parse_connection_headers (struct MHD_Connection *connection)
693 MHD_parse_cookie_header (connection); 710 MHD_parse_cookie_header (connection);
694 return; 711 return;
695DIE: 712DIE:
713 MHD_DLOG (connection->daemon,
714 "Closing connection (problem parsing headers)\n");
696 CLOSE (connection->socket_fd); 715 CLOSE (connection->socket_fd);
697 connection->socket_fd = -1; 716 connection->socket_fd = -1;
698} 717}
@@ -930,6 +949,10 @@ MHD_connection_handle_read (struct MHD_Connection *connection)
930 connection->read_close = MHD_YES; 949 connection->read_close = MHD_YES;
931 if (connection->readLoc > 0) 950 if (connection->readLoc > 0)
932 MHD_call_connection_handler (connection); 951 MHD_call_connection_handler (connection);
952#if DEBUG_CLOSE
953 MHD_DLOG (connection->daemon,
954 "Shutting down connection for reading (other side closed connection)\n");
955#endif
933 shutdown (connection->socket_fd, SHUT_RD); 956 shutdown (connection->socket_fd, SHUT_RD);
934 return MHD_YES; 957 return MHD_YES;
935 } 958 }
@@ -1096,7 +1119,12 @@ MHD_connection_handle_write (struct MHD_Connection *connection)
1096 connection->socket_fd = -1; 1119 connection->socket_fd = -1;
1097 return MHD_YES; 1120 return MHD_YES;
1098 } 1121 }
1099 connection->continuePos += ret; 1122#if DEBUG_SEND_DATA
1123 fprintf(stderr,
1124 "Sent 100 continue response: `%.*s'\n",
1125 ret,
1126 &HTTP_100_CONTINUE[connection->continuePos]);
1127#endif
1100 return MHD_YES; 1128 return MHD_YES;
1101 } 1129 }
1102 response = connection->response; 1130 response = connection->response;
@@ -1111,6 +1139,8 @@ MHD_connection_handle_write (struct MHD_Connection *connection)
1111 (MHD_NO == MHD_build_header_response (connection))) 1139 (MHD_NO == MHD_build_header_response (connection)))
1112 { 1140 {
1113 /* oops - close! */ 1141 /* oops - close! */
1142 MHD_DLOG (connection->daemon,
1143 "Closing connection (failed to create response header)\n");
1114 CLOSE (connection->socket_fd); 1144 CLOSE (connection->socket_fd);
1115 connection->socket_fd = -1; 1145 connection->socket_fd = -1;
1116 return MHD_NO; 1146 return MHD_NO;
@@ -1128,6 +1158,12 @@ MHD_connection_handle_write (struct MHD_Connection *connection)
1128 connection->socket_fd = -1; 1158 connection->socket_fd = -1;
1129 return MHD_YES; 1159 return MHD_YES;
1130 } 1160 }
1161#if DEBUG_SEND_DATA
1162 fprintf(stderr,
1163 "Sent HEADER response: `%.*s'\n",
1164 ret,
1165 &connection->write_buffer[connection->writePos]);
1166#endif
1131 connection->writePos += ret; 1167 connection->writePos += ret;
1132 if (connection->writeLoc == connection->writePos) 1168 if (connection->writeLoc == connection->writePos)
1133 { 1169 {
@@ -1173,6 +1209,12 @@ MHD_connection_handle_write (struct MHD_Connection *connection)
1173 connection->socket_fd = -1; 1209 connection->socket_fd = -1;
1174 return MHD_YES; 1210 return MHD_YES;
1175 } 1211 }
1212#if DEBUG_SEND_DATA
1213 fprintf(stderr,
1214 "Sent DATA response: `%.*s'\n",
1215 ret,
1216 &response->data[connection->messagePos - response->data_start]);
1217#endif
1176 connection->messagePos += ret; 1218 connection->messagePos += ret;
1177 if (connection->messagePos > response->total_size) 1219 if (connection->messagePos > response->total_size)
1178 abort (); /* internal error */ 1220 abort (); /* internal error */
@@ -1196,8 +1238,13 @@ MHD_connection_handle_write (struct MHD_Connection *connection)
1196 (0 != strcasecmp (MHD_HTTP_VERSION_1_1, connection->version))) 1238 (0 != strcasecmp (MHD_HTTP_VERSION_1_1, connection->version)))
1197 { 1239 {
1198 /* closed for reading => close for good! */ 1240 /* closed for reading => close for good! */
1199 if (connection->socket_fd != -1) 1241 if (connection->socket_fd != -1) {
1242#if DEBUG_CLOSE
1243 MHD_DLOG (connection->daemon,
1244 "Closing connection (http 1.0 or end-of-stream for unknown content length)\n");
1245#endif
1200 CLOSE (connection->socket_fd); 1246 CLOSE (connection->socket_fd);
1247 }
1201 connection->socket_fd = -1; 1248 connection->socket_fd = -1;
1202 } 1249 }
1203 connection->version = NULL; 1250 connection->version = NULL;
diff --git a/src/daemon/daemon.c b/src/daemon/daemon.c
index 385e37c3..79963d6b 100644
--- a/src/daemon/daemon.c
+++ b/src/daemon/daemon.c
@@ -41,6 +41,12 @@
41#define MHD_POOL_SIZE_DEFAULT (1024 * 1024) 41#define MHD_POOL_SIZE_DEFAULT (1024 * 1024)
42 42
43/** 43/**
44 * Print extra messages with reasons for closing
45 * sockets? (only adds non-error messages).
46 */
47#define DEBUG_CLOSE 0
48
49/**
44 * Register an access handler for all URIs beginning with uri_prefix. 50 * Register an access handler for all URIs beginning with uri_prefix.
45 * 51 *
46 * @param uri_prefix 52 * @param uri_prefix
@@ -218,6 +224,10 @@ MHD_handle_connection (void *data)
218 } 224 }
219 if (con->socket_fd != -1) 225 if (con->socket_fd != -1)
220 { 226 {
227#if DEBUG_CLOSE
228 MHD_DLOG (con->daemon,
229 "Processing thread terminating, closing connection\n");
230#endif
221 CLOSE (con->socket_fd); 231 CLOSE (con->socket_fd);
222 con->socket_fd = -1; 232 con->socket_fd = -1;
223 } 233 }
@@ -263,6 +273,10 @@ MHD_accept_connection (struct MHD_Daemon *daemon)
263 if ((daemon->apc != NULL) && 273 if ((daemon->apc != NULL) &&
264 (MHD_NO == daemon->apc (daemon->apc_cls, addr, addrlen))) 274 (MHD_NO == daemon->apc (daemon->apc_cls, addr, addrlen)))
265 { 275 {
276#if DEBUG_CLOSE
277 MHD_DLOG (daemon,
278 "Connection rejected, closing connection\n");
279#endif
266 CLOSE (s); 280 CLOSE (s);
267 return MHD_YES; 281 return MHD_YES;
268 } 282 }
@@ -334,6 +348,10 @@ MHD_cleanup_connections (struct MHD_Daemon *daemon)
334 { 348 {
335 if ((pos->last_activity < timeout) && (pos->socket_fd != -1)) 349 if ((pos->last_activity < timeout) && (pos->socket_fd != -1))
336 { 350 {
351#if DEBUG_CLOSE
352 MHD_DLOG (daemon,
353 "Connection timed out, closing connection\n");
354#endif
337 CLOSE (pos->socket_fd); 355 CLOSE (pos->socket_fd);
338 pos->socket_fd = -1; 356 pos->socket_fd = -1;
339 } 357 }
@@ -470,7 +488,7 @@ MHD_select (struct MHD_Daemon *daemon, int may_block)
470 /* ltimeout is in ms */ 488 /* ltimeout is in ms */
471 if (MHD_YES == MHD_get_timeout (daemon, &ltimeout)) 489 if (MHD_YES == MHD_get_timeout (daemon, &ltimeout))
472 { 490 {
473 timeout.tv_usec = (ltimeout % 1000) * 1000 * 1000; 491 timeout.tv_usec = (ltimeout % 1000) * 1000;
474 timeout.tv_sec = ltimeout / 1000; 492 timeout.tv_sec = ltimeout / 1000;
475 may_block = MHD_NO; 493 may_block = MHD_NO;
476 } 494 }
@@ -705,6 +723,10 @@ MHD_stop_daemon (struct MHD_Daemon *daemon)
705 daemon->shutdown = MHD_YES; 723 daemon->shutdown = MHD_YES;
706 fd = daemon->socket_fd; 724 fd = daemon->socket_fd;
707 daemon->socket_fd = -1; 725 daemon->socket_fd = -1;
726#if DEBUG_CLOSE
727 MHD_DLOG (daemon,
728 "MHD shutdown, closing listen socket\n");
729#endif
708 CLOSE (fd); 730 CLOSE (fd);
709 if ((0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) || 731 if ((0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) ||
710 (0 != (daemon->options & MHD_USE_SELECT_INTERNALLY))) 732 (0 != (daemon->options & MHD_USE_SELECT_INTERNALLY)))
@@ -716,6 +738,10 @@ MHD_stop_daemon (struct MHD_Daemon *daemon)
716 { 738 {
717 if (-1 != daemon->connections->socket_fd) 739 if (-1 != daemon->connections->socket_fd)
718 { 740 {
741#if DEBUG_CLOSE
742 MHD_DLOG (daemon,
743 "MHD shutdown, closing active connections\n");
744#endif
719 CLOSE (daemon->connections->socket_fd); 745 CLOSE (daemon->connections->socket_fd);
720 daemon->connections->socket_fd = -1; 746 daemon->connections->socket_fd = -1;
721 } 747 }