blob: 49204b89192c905e3da628f4b2e3c0928b79ad90 [file] [log] [blame]
Willy Tarreaudd815982007-10-16 12:25:14 +02001/*
2 * Protocol registration functions.
3 *
4 * Copyright 2000-2007 Willy Tarreau <w@1wt.eu>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 *
11 */
12
13#include <stdio.h>
14#include <string.h>
15
16#include <common/config.h>
17#include <common/mini-clist.h>
18#include <common/standard.h>
19
20#include <types/protocols.h>
21
22/* List head of all registered protocols */
23static struct list protocols = LIST_HEAD_INIT(protocols);
24
25/* Registers the protocol <proto> */
26void protocol_register(struct protocol *proto)
27{
28 LIST_ADDQ(&protocols, &proto->list);
29}
30
31/* Unregisters the protocol <proto>. Note that all listeners must have
32 * previously been unbound.
33 */
34void protocol_unregister(struct protocol *proto)
35{
36 LIST_DEL(&proto->list);
37 LIST_INIT(&proto->list);
38}
39
40/* binds all listeneres of all registered protocols. Returns a composition
41 * of ERR_NONE, ERR_RETRYABLE, ERR_FATAL.
42 */
43int protocol_bind_all(void)
44{
45 struct protocol *proto;
46 int err;
47
48 err = 0;
49 list_for_each_entry(proto, &protocols, list) {
50 if (proto->bind_all)
51 err |= proto->bind_all(proto);
52 }
53 return err;
54}
55
56/* unbinds all listeners of all registered protocols. They are also closed.
57 * This must be performed before calling exit() in order to get a chance to
58 * remove file-system based sockets and pipes.
59 * Returns a composition of ERR_NONE, ERR_RETRYABLE, ERR_FATAL.
60 */
61int protocol_unbind_all(void)
62{
63 struct protocol *proto;
64 int err;
65
66 err = 0;
67 list_for_each_entry(proto, &protocols, list) {
68 if (proto->unbind_all)
69 err |= proto->unbind_all(proto);
70 }
71 return err;
72}
73
74/* enables all listeners of all registered protocols. This is intended to be
75 * used after a fork() to enable reading on all file descriptors. Returns a
76 * composition of ERR_NONE, ERR_RETRYABLE, ERR_FATAL.
77 */
78int protocol_enable_all(void)
79{
80 struct protocol *proto;
81 int err;
82
83 err = 0;
84 list_for_each_entry(proto, &protocols, list) {
85 if (proto->enable_all)
86 err |= proto->enable_all(proto);
87 }
88 return err;
89}
90