blob: 05567ea689fec777d23b0b020d6dceb9cd4ad7fc [file] [log] [blame]
Willy Tarreaudd815982007-10-16 12:25:14 +02001/*
2 include/proto/protocols.h
3 This file declares generic protocol primitives.
4
5 Copyright (C) 2000-2007 Willy Tarreau - w@1wt.eu
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation, version 2.1
10 exclusively.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20*/
21
22#ifndef _PROTO_PROTOCOLS_H
23#define _PROTO_PROTOCOLS_H
24
25#include <types/protocols.h>
26
Willy Tarreaudabf2e22007-10-28 21:59:24 +010027/* This function adds the specified listener's file descriptor to the polling
28 * lists if it is in the LI_LISTEN state. The listener enters LI_READY or
29 * LI_FULL state depending on its number of connections.
30 */
31void enable_listener(struct listener *listener);
32
33/* This function removes the specified listener's file descriptor from the
34 * polling lists if it is in the LI_READY or in the LI_FULL state. The listener
35 * enters LI_LISTEN.
36 */
37void disable_listener(struct listener *listener);
38
Willy Tarreaube58c382011-07-24 18:28:10 +020039/* This function tries to temporarily disable a listener, depending on the OS
40 * capabilities. Linux unbinds the listen socket after a SHUT_RD, and ignores
41 * SHUT_WR. Solaris refuses either shutdown(). OpenBSD ignores SHUT_RD but
42 * closes upon SHUT_WR and refuses to rebind. So a common validation path
43 * involves SHUT_WR && listen && SHUT_RD. In case of success, the FD's polling
44 * is disabled. It normally returns non-zero, unless an error is reported.
45 */
46int pause_listener(struct listener *l);
47
48/* This function tries to resume a temporarily disabled listener.
49 * The resulting state will either be LI_READY or LI_FULL. 0 is returned
50 * in case of failure to resume (eg: dead socket).
51 */
52int resume_listener(struct listener *l);
53
Willy Tarreau62793712011-07-24 19:23:38 +020054/* Marks a ready listener as full so that the session code tries to re-enable
55 * it upon next close() using resume_listener().
56 */
57void listener_full(struct listener *l);
58
Willy Tarreaudabf2e22007-10-28 21:59:24 +010059/* This function adds all of the protocol's listener's file descriptors to the
60 * polling lists when they are in the LI_LISTEN state. It is intended to be
61 * used as a protocol's generic enable_all() primitive, for use after the
62 * fork(). It puts the listeners into LI_READY or LI_FULL states depending on
63 * their number of connections. It always returns ERR_NONE.
64 */
65int enable_all_listeners(struct protocol *proto);
66
67/* This function removes all of the protocol's listener's file descriptors from
68 * the polling lists when they are in the LI_READY or LI_FULL states. It is
69 * intended to be used as a protocol's generic disable_all() primitive. It puts
70 * the listeners into LI_LISTEN, and always returns ERR_NONE.
71 */
72int disable_all_listeners(struct protocol *proto);
73
Willy Tarreaue6ca1fc2011-07-24 22:03:52 +020074/* Marks a ready listener as limited so that we only try to re-enable it when
75 * resources are free again. It will be queued into the specified queue.
76 */
77void limit_listener(struct listener *l, struct list *list);
78
79/* Dequeues all of the listeners waiting for a resource in wait queue <queue>. */
80void dequeue_all_listeners(struct list *list);
81
Willy Tarreaub648d632007-10-28 22:13:50 +010082/* This function closes the listening socket for the specified listener,
83 * provided that it's already in a listening state. The listener enters the
84 * LI_ASSIGNED state. It always returns ERR_NONE. This function is intended
85 * to be used as a generic function for standard protocols.
86 */
87int unbind_listener(struct listener *listener);
88
Willy Tarreau3acf8c32007-10-28 22:35:41 +010089/* This function closes all listening sockets bound to the protocol <proto>,
90 * and the listeners end in LI_ASSIGNED state if they were higher. It does not
91 * detach them from the protocol. It always returns ERR_NONE.
92 */
93int unbind_all_listeners(struct protocol *proto);
94
Willy Tarreau1a64d162007-10-28 22:26:05 +010095/* Delete a listener from its protocol's list of listeners. The listener's
96 * state is automatically updated from LI_ASSIGNED to LI_INIT. The protocol's
97 * number of listeners is updated. Note that the listener must have previously
98 * been unbound. This is the generic function to use to remove a listener.
99 */
100void delete_listener(struct listener *listener);
101
Willy Tarreaudd815982007-10-16 12:25:14 +0200102/* Registers the protocol <proto> */
103void protocol_register(struct protocol *proto);
104
105/* Unregisters the protocol <proto>. Note that all listeners must have
106 * previously been unbound.
107 */
108void protocol_unregister(struct protocol *proto);
109
110/* binds all listeneres of all registered protocols. Returns a composition
111 * of ERR_NONE, ERR_RETRYABLE, ERR_FATAL.
112 */
Emeric Bruncf20bf12010-10-22 16:06:11 +0200113int protocol_bind_all(char *errmsg, int errlen);
Willy Tarreaudd815982007-10-16 12:25:14 +0200114
115/* unbinds all listeners of all registered protocols. They are also closed.
116 * This must be performed before calling exit() in order to get a chance to
117 * remove file-system based sockets and pipes.
118 * Returns a composition of ERR_NONE, ERR_RETRYABLE, ERR_FATAL.
119 */
120int protocol_unbind_all(void);
121
122/* enables all listeners of all registered protocols. This is intended to be
123 * used after a fork() to enable reading on all file descriptors. Returns a
124 * composition of ERR_NONE, ERR_RETRYABLE, ERR_FATAL.
125 */
126int protocol_enable_all(void);
127
128
129#endif /* _PROTO_PROTOCOLS_H */
130
131/*
132 * Local variables:
133 * c-indent-level: 8
134 * c-basic-offset: 8
135 * End:
136 */