Parcourir la source

stream_process_states: extracted one function for internal access

Evgeny Grin (Karlson2k) il y a 1 an
Parent
commit
540078c600
2 fichiers modifiés avec 43 ajouts et 14 suppressions
  1. 29 12
      src/mhd2/stream_process_states.c
  2. 14 2
      src/mhd2/stream_process_states.h

+ 29 - 12
src/mhd2/stream_process_states.c

@@ -52,17 +52,8 @@
 #  include "upgrade_proc.h"
 #endif /* MHD_UPGRADE_SUPPORT */
 
-/**
- * Update current processing state: need to receive, need to send.
- * Mark stream as ready or not ready for processing.
- * Grow the receive buffer if neccesary, close stream if no buffer space left,
- * but connection needs to receive.
- * @param c the connection to update
- * @return true if connection states updated successfully,
- *         false if connection has been prepared for closing
- */
-static MHD_FN_PAR_NONNULL_ALL_ bool
-update_active_state (struct MHD_Connection *restrict c)
+MHD_INTERNAL MHD_FN_PAR_NONNULL_ALL_ void
+mhd_conn_event_loop_state_update (struct MHD_Connection *restrict c)
 {
   /* Do not update states of suspended connection */
   mhd_assert (! c->suspended);
@@ -188,11 +179,37 @@ update_active_state (struct MHD_Connection *restrict c)
   case MHD_CONNECTION_CLOSED:
     mhd_assert (0 && "Should be unreachable");
     c->event_loop_info = MHD_EVENT_LOOP_INFO_CLEANUP;
-    return false;           /* do nothing, not even reading */
+    break;
   default:
     mhd_assert (0 && "Impossible value");
     MHD_UNREACHABLE_;
   }
+}
+
+
+/**
+ * Update current processing state: need to receive, need to send.
+ * Mark stream as ready or not ready for processing.
+ * Grow the receive buffer if neccesary, close stream if no buffer space left,
+ * but connection needs to receive.
+ * @param c the connection to update
+ * @return true if connection states updated successfully,
+ *         false if connection has been prepared for closing
+ */
+static MHD_FN_PAR_NONNULL_ALL_ bool
+update_active_state (struct MHD_Connection *restrict c)
+{
+  /* Do not update states of suspended connection */
+  mhd_assert (! c->suspended);
+
+  if (0 != (c->sk.ready & mhd_SOCKET_NET_STATE_ERROR_READY))
+  {
+    mhd_assert (0 && "Should be handled earlier");
+    mhd_conn_start_closing_skt_err (c);
+    return false;
+  }
+
+  mhd_conn_event_loop_state_update (c);
 
   if (0 != (MHD_EVENT_LOOP_INFO_RECV & c->event_loop_info))
   {

+ 14 - 2
src/mhd2/stream_process_states.h

@@ -35,8 +35,20 @@
 struct MHD_Connection; /* forward declaration */
 
 /**
- * Process states and the data for the connection
- * For HTTP/1.1 connection is equal stream
+ * Update event loop state for the connection.
+ * Event loop state indicates current stage: sending or receiving the data.
+ * The underlying connection layer (plain TCP or TLS) must be already connected.
+ * @param c the connection to process
+ */
+MHD_INTERNAL void
+mhd_conn_event_loop_state_update (struct MHD_Connection *restrict c)
+MHD_FN_PAR_NONNULL_ALL_;
+
+/**
+ * Process states and the data for the connection.
+ * For HTTP/1.1: connection is equal stream.
+ * The function updates the states of the connection.
+ * The underlying connection layer (plain TCP or TLS) must be already connected.
  * @param c the connection to process
  * @return true if states and data has been successfully processed,
  *         false if connection needs to be closed