REORG: split "protocols" files into protocol and listener
It was becoming confusing to have protocols and listeners in the same
files, split them.
diff --git a/src/backend.c b/src/backend.c
index c2ecda8..29d8145 100644
--- a/src/backend.c
+++ b/src/backend.c
@@ -38,7 +38,7 @@
#include <proto/lb_fwlc.h>
#include <proto/lb_fwrr.h>
#include <proto/lb_map.h>
-#include <proto/protocols.h>
+#include <proto/protocol.h>
#include <proto/proto_http.h>
#include <proto/proto_tcp.h>
#include <proto/queue.h>
diff --git a/src/cfgparse.c b/src/cfgparse.c
index c91e996..f78f896 100644
--- a/src/cfgparse.c
+++ b/src/cfgparse.c
@@ -51,9 +51,10 @@
#include <proto/lb_fwlc.h>
#include <proto/lb_fwrr.h>
#include <proto/lb_map.h>
+#include <proto/listener.h>
#include <proto/log.h>
#include <proto/port_range.h>
-#include <proto/protocols.h>
+#include <proto/protocol.h>
#include <proto/proto_tcp.h>
#include <proto/proto_uxst.h>
#include <proto/proto_http.h>
diff --git a/src/dumpstats.c b/src/dumpstats.c
index 2e775d9..e28f808 100644
--- a/src/dumpstats.c
+++ b/src/dumpstats.c
@@ -47,7 +47,7 @@
#include <proto/freq_ctr.h>
#include <proto/log.h>
#include <proto/pipe.h>
-#include <proto/protocols.h>
+#include <proto/listener.h>
#include <proto/proto_uxst.h>
#include <proto/proxy.h>
#include <proto/session.h>
diff --git a/src/haproxy.c b/src/haproxy.c
index 7fb0429..5edde4f 100644
--- a/src/haproxy.c
+++ b/src/haproxy.c
@@ -78,8 +78,9 @@
#include <proto/checks.h>
#include <proto/fd.h>
#include <proto/hdr_idx.h>
+#include <proto/listener.h>
#include <proto/log.h>
-#include <proto/protocols.h>
+#include <proto/protocol.h>
#include <proto/proto_http.h>
#include <proto/proxy.h>
#include <proto/queue.h>
diff --git a/src/protocols.c b/src/listener.c
similarity index 83%
rename from src/protocols.c
rename to src/listener.c
index 377c985..0e864b2 100644
--- a/src/protocols.c
+++ b/src/listener.c
@@ -1,7 +1,7 @@
/*
- * Protocol registration and listener management functions.
+ * Listener management functions.
*
- * Copyright 2000-2010 Willy Tarreau <w@1wt.eu>
+ * Copyright 2000-2012 Willy Tarreau <w@1wt.eu>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -21,6 +21,7 @@
#include <common/time.h>
#include <types/global.h>
+#include <types/protocol.h>
#include <proto/acl.h>
#include <proto/fd.h>
@@ -28,9 +29,6 @@
#include <proto/log.h>
#include <proto/task.h>
-/* List head of all registered protocols */
-static struct list protocols = LIST_HEAD_INIT(protocols);
-
/* This function adds the specified listener's file descriptor to the polling
* lists if it is in the LI_LISTEN state. The listener enters LI_READY or
* LI_FULL state depending on its number of connections.
@@ -411,107 +409,6 @@
return;
}
-/* Registers the protocol <proto> */
-void protocol_register(struct protocol *proto)
-{
- LIST_ADDQ(&protocols, &proto->list);
-}
-
-/* Unregisters the protocol <proto>. Note that all listeners must have
- * previously been unbound.
- */
-void protocol_unregister(struct protocol *proto)
-{
- LIST_DEL(&proto->list);
- LIST_INIT(&proto->list);
-}
-
-/* binds all listeners of all registered protocols. Returns a composition
- * of ERR_NONE, ERR_RETRYABLE, ERR_FATAL.
- */
-int protocol_bind_all(char *errmsg, int errlen)
-{
- struct protocol *proto;
- int err;
-
- err = 0;
- list_for_each_entry(proto, &protocols, list) {
- if (proto->bind_all) {
- err |= proto->bind_all(proto, errmsg, errlen);
- if ( err & ERR_ABORT )
- break;
- }
- }
- return err;
-}
-
-/* unbinds all listeners of all registered protocols. They are also closed.
- * This must be performed before calling exit() in order to get a chance to
- * remove file-system based sockets and pipes.
- * Returns a composition of ERR_NONE, ERR_RETRYABLE, ERR_FATAL, ERR_ABORT.
- */
-int protocol_unbind_all(void)
-{
- struct protocol *proto;
- int err;
-
- err = 0;
- list_for_each_entry(proto, &protocols, list) {
- if (proto->unbind_all) {
- err |= proto->unbind_all(proto);
- }
- }
- return err;
-}
-
-/* enables all listeners of all registered protocols. This is intended to be
- * used after a fork() to enable reading on all file descriptors. Returns a
- * composition of ERR_NONE, ERR_RETRYABLE, ERR_FATAL.
- */
-int protocol_enable_all(void)
-{
- struct protocol *proto;
- int err;
-
- err = 0;
- list_for_each_entry(proto, &protocols, list) {
- if (proto->enable_all) {
- err |= proto->enable_all(proto);
- }
- }
- return err;
-}
-
-/* disables all listeners of all registered protocols. This may be used before
- * a fork() to avoid duplicating poll lists. Returns a composition of ERR_NONE,
- * ERR_RETRYABLE, ERR_FATAL.
- */
-int protocol_disable_all(void)
-{
- struct protocol *proto;
- int err;
-
- err = 0;
- list_for_each_entry(proto, &protocols, list) {
- if (proto->disable_all) {
- err |= proto->disable_all(proto);
- }
- }
- return err;
-}
-
-/* Returns the protocol handler for socket family <family> or NULL if not found */
-struct protocol *protocol_by_family(int family)
-{
- struct protocol *proto;
-
- list_for_each_entry(proto, &protocols, list) {
- if (proto->sock_domain == family)
- return proto;
- }
- return NULL;
-}
-
/************************************************************************/
/* All supported ACL keywords must be declared here. */
/************************************************************************/
@@ -546,7 +443,7 @@
}};
__attribute__((constructor))
-static void __protocols_init(void)
+static void __listener_init(void)
{
acl_register_keywords(&acl_kws);
}
diff --git a/src/peers.c b/src/peers.c
index 6af5d9c..09e45f7 100644
--- a/src/peers.c
+++ b/src/peers.c
@@ -25,6 +25,7 @@
#include <common/time.h>
#include <types/global.h>
+#include <proto/listener.h>
#include <types/peers.h>
#include <proto/acl.h>
@@ -32,7 +33,6 @@
#include <proto/fd.h>
#include <proto/log.h>
#include <proto/hdr_idx.h>
-#include <proto/protocols.h>
#include <proto/proto_tcp.h>
#include <proto/proto_http.h>
#include <proto/proxy.h>
diff --git a/src/proto_tcp.c b/src/proto_tcp.c
index f819147..092db69 100644
--- a/src/proto_tcp.c
+++ b/src/proto_tcp.c
@@ -42,9 +42,10 @@
#include <proto/channel.h>
#include <proto/connection.h>
#include <proto/fd.h>
+#include <proto/listener.h>
#include <proto/log.h>
#include <proto/port_range.h>
-#include <proto/protocols.h>
+#include <proto/protocol.h>
#include <proto/proto_tcp.h>
#include <proto/proxy.h>
#include <proto/sample.h>
diff --git a/src/proto_uxst.c b/src/proto_uxst.c
index e4aaeed..ed05e02 100644
--- a/src/proto_uxst.c
+++ b/src/proto_uxst.c
@@ -36,8 +36,9 @@
#include <types/global.h>
#include <proto/fd.h>
+#include <proto/listener.h>
#include <proto/log.h>
-#include <proto/protocols.h>
+#include <proto/protocol.h>
#include <proto/proto_uxst.h>
#include <proto/task.h>
diff --git a/src/protocol.c b/src/protocol.c
new file mode 100644
index 0000000..84d23da
--- /dev/null
+++ b/src/protocol.c
@@ -0,0 +1,129 @@
+/*
+ * Protocol registration functions.
+ *
+ * Copyright 2000-2012 Willy Tarreau <w@1wt.eu>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ *
+ */
+
+#include <common/config.h>
+#include <common/errors.h>
+#include <common/mini-clist.h>
+#include <common/standard.h>
+
+#include <types/protocol.h>
+
+/* List head of all registered protocols */
+static struct list protocols = LIST_HEAD_INIT(protocols);
+
+/* Registers the protocol <proto> */
+void protocol_register(struct protocol *proto)
+{
+ LIST_ADDQ(&protocols, &proto->list);
+}
+
+/* Unregisters the protocol <proto>. Note that all listeners must have
+ * previously been unbound.
+ */
+void protocol_unregister(struct protocol *proto)
+{
+ LIST_DEL(&proto->list);
+ LIST_INIT(&proto->list);
+}
+
+/* binds all listeners of all registered protocols. Returns a composition
+ * of ERR_NONE, ERR_RETRYABLE, ERR_FATAL.
+ */
+int protocol_bind_all(char *errmsg, int errlen)
+{
+ struct protocol *proto;
+ int err;
+
+ err = 0;
+ list_for_each_entry(proto, &protocols, list) {
+ if (proto->bind_all) {
+ err |= proto->bind_all(proto, errmsg, errlen);
+ if ( err & ERR_ABORT )
+ break;
+ }
+ }
+ return err;
+}
+
+/* unbinds all listeners of all registered protocols. They are also closed.
+ * This must be performed before calling exit() in order to get a chance to
+ * remove file-system based sockets and pipes.
+ * Returns a composition of ERR_NONE, ERR_RETRYABLE, ERR_FATAL, ERR_ABORT.
+ */
+int protocol_unbind_all(void)
+{
+ struct protocol *proto;
+ int err;
+
+ err = 0;
+ list_for_each_entry(proto, &protocols, list) {
+ if (proto->unbind_all) {
+ err |= proto->unbind_all(proto);
+ }
+ }
+ return err;
+}
+
+/* enables all listeners of all registered protocols. This is intended to be
+ * used after a fork() to enable reading on all file descriptors. Returns a
+ * composition of ERR_NONE, ERR_RETRYABLE, ERR_FATAL.
+ */
+int protocol_enable_all(void)
+{
+ struct protocol *proto;
+ int err;
+
+ err = 0;
+ list_for_each_entry(proto, &protocols, list) {
+ if (proto->enable_all) {
+ err |= proto->enable_all(proto);
+ }
+ }
+ return err;
+}
+
+/* disables all listeners of all registered protocols. This may be used before
+ * a fork() to avoid duplicating poll lists. Returns a composition of ERR_NONE,
+ * ERR_RETRYABLE, ERR_FATAL.
+ */
+int protocol_disable_all(void)
+{
+ struct protocol *proto;
+ int err;
+
+ err = 0;
+ list_for_each_entry(proto, &protocols, list) {
+ if (proto->disable_all) {
+ err |= proto->disable_all(proto);
+ }
+ }
+ return err;
+}
+
+/* Returns the protocol handler for socket family <family> or NULL if not found */
+struct protocol *protocol_by_family(int family)
+{
+ struct protocol *proto;
+
+ list_for_each_entry(proto, &protocols, list) {
+ if (proto->sock_domain == family)
+ return proto;
+ }
+ return NULL;
+}
+
+/*
+ * Local variables:
+ * c-indent-level: 8
+ * c-basic-offset: 8
+ * End:
+ */
diff --git a/src/proxy.c b/src/proxy.c
index 07e863c..56d343e 100644
--- a/src/proxy.c
+++ b/src/proxy.c
@@ -31,8 +31,8 @@
#include <proto/backend.h>
#include <proto/fd.h>
#include <proto/hdr_idx.h>
+#include <proto/listener.h>
#include <proto/log.h>
-#include <proto/protocols.h>
#include <proto/proto_tcp.h>
#include <proto/proto_http.h>
#include <proto/proxy.h>
diff --git a/src/raw_sock.c b/src/raw_sock.c
index ea2fa66..37bea72 100644
--- a/src/raw_sock.c
+++ b/src/raw_sock.c
@@ -35,7 +35,6 @@
#include <proto/freq_ctr.h>
#include <proto/log.h>
#include <proto/pipe.h>
-#include <proto/protocols.h>
#include <proto/raw_sock.h>
#include <proto/stream_interface.h>
#include <proto/task.h>
diff --git a/src/session.c b/src/session.c
index 4503b41..6fb79e3 100644
--- a/src/session.c
+++ b/src/session.c
@@ -32,11 +32,11 @@
#include <proto/freq_ctr.h>
#include <proto/frontend.h>
#include <proto/hdr_idx.h>
+#include <proto/listener.h>
#include <proto/log.h>
#include <proto/raw_sock.h>
#include <proto/session.h>
#include <proto/pipe.h>
-#include <proto/protocols.h>
#include <proto/proto_http.h>
#include <proto/proto_tcp.h>
#include <proto/proxy.h>
diff --git a/src/ssl_sock.c b/src/ssl_sock.c
index 4198339..5f259f3 100644
--- a/src/ssl_sock.c
+++ b/src/ssl_sock.c
@@ -64,7 +64,6 @@
#include <proto/freq_ctr.h>
#include <proto/frontend.h>
#include <proto/log.h>
-#include <proto/protocols.h>
#include <proto/shctx.h>
#include <proto/ssl_sock.h>
#include <proto/task.h>