blob: 6909cbe0dfd9ba57d070b14fc708ae94da896742 [file] [log] [blame]
Willy Tarreaubaaee002006-06-26 02:48:02 +02001/*
2 include/proto/queue.h
3 This file defines everything related to queues.
4
5 Copyright (C) 2000-2006 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_QUEUE_H
23#define _PROTO_QUEUE_H
24
Willy Tarreau2dd0d472006-06-29 17:53:05 +020025#include <common/memory.h>
26#include <common/mini-clist.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020027
28#include <types/proxy.h>
29#include <types/queue.h>
30#include <types/session.h>
31#include <types/server.h>
32#include <types/task.h>
33
34struct session *pendconn_get_next_sess(struct server *srv, struct proxy *px);
35struct pendconn *pendconn_add(struct session *sess);
36void pendconn_free(struct pendconn *p);
37int process_srv_queue(struct task *t);
38unsigned int srv_dynamic_maxconn(struct server *s);
39
40
41
42/* Returns the first pending connection for server <s>, which may be NULL if
43 * nothing is pending.
44 */
45static inline struct pendconn *pendconn_from_srv(struct server *s) {
46 if (!s->nbpend)
47 return NULL;
48
49 return LIST_ELEM(s->pendconns.n, struct pendconn *, list);
50}
51
52/* Returns the first pending connection for proxy <px>, which may be NULL if
53 * nothing is pending.
54 */
55static inline struct pendconn *pendconn_from_px(struct proxy *px) {
56 if (!px->nbpend)
57 return NULL;
58
59 return LIST_ELEM(px->pendconns.n, struct pendconn *, list);
60}
61
62/* returns 0 if nothing has to be done for server <s> regarding queued connections,
63 * and non-zero otherwise. Suited for and if/else usage.
64 */
65static inline int may_dequeue_tasks(struct server *s, struct proxy *p) {
66 return (s && (s->nbpend || p->nbpend) &&
67 (!s->maxconn || s->cur_sess < srv_dynamic_maxconn(s)) &&
68 s->queue_mgt);
69}
70
71#endif /* _PROTO_QUEUE_H */
72
73/*
74 * Local variables:
75 * c-indent-level: 8
76 * c-basic-offset: 8
77 * End:
78 */