]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: stream-int: Add function to reset a SI endpoint
authorChristopher Faulet <cfaulet@haproxy.com>
Thu, 16 Dec 2021 13:41:29 +0000 (14:41 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Thu, 24 Feb 2022 10:00:02 +0000 (11:00 +0100)
si_reset_endpoint() function may be used to reset the SI's endpoint without
releasing the conn-stream if the endpoint is a connection. If the endpoint
is an appctx, it is released. This change is mandatory to merge the SI and
the CS and keep the backend conn-stream attached to the stream during
connection retries.

include/haproxy/stream_interface.h

index 55c622b961757ba5948eeef960a0ddf988046565..dec91f2b384a688f4206842d4d7526412ec7a11d 100644 (file)
@@ -166,6 +166,33 @@ static inline enum obj_type *si_detach_endpoint(struct stream_interface *si)
        return prev;
 }
 
+/* Reset the endpoint if it's a connection or an applet, For an applet, it is
+ * for now the same than si_release_endpoint(), the appctx is freed. But for a
+ * connection, the conn-stream is only detached.
+ */
+static inline void si_reset_endpoint(struct stream_interface *si)
+{
+       struct conn_stream *cs;
+       struct appctx *appctx;
+
+       if (!si->end)
+               return;
+
+       if ((appctx = objt_appctx(si->end))) {
+               if (appctx->applet->release && !si_state_in(si->state, SI_SB_DIS|SI_SB_CLO))
+                       appctx->applet->release(appctx);
+               appctx_free(appctx);
+               si_detach_endpoint(si);
+       }
+       else if ((cs = objt_cs(si->end))) {
+               if (cs_conn(cs) && si->wait_event.events != 0)
+                       cs->conn->mux->unsubscribe(cs, si->wait_event.events,
+                                                  &si->wait_event);
+               cs_detach(cs);
+               si->ops = &si_embedded_ops;
+       }
+}
+
 /* Release the endpoint if it's a connection or an applet, then nullify it.
  * Note: released connections are closed then freed.
  */