mirror of
https://git.gnunet.org/libmicrohttpd.git
synced 2026-09-25 04:09:31 +03:00
more logging and fix in usec calculation
This commit is contained in:
+49
-2
@@ -42,6 +42,19 @@
|
||||
*/
|
||||
#define REQUEST_TOO_BIG ""
|
||||
|
||||
/**
|
||||
* Add extra debug messages with reasons for closing connections
|
||||
* (non-error reasons).
|
||||
*/
|
||||
#define DEBUG_CLOSE 0
|
||||
|
||||
|
||||
/**
|
||||
* Should all data send be printed to stderr?
|
||||
*/
|
||||
#define DEBUG_SEND_DATA 0
|
||||
|
||||
|
||||
/**
|
||||
* Get all of the headers from the request.
|
||||
*
|
||||
@@ -179,6 +192,10 @@ ready_response (struct MHD_Connection *connection)
|
||||
if (ret == -1)
|
||||
{
|
||||
/* end of message, signal other side by closing! */
|
||||
#if DEBUG_CLOSE
|
||||
MHD_DLOG (connection->daemon,
|
||||
"Closing connection (end of response)\n");
|
||||
#endif
|
||||
response->total_size = connection->messagePos;
|
||||
CLOSE (connection->socket_fd);
|
||||
connection->socket_fd = -1;
|
||||
@@ -693,6 +710,8 @@ MHD_parse_connection_headers (struct MHD_Connection *connection)
|
||||
MHD_parse_cookie_header (connection);
|
||||
return;
|
||||
DIE:
|
||||
MHD_DLOG (connection->daemon,
|
||||
"Closing connection (problem parsing headers)\n");
|
||||
CLOSE (connection->socket_fd);
|
||||
connection->socket_fd = -1;
|
||||
}
|
||||
@@ -930,6 +949,10 @@ MHD_connection_handle_read (struct MHD_Connection *connection)
|
||||
connection->read_close = MHD_YES;
|
||||
if (connection->readLoc > 0)
|
||||
MHD_call_connection_handler (connection);
|
||||
#if DEBUG_CLOSE
|
||||
MHD_DLOG (connection->daemon,
|
||||
"Shutting down connection for reading (other side closed connection)\n");
|
||||
#endif
|
||||
shutdown (connection->socket_fd, SHUT_RD);
|
||||
return MHD_YES;
|
||||
}
|
||||
@@ -1096,7 +1119,12 @@ MHD_connection_handle_write (struct MHD_Connection *connection)
|
||||
connection->socket_fd = -1;
|
||||
return MHD_YES;
|
||||
}
|
||||
connection->continuePos += ret;
|
||||
#if DEBUG_SEND_DATA
|
||||
fprintf(stderr,
|
||||
"Sent 100 continue response: `%.*s'\n",
|
||||
ret,
|
||||
&HTTP_100_CONTINUE[connection->continuePos]);
|
||||
#endif
|
||||
return MHD_YES;
|
||||
}
|
||||
response = connection->response;
|
||||
@@ -1111,6 +1139,8 @@ MHD_connection_handle_write (struct MHD_Connection *connection)
|
||||
(MHD_NO == MHD_build_header_response (connection)))
|
||||
{
|
||||
/* oops - close! */
|
||||
MHD_DLOG (connection->daemon,
|
||||
"Closing connection (failed to create response header)\n");
|
||||
CLOSE (connection->socket_fd);
|
||||
connection->socket_fd = -1;
|
||||
return MHD_NO;
|
||||
@@ -1128,6 +1158,12 @@ MHD_connection_handle_write (struct MHD_Connection *connection)
|
||||
connection->socket_fd = -1;
|
||||
return MHD_YES;
|
||||
}
|
||||
#if DEBUG_SEND_DATA
|
||||
fprintf(stderr,
|
||||
"Sent HEADER response: `%.*s'\n",
|
||||
ret,
|
||||
&connection->write_buffer[connection->writePos]);
|
||||
#endif
|
||||
connection->writePos += ret;
|
||||
if (connection->writeLoc == connection->writePos)
|
||||
{
|
||||
@@ -1173,6 +1209,12 @@ MHD_connection_handle_write (struct MHD_Connection *connection)
|
||||
connection->socket_fd = -1;
|
||||
return MHD_YES;
|
||||
}
|
||||
#if DEBUG_SEND_DATA
|
||||
fprintf(stderr,
|
||||
"Sent DATA response: `%.*s'\n",
|
||||
ret,
|
||||
&response->data[connection->messagePos - response->data_start]);
|
||||
#endif
|
||||
connection->messagePos += ret;
|
||||
if (connection->messagePos > response->total_size)
|
||||
abort (); /* internal error */
|
||||
@@ -1196,8 +1238,13 @@ MHD_connection_handle_write (struct MHD_Connection *connection)
|
||||
(0 != strcasecmp (MHD_HTTP_VERSION_1_1, connection->version)))
|
||||
{
|
||||
/* closed for reading => close for good! */
|
||||
if (connection->socket_fd != -1)
|
||||
if (connection->socket_fd != -1) {
|
||||
#if DEBUG_CLOSE
|
||||
MHD_DLOG (connection->daemon,
|
||||
"Closing connection (http 1.0 or end-of-stream for unknown content length)\n");
|
||||
#endif
|
||||
CLOSE (connection->socket_fd);
|
||||
}
|
||||
connection->socket_fd = -1;
|
||||
}
|
||||
connection->version = NULL;
|
||||
|
||||
+27
-1
@@ -40,6 +40,12 @@
|
||||
*/
|
||||
#define MHD_POOL_SIZE_DEFAULT (1024 * 1024)
|
||||
|
||||
/**
|
||||
* Print extra messages with reasons for closing
|
||||
* sockets? (only adds non-error messages).
|
||||
*/
|
||||
#define DEBUG_CLOSE 0
|
||||
|
||||
/**
|
||||
* Register an access handler for all URIs beginning with uri_prefix.
|
||||
*
|
||||
@@ -218,6 +224,10 @@ MHD_handle_connection (void *data)
|
||||
}
|
||||
if (con->socket_fd != -1)
|
||||
{
|
||||
#if DEBUG_CLOSE
|
||||
MHD_DLOG (con->daemon,
|
||||
"Processing thread terminating, closing connection\n");
|
||||
#endif
|
||||
CLOSE (con->socket_fd);
|
||||
con->socket_fd = -1;
|
||||
}
|
||||
@@ -263,6 +273,10 @@ MHD_accept_connection (struct MHD_Daemon *daemon)
|
||||
if ((daemon->apc != NULL) &&
|
||||
(MHD_NO == daemon->apc (daemon->apc_cls, addr, addrlen)))
|
||||
{
|
||||
#if DEBUG_CLOSE
|
||||
MHD_DLOG (daemon,
|
||||
"Connection rejected, closing connection\n");
|
||||
#endif
|
||||
CLOSE (s);
|
||||
return MHD_YES;
|
||||
}
|
||||
@@ -334,6 +348,10 @@ MHD_cleanup_connections (struct MHD_Daemon *daemon)
|
||||
{
|
||||
if ((pos->last_activity < timeout) && (pos->socket_fd != -1))
|
||||
{
|
||||
#if DEBUG_CLOSE
|
||||
MHD_DLOG (daemon,
|
||||
"Connection timed out, closing connection\n");
|
||||
#endif
|
||||
CLOSE (pos->socket_fd);
|
||||
pos->socket_fd = -1;
|
||||
}
|
||||
@@ -470,7 +488,7 @@ MHD_select (struct MHD_Daemon *daemon, int may_block)
|
||||
/* ltimeout is in ms */
|
||||
if (MHD_YES == MHD_get_timeout (daemon, <imeout))
|
||||
{
|
||||
timeout.tv_usec = (ltimeout % 1000) * 1000 * 1000;
|
||||
timeout.tv_usec = (ltimeout % 1000) * 1000;
|
||||
timeout.tv_sec = ltimeout / 1000;
|
||||
may_block = MHD_NO;
|
||||
}
|
||||
@@ -705,6 +723,10 @@ MHD_stop_daemon (struct MHD_Daemon *daemon)
|
||||
daemon->shutdown = MHD_YES;
|
||||
fd = daemon->socket_fd;
|
||||
daemon->socket_fd = -1;
|
||||
#if DEBUG_CLOSE
|
||||
MHD_DLOG (daemon,
|
||||
"MHD shutdown, closing listen socket\n");
|
||||
#endif
|
||||
CLOSE (fd);
|
||||
if ((0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) ||
|
||||
(0 != (daemon->options & MHD_USE_SELECT_INTERNALLY)))
|
||||
@@ -716,6 +738,10 @@ MHD_stop_daemon (struct MHD_Daemon *daemon)
|
||||
{
|
||||
if (-1 != daemon->connections->socket_fd)
|
||||
{
|
||||
#if DEBUG_CLOSE
|
||||
MHD_DLOG (daemon,
|
||||
"MHD shutdown, closing active connections\n");
|
||||
#endif
|
||||
CLOSE (daemon->connections->socket_fd);
|
||||
daemon->connections->socket_fd = -1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user