MINOR: protocol: add protocol_stop_now() to instant-stop listeners
This will instantly stop all listeners except those which belong to
a proxy configured with a grace time. This means that UDP listeners,
and peers will also be stopped when called this way.
diff --git a/include/haproxy/protocol.h b/include/haproxy/protocol.h
index a752f98..81f4d5b 100644
--- a/include/haproxy/protocol.h
+++ b/include/haproxy/protocol.h
@@ -50,6 +50,14 @@
*/
int protocol_unbind_all(void);
+/* stops all listeners of all registered protocols, except when the belong to a
+ * proxy configured with a grace time. This will normally catch every single
+ * listener, all protocols included, and the grace ones will have to be handled
+ * by the proxy stopping loop. This is to be used during soft_stop() only. It
+ * does not return any error.
+ */
+void protocol_stop_now(void);
+
/* pauses all listeners of all registered protocols. This is typically
* used on SIG_TTOU to release all listening sockets for the time needed to
* try to bind a new process. The listeners enter LI_PAUSED. It returns
diff --git a/src/protocol.c b/src/protocol.c
index c0a0090..82deaad 100644
--- a/src/protocol.c
+++ b/src/protocol.c
@@ -151,6 +151,26 @@
return err;
}
+/* stops all listeners of all registered protocols, except when the belong to a
+ * proxy configured with a grace time. This will normally catch every single
+ * listener, all protocols included, and the grace ones will have to be handled
+ * by the proxy stopping loop. This is to be used during soft_stop() only. It
+ * does not return any error.
+ */
+void protocol_stop_now(void)
+{
+ struct protocol *proto;
+ struct listener *listener, *lback;
+
+ HA_SPIN_LOCK(PROTO_LOCK, &proto_lock);
+ list_for_each_entry(proto, &protocols, list) {
+ list_for_each_entry_safe(listener, lback, &proto->receivers, rx.proto_list)
+ if (!listener->bind_conf->frontend->grace)
+ stop_listener(listener, 0, 1, 0);
+ }
+ HA_SPIN_UNLOCK(PROTO_LOCK, &proto_lock);
+}
+
/* pauses all listeners of all registered protocols. This is typically
* used on SIG_TTOU to release all listening sockets for the time needed to
* try to bind a new process. The listeners enter LI_PAUSED. It returns