소스 검색

Added debug print for connection add/close

Evgeny Grin (Karlson2k) 10 달 전
부모
커밋
e3beaafbfe
3개의 변경된 파일61개의 추가작업 그리고 4개의 파일을 삭제
  1. 5 0
      src/incl_priv/mhd_sys_options.h
  2. 48 3
      src/mhd2/daemon_add_conn.c
  3. 8 1
      src/mhd2/stream_funcs.c

+ 5 - 0
src/incl_priv/mhd_sys_options.h

@@ -526,6 +526,11 @@
 /* #  define mhd_DEBUG_SUSPEND_RESUME 1 */
 /* #  define mhd_DEBUG_SUSPEND_RESUME 1 */
 #endif
 #endif
 
 
+#ifndef mhd_DEBUG_CONN_ADD_CLOSE
+/* Use debug-print for adding and closing of the connections */
+/* #  define mhd_DEBUG_CONN_ADD_CLOSE 1 */
+#endif
+
 #ifndef MHD_AUTH_DIGEST_DEF_TIMEOUT
 #ifndef MHD_AUTH_DIGEST_DEF_TIMEOUT
 #  define MHD_AUTH_DIGEST_DEF_TIMEOUT 90
 #  define MHD_AUTH_DIGEST_DEF_TIMEOUT 90
 #endif /* ! MHD_AUTH_DIGEST_DEF_TIMEOUT */
 #endif /* ! MHD_AUTH_DIGEST_DEF_TIMEOUT */

+ 48 - 3
src/mhd2/daemon_add_conn.c

@@ -43,6 +43,9 @@
 #include "sys_sockets_headers.h"
 #include "sys_sockets_headers.h"
 #include "sys_ip_headers.h"
 #include "sys_ip_headers.h"
 
 
+#ifdef mhd_DEBUG_CONN_ADD_CLOSE
+#  include <stdio.h>
+#endif /* mhd_DEBUG_CONN_ADD_CLOSE */
 #include <string.h>
 #include <string.h>
 #ifdef MHD_SUPPORT_EPOLL
 #ifdef MHD_SUPPORT_EPOLL
 #  include <sys/epoll.h>
 #  include <sys/epoll.h>
@@ -280,6 +283,7 @@ new_connection_prepare_ (struct MHD_Daemon *restrict daemon,
 
 
 
 
 /**
 /**
+ * Internal (inner) function.
  * Finally insert the new connection to the list of connections
  * Finally insert the new connection to the list of connections
  * served by the daemon and start processing.
  * served by the daemon and start processing.
  * @remark To be called only from thread that process
  * @remark To be called only from thread that process
@@ -287,11 +291,12 @@ new_connection_prepare_ (struct MHD_Daemon *restrict daemon,
  *
  *
  * @param daemon daemon that manages the connection
  * @param daemon daemon that manages the connection
  * @param connection the newly created connection
  * @param connection the newly created connection
- * @return #MHD_YES on success, #MHD_NO on error
+ * @return #MHD_SC_OK on success,
+ *         error code otherwise
  */
  */
 static enum MHD_StatusCode
 static enum MHD_StatusCode
-new_connection_process_ (struct MHD_Daemon *restrict daemon,
-                         struct MHD_Connection *restrict connection)
+new_connection_process_inner (struct MHD_Daemon *restrict daemon,
+                              struct MHD_Connection *restrict connection)
 {
 {
   enum MHD_StatusCode res;
   enum MHD_StatusCode res;
   mhd_assert (connection->daemon == daemon);
   mhd_assert (connection->daemon == daemon);
@@ -437,6 +442,41 @@ new_connection_process_ (struct MHD_Daemon *restrict daemon,
 }
 }
 
 
 
 
+/**
+ * Finally insert the new connection to the list of connections
+ * served by the daemon and start processing.
+ * @remark To be called only from thread that process
+ * daemon's select()/poll()/etc.
+ *
+ * @param daemon daemon that manages the connection
+ * @param connection the newly created connection
+ * @return #MHD_SC_OK on success,
+ *         error code otherwise
+ */
+static enum MHD_StatusCode
+new_connection_process_ (struct MHD_Daemon *restrict daemon,
+                         struct MHD_Connection *restrict connection)
+{
+  enum MHD_StatusCode res;
+
+  res = new_connection_process_inner (daemon,
+                                      connection);
+#ifdef mhd_DEBUG_CONN_ADD_CLOSE
+  if (MHD_SC_OK == res)
+    fprintf (stderr,
+             "&&&  Added new connection, FD: %llu\n",
+             (unsigned long long) connection->sk.fd);
+  else
+    fprintf (stderr,
+             "&&& Failed add connection, FD: %llu -> %u\n",
+             (unsigned long long) connection->sk.fd,
+             (unsigned int) res);
+#endif /* mhd_DEBUG_CONN_ADD_CLOSE */
+
+  return res;
+}
+
+
 /**
 /**
  * The given client socket will be managed (and closed!) by MHD after
  * The given client socket will be managed (and closed!) by MHD after
  * this call and must no longer be used directly by the application
  * this call and must no longer be used directly by the application
@@ -1061,6 +1101,11 @@ mhd_conn_close_final (struct MHD_Connection *restrict c)
   if (NULL != c->sk.addr.data)
   if (NULL != c->sk.addr.data)
     free (c->sk.addr.data);
     free (c->sk.addr.data);
   mhd_socket_close (c->sk.fd);
   mhd_socket_close (c->sk.fd);
+#ifdef mhd_DEBUG_CONN_ADD_CLOSE
+  fprintf (stderr,
+           "&&&     Closed connection, FD: %llu\n",
+           (unsigned long long) c->sk.fd);
+#endif /* mhd_DEBUG_CONN_ADD_CLOSE */
 
 
   free (c);
   free (c);
 }
 }

+ 8 - 1
src/mhd2/stream_funcs.c

@@ -31,6 +31,9 @@
 #include "mhd_assert.h"
 #include "mhd_assert.h"
 #include "mhd_unreachable.h"
 #include "mhd_unreachable.h"
 
 
+#ifdef mhd_DEBUG_CONN_ADD_CLOSE
+#  include <stdio.h>
+#endif /* mhd_DEBUG_CONN_ADD_CLOSE */
 #include <string.h>
 #include <string.h>
 #include "extr_events_funcs.h"
 #include "extr_events_funcs.h"
 #ifdef MHD_SUPPORT_EPOLL
 #ifdef MHD_SUPPORT_EPOLL
@@ -1025,7 +1028,11 @@ MHD_INTERNAL
 MHD_FN_PAR_NONNULL_ (1) void
 MHD_FN_PAR_NONNULL_ (1) void
 mhd_conn_pre_clean (struct MHD_Connection *restrict c)
 mhd_conn_pre_clean (struct MHD_Connection *restrict c)
 {
 {
-  // TODO: support suspended connections
+#ifdef mhd_DEBUG_CONN_ADD_CLOSE
+  fprintf (stderr,
+           "&&&    Closing connection, FD: %llu\n",
+           (unsigned long long) c->sk.fd);
+#endif /* mhd_DEBUG_CONN_ADD_CLOSE */
 
 
   mhd_assert (c->dbg.closing_started);
   mhd_assert (c->dbg.closing_started);
   mhd_assert (! c->dbg.pre_cleaned);
   mhd_assert (! c->dbg.pre_cleaned);