瀏覽代碼

conn_mark_ready: unified duplicated code

Evgeny Grin (Karlson2k) 1 年之前
父節點
當前提交
835c9fac96
共有 3 個文件被更改,包括 56 次插入13 次删除
  1. 54 0
      src/mhd2/conn_mark_ready.h
  2. 1 7
      src/mhd2/events_process.c
  3. 1 6
      src/mhd2/stream_process_states.c

+ 54 - 0
src/mhd2/conn_mark_ready.h

@@ -94,4 +94,58 @@ mhd_conn_mark_unready (struct MHD_Connection *restrict c,
 }
 
 
+/**
+ * Update "ready" mark on the connection, remove or add connection to
+ * the "process ready" list if necessary.
+ * @param c the connection to update
+ * @param force_ready ignore network states and mark the connection as "ready"
+ * @param d the daemon for the connection
+ */
+MHD_static_inline_ MHD_FN_PAR_NONNULL_ALL_ void
+mhd_conn_mark_ready_update3 (struct MHD_Connection *restrict c,
+                             unsigned int force_ready,
+                             struct MHD_Daemon *restrict d)
+{
+  if (force_ready ||
+      (0 !=
+       (((unsigned int) c->sk.ready) & ((unsigned int) c->event_loop_info)
+        & (MHD_EVENT_LOOP_INFO_RECV | MHD_EVENT_LOOP_INFO_SEND))))
+    mhd_conn_mark_ready (c, d);
+  else
+    mhd_conn_mark_unready (c, d);
+}
+
+
+/**
+ * Update "ready" mark on the connection, remove or add connection to
+ * the "process ready" list if necessary.
+ * This function could be used if the "daemon" handle is already extracted
+ * from the connection.
+ * @param c the connection to update
+ * @param d the daemon for the connection
+ */
+MHD_static_inline_ MHD_FN_PAR_NONNULL_ALL_ void
+mhd_conn_mark_ready_update2 (struct MHD_Connection *restrict c,
+                             struct MHD_Daemon *restrict d)
+{
+  mhd_conn_mark_ready_update3 (c, 0, d);
+}
+
+
+/**
+ * Update "ready" mark on the connection, remove or add connection to
+ * the "process ready" list if necessary.
+ * This function could be used if the "daemon" handle has not been extracted
+ * from the connection.
+ * @param c the connection to update
+ * @param d the daemon for the connection
+ */
+MHD_static_inline_ MHD_FN_PAR_NONNULL_ALL_ void
+mhd_conn_mark_ready_update (struct MHD_Connection *restrict c)
+{
+  mhd_conn_mark_ready_update2 (c,
+                               c->daemon);
+}
+
+
 #endif /* ! MHD_CONN_MARK_READY_H */

+ 1 - 7
src/mhd2/events_process.c

@@ -103,13 +103,7 @@ update_conn_net_status (struct MHD_Daemon *restrict d,
                (sk_state | (unsigned int) mhd_SOCKET_NET_STATE_ERROR_READY);
   c->sk.ready = sk_state;
 
-  if ((0 !=
-       (((unsigned int) c->sk.ready) & ((unsigned int) c->event_loop_info)
-        & (MHD_EVENT_LOOP_INFO_RECV | MHD_EVENT_LOOP_INFO_SEND)))
-      || err_state)
-    mhd_conn_mark_ready (c, d);
-  else
-    mhd_conn_mark_unready (c, d);
+  mhd_conn_mark_ready_update3 (c, err_state, d);
 }
 
 

+ 1 - 6
src/mhd2/stream_process_states.c

@@ -211,12 +211,7 @@ update_active_state (struct MHD_Connection *restrict c)
   /* Sockets errors must be already handled */
   mhd_assert (0 == (c->sk.ready & mhd_SOCKET_NET_STATE_ERROR_READY));
 
-  if (0 !=
-      (((unsigned int) c->sk.ready) & ((unsigned int) c->event_loop_info)
-       & (MHD_EVENT_LOOP_INFO_RECV | MHD_EVENT_LOOP_INFO_SEND)))
-    mhd_conn_mark_ready (c, c->daemon);
-  else
-    mhd_conn_mark_unready (c, c->daemon);
+  mhd_conn_mark_ready_update (c);
 
   return true;
 }