]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MINOR] add a generic unbind_listener() primitive
authorWilly Tarreau <w@1wt.eu>
Sun, 28 Oct 2007 21:13:50 +0000 (22:13 +0100)
committerWilly Tarreau <w@1wt.eu>
Sun, 4 Nov 2007 21:42:49 +0000 (22:42 +0100)
Most protocols will be able to share a single unbind_listener()
primitive. Provided it in protocols.c.

include/proto/protocols.h
src/protocols.c

index 7b9e1dd9a9076ef2c37a4ea3382330098a9df592..353e4c441cfddece54778a82347b563f8dc9a891 100644 (file)
@@ -51,6 +51,13 @@ int enable_all_listeners(struct protocol *proto);
  */
 int disable_all_listeners(struct protocol *proto);
 
+/* This function closes the listening socket for the specified listener,
+ * provided that it's already in a listening state. The listener enters the
+ * LI_ASSIGNED state. It always returns ERR_NONE. This function is intended
+ * to be used as a generic function for standard protocols.
+ */
+int unbind_listener(struct listener *listener);
+
 /* Registers the protocol <proto> */
 void protocol_register(struct protocol *proto);
 
index 2412d0e4081f75d0ba7e9dd2b760d04797d1fa67..3e118b822c8809ae1d231e35e08c86574aed5488 100644 (file)
@@ -20,6 +20,8 @@
 
 #include <types/protocols.h>
 
+#include <proto/fd.h>
+
 /* List head of all registered protocols */
 static struct list protocols = LIST_HEAD_INIT(protocols);
 
@@ -81,6 +83,23 @@ int disable_all_listeners(struct protocol *proto)
        return ERR_NONE;
 }
 
+/* This function closes the listening socket for the specified listener,
+ * provided that it's already in a listening state. The listener enters the
+ * LI_ASSIGNED state. It always returns ERR_NONE. This function is intended
+ * to be used as a generic function for standard protocols.
+ */
+int unbind_listener(struct listener *listener)
+{
+       if (listener->state == LI_READY)
+               EV_FD_CLR(listener->fd, DIR_RD);
+
+       if (listener->state >= LI_LISTEN) {
+               fd_delete(listener->fd);
+               listener->state = LI_ASSIGNED;
+       }
+       return ERR_NONE;
+}
+
 /* Registers the protocol <proto> */
 void protocol_register(struct protocol *proto)
 {