Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1 | /* |
Willy Tarreau | f8e8b76 | 2012-01-20 15:57:05 +0100 | [diff] [blame] | 2 | * include/proto/queue.h |
| 3 | * This file defines everything related to queues. |
| 4 | * |
| 5 | * Copyright (C) 2000-2012 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 | */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 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 | |
Willy Tarreau | f8e8b76 | 2012-01-20 15:57:05 +0100 | [diff] [blame] | 35 | #include <proto/backend.h> |
| 36 | |
Willy Tarreau | e4d7e55 | 2007-05-13 20:19:55 +0200 | [diff] [blame] | 37 | extern struct pool_head *pool2_pendconn; |
| 38 | |
| 39 | int init_pendconn(); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 40 | struct session *pendconn_get_next_sess(struct server *srv, struct proxy *px); |
| 41 | struct pendconn *pendconn_add(struct session *sess); |
| 42 | void pendconn_free(struct pendconn *p); |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 43 | void process_srv_queue(struct server *s); |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 44 | unsigned int srv_dynamic_maxconn(const struct server *s); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 45 | |
| 46 | |
| 47 | |
| 48 | /* Returns the first pending connection for server <s>, which may be NULL if |
| 49 | * nothing is pending. |
| 50 | */ |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 51 | static inline struct pendconn *pendconn_from_srv(const struct server *s) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 52 | if (!s->nbpend) |
| 53 | return NULL; |
| 54 | |
| 55 | return LIST_ELEM(s->pendconns.n, struct pendconn *, list); |
| 56 | } |
| 57 | |
| 58 | /* Returns the first pending connection for proxy <px>, which may be NULL if |
| 59 | * nothing is pending. |
| 60 | */ |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 61 | static inline struct pendconn *pendconn_from_px(const struct proxy *px) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 62 | if (!px->nbpend) |
| 63 | return NULL; |
| 64 | |
| 65 | return LIST_ELEM(px->pendconns.n, struct pendconn *, list); |
| 66 | } |
| 67 | |
| 68 | /* returns 0 if nothing has to be done for server <s> regarding queued connections, |
Willy Tarreau | 922a806 | 2008-12-04 09:33:58 +0100 | [diff] [blame] | 69 | * and non-zero otherwise. If the server is down, we only check its own queue. Suited |
| 70 | * for and if/else usage. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 71 | */ |
Willy Tarreau | b17916e | 2006-10-15 15:17:57 +0200 | [diff] [blame] | 72 | static inline int may_dequeue_tasks(const struct server *s, const struct proxy *p) { |
Willy Tarreau | f8e8b76 | 2012-01-20 15:57:05 +0100 | [diff] [blame] | 73 | return (s && (s->nbpend || (p->nbpend && srv_is_usable(s->state, s->eweight))) && |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 74 | (!s->maxconn || s->cur_sess < srv_dynamic_maxconn(s))); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | #endif /* _PROTO_QUEUE_H */ |
| 78 | |
| 79 | /* |
| 80 | * Local variables: |
| 81 | * c-indent-level: 8 |
| 82 | * c-basic-offset: 8 |
| 83 | * End: |
| 84 | */ |