Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1 | /* |
| 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 Tarreau | e3ba5f0 | 2006-06-29 18:54:54 +0200 | [diff] [blame] | 25 | #include <common/config.h> |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 26 | #include <common/memory.h> |
| 27 | #include <common/mini-clist.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 28 | |
| 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 | |
| 35 | struct session *pendconn_get_next_sess(struct server *srv, struct proxy *px); |
| 36 | struct pendconn *pendconn_add(struct session *sess); |
| 37 | void pendconn_free(struct pendconn *p); |
| 38 | int process_srv_queue(struct task *t); |
| 39 | unsigned int srv_dynamic_maxconn(struct server *s); |
| 40 | |
| 41 | |
| 42 | |
| 43 | /* Returns the first pending connection for server <s>, which may be NULL if |
| 44 | * nothing is pending. |
| 45 | */ |
| 46 | static inline struct pendconn *pendconn_from_srv(struct server *s) { |
| 47 | if (!s->nbpend) |
| 48 | return NULL; |
| 49 | |
| 50 | return LIST_ELEM(s->pendconns.n, struct pendconn *, list); |
| 51 | } |
| 52 | |
| 53 | /* Returns the first pending connection for proxy <px>, which may be NULL if |
| 54 | * nothing is pending. |
| 55 | */ |
| 56 | static inline struct pendconn *pendconn_from_px(struct proxy *px) { |
| 57 | if (!px->nbpend) |
| 58 | return NULL; |
| 59 | |
| 60 | return LIST_ELEM(px->pendconns.n, struct pendconn *, list); |
| 61 | } |
| 62 | |
| 63 | /* returns 0 if nothing has to be done for server <s> regarding queued connections, |
| 64 | * and non-zero otherwise. Suited for and if/else usage. |
| 65 | */ |
| 66 | static inline int may_dequeue_tasks(struct server *s, struct proxy *p) { |
| 67 | return (s && (s->nbpend || p->nbpend) && |
| 68 | (!s->maxconn || s->cur_sess < srv_dynamic_maxconn(s)) && |
| 69 | s->queue_mgt); |
| 70 | } |
| 71 | |
| 72 | #endif /* _PROTO_QUEUE_H */ |
| 73 | |
| 74 | /* |
| 75 | * Local variables: |
| 76 | * c-indent-level: 8 |
| 77 | * c-basic-offset: 8 |
| 78 | * End: |
| 79 | */ |