blob: cc25a6fe165166d4c12906add8b642e705683a39 [file] [log] [blame]
Willy Tarreaubaaee002006-06-26 02:48:02 +02001/*
2 include/proto/backend.h
3 Functions prototypes for the backend.
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_BACKEND_H
23#define _PROTO_BACKEND_H
24
Willy Tarreaue3ba5f02006-06-29 18:54:54 +020025#include <common/config.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020026
27#include <types/backend.h>
28#include <types/session.h>
29
30#include <proto/queue.h>
31
32int assign_server(struct session *s);
33int assign_server_address(struct session *s);
34int assign_server_and_queue(struct session *s);
35int connect_server(struct session *s);
36int srv_count_retry_down(struct session *t, int conn_err);
37int srv_retryable_connect(struct session *t);
38int srv_redispatch_connect(struct session *t);
39
40void recount_servers(struct proxy *px);
41void recalc_server_map(struct proxy *px);
42
43
44/*
45 * This function tries to find a running server with free connection slots for
46 * the proxy <px> following the round-robin method.
47 * If any server is found, it will be returned and px->srv_rr_idx will be updated
48 * to point to the next server. If no valid server is found, NULL is returned.
49 */
50static inline struct server *get_server_rr_with_conns(struct proxy *px)
51{
52 int newidx;
53 struct server *srv;
54
55 if (px->srv_map_sz == 0)
56 return NULL;
57
58 if (px->srv_rr_idx < 0 || px->srv_rr_idx >= px->srv_map_sz)
59 px->srv_rr_idx = 0;
60 newidx = px->srv_rr_idx;
61
62 do {
63 srv = px->srv_map[newidx++];
64 if (!srv->maxconn || srv->cur_sess < srv_dynamic_maxconn(srv)) {
65 px->srv_rr_idx = newidx;
66 return srv;
67 }
68 if (newidx == px->srv_map_sz)
69 newidx = 0;
70 } while (newidx != px->srv_rr_idx);
71
72 return NULL;
73}
74
75
76/*
77 * This function tries to find a running server for the proxy <px> following
78 * the round-robin method.
79 * If any server is found, it will be returned and px->srv_rr_idx will be updated
80 * to point to the next server. If no valid server is found, NULL is returned.
81 */
82static inline struct server *get_server_rr(struct proxy *px)
83{
84 if (px->srv_map_sz == 0)
85 return NULL;
86
87 if (px->srv_rr_idx < 0 || px->srv_rr_idx >= px->srv_map_sz)
88 px->srv_rr_idx = 0;
89 return px->srv_map[px->srv_rr_idx++];
90}
91
92
93/*
94 * This function tries to find a running server for the proxy <px> following
95 * the source hash method. Depending on the number of active/backup servers,
96 * it will either look for active servers, or for backup servers.
97 * If any server is found, it will be returned. If no valid server is found,
98 * NULL is returned.
99 */
100static inline struct server *get_server_sh(struct proxy *px, char *addr, int len)
101{
102 unsigned int h, l;
103
104 if (px->srv_map_sz == 0)
105 return NULL;
106
107 l = h = 0;
108 if (px->srv_act > 1 || (px->srv_act == 0 && px->srv_bck > 1)) {
109 while ((l + sizeof (int)) <= len) {
110 h ^= ntohl(*(unsigned int *)(&addr[l]));
111 l += sizeof (int);
112 }
113 h %= px->srv_map_sz;
114 }
115 return px->srv_map[h];
116}
117
118
119#endif /* _PROTO_BACKEND_H */
120
121/*
122 * Local variables:
123 * c-indent-level: 8
124 * c-basic-offset: 8
125 * End:
126 */