blob: 6899aee4882462252b44164c1f4462b3ef2ae5ca [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
Willy Tarreau7c669d72008-06-20 15:04:11 +02005 Copyright (C) 2000-2008 Willy Tarreau - w@1wt.eu
Willy Tarreaubaaee002006-06-26 02:48:02 +02006
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 Tarreaue3ba5f02006-06-29 18:54:54 +020025#include <common/config.h>
Willy Tarreau2dd0d472006-06-29 17:53:05 +020026#include <common/memory.h>
27#include <common/mini-clist.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020028
29#include <types/proxy.h>
30#include <types/queue.h>
31#include <types/session.h>
32#include <types/server.h>
33#include <types/task.h>
34
Willy Tarreaue4d7e552007-05-13 20:19:55 +020035extern struct pool_head *pool2_pendconn;
36
37int init_pendconn();
Willy Tarreaubaaee002006-06-26 02:48:02 +020038struct session *pendconn_get_next_sess(struct server *srv, struct proxy *px);
39struct pendconn *pendconn_add(struct session *sess);
40void pendconn_free(struct pendconn *p);
Willy Tarreau7c669d72008-06-20 15:04:11 +020041void process_srv_queue(struct server *s);
Willy Tarreaub17916e2006-10-15 15:17:57 +020042unsigned int srv_dynamic_maxconn(const struct server *s);
Willy Tarreaubaaee002006-06-26 02:48:02 +020043
44
45
46/* Returns the first pending connection for server <s>, which may be NULL if
47 * nothing is pending.
48 */
Willy Tarreaub17916e2006-10-15 15:17:57 +020049static inline struct pendconn *pendconn_from_srv(const struct server *s) {
Willy Tarreaubaaee002006-06-26 02:48:02 +020050 if (!s->nbpend)
51 return NULL;
52
53 return LIST_ELEM(s->pendconns.n, struct pendconn *, list);
54}
55
56/* Returns the first pending connection for proxy <px>, which may be NULL if
57 * nothing is pending.
58 */
Willy Tarreaub17916e2006-10-15 15:17:57 +020059static inline struct pendconn *pendconn_from_px(const struct proxy *px) {
Willy Tarreaubaaee002006-06-26 02:48:02 +020060 if (!px->nbpend)
61 return NULL;
62
63 return LIST_ELEM(px->pendconns.n, struct pendconn *, list);
64}
65
66/* returns 0 if nothing has to be done for server <s> regarding queued connections,
67 * and non-zero otherwise. Suited for and if/else usage.
68 */
Willy Tarreaub17916e2006-10-15 15:17:57 +020069static inline int may_dequeue_tasks(const struct server *s, const struct proxy *p) {
Willy Tarreaubaaee002006-06-26 02:48:02 +020070 return (s && (s->nbpend || p->nbpend) &&
Willy Tarreau7c669d72008-06-20 15:04:11 +020071 (!s->maxconn || s->cur_sess < srv_dynamic_maxconn(s)));
Willy Tarreaubaaee002006-06-26 02:48:02 +020072}
73
74#endif /* _PROTO_QUEUE_H */
75
76/*
77 * Local variables:
78 * c-indent-level: 8
79 * c-basic-offset: 8
80 * End:
81 */