blob: 1a3193017c4706c229739236b99924a947641496 [file] [log] [blame]
Willy TARREAU3dc06442006-06-15 21:48:13 +02001/*
Willy Tarreau87b09662015-04-03 00:22:06 +02002 * include/proto/stream.h
3 * This file defines everything related to streams.
Willy Tarreau81f9aa32010-06-01 17:45:26 +02004 *
5 * Copyright (C) 2000-2010 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 TARREAU3dc06442006-06-15 21:48:13 +020021
Willy Tarreau87b09662015-04-03 00:22:06 +020022#ifndef _PROTO_STREAM_H
23#define _PROTO_STREAM_H
Willy Tarreaubaaee002006-06-26 02:48:02 +020024
Willy Tarreaue3ba5f02006-06-29 18:54:54 +020025#include <common/config.h>
Willy Tarreauc6ca1a02007-05-13 19:43:47 +020026#include <common/memory.h>
Willy Tarreau87b09662015-04-03 00:22:06 +020027#include <types/stream.h>
Willy Tarreaua24adf02014-11-27 01:11:56 +010028#include <proto/fd.h>
Willy Tarreau91c43d72010-06-20 11:19:22 +020029#include <proto/freq_ctr.h>
Willy Tarreau9ba2dcc2010-06-14 21:04:55 +020030#include <proto/stick_table.h>
Willy Tarreaua24adf02014-11-27 01:11:56 +010031#include <proto/task.h>
Willy TARREAU3dc06442006-06-15 21:48:13 +020032
Willy Tarreau87b09662015-04-03 00:22:06 +020033extern struct pool_head *pool2_stream;
34extern struct list streams;
Willy Tarreauc6ca1a02007-05-13 19:43:47 +020035
Willy Tarreaubc174aa2012-11-19 16:10:32 +010036extern struct data_cb sess_conn_cb;
37
Willy Tarreau87787ac2017-08-28 16:22:54 +020038struct stream *stream_new(struct session *sess, enum obj_type *origin);
Olivier Houchard9aaf7782017-09-13 18:30:23 +020039int stream_create_from_cs(struct conn_stream *cs);
Willy Tarreaubaaee002006-06-26 02:48:02 +020040
Willy Tarreauc6ca1a02007-05-13 19:43:47 +020041/* perform minimal intializations, report 0 in case of error, 1 if OK. */
Willy Tarreau87b09662015-04-03 00:22:06 +020042int init_stream();
Willy Tarreaubaaee002006-06-26 02:48:02 +020043
Willy Tarreaue7dff022015-04-03 01:14:29 +020044/* kill a stream and set the termination flags to <why> (one of SF_ERR_*) */
Willy Tarreau87b09662015-04-03 00:22:06 +020045void stream_shutdown(struct stream *stream, int why);
Simon Hormandec5be42011-06-08 09:19:07 +090046
Willy Tarreau87b09662015-04-03 00:22:06 +020047void stream_process_counters(struct stream *s);
48void sess_change_server(struct stream *sess, struct server *newsrv);
49struct task *process_stream(struct task *t);
50void default_srv_error(struct stream *s, struct stream_interface *si);
Willy Tarreau9ba2dcc2010-06-14 21:04:55 +020051int parse_track_counters(char **args, int *arg,
52 int section_type, struct proxy *curpx,
53 struct track_ctr_prm *prm,
Willy Tarreau0a3dd742012-05-08 19:47:01 +020054 struct proxy *defpx, char **err);
Willy Tarreau9ba2dcc2010-06-14 21:04:55 +020055
Willy Tarreau87b09662015-04-03 00:22:06 +020056/* Update the stream's backend and server time stats */
57void stream_update_time_stats(struct stream *s);
Willy Tarreau87b09662015-04-03 00:22:06 +020058void stream_release_buffers(struct stream *s);
Willy Tarreau4bfc5802014-06-17 12:19:18 +020059
Willy Tarreaub1ec8c42015-04-03 13:53:24 +020060/* returns the session this stream belongs to */
61static inline struct session *strm_sess(const struct stream *strm)
62{
63 return strm->sess;
64}
65
Willy Tarreaud0d8da92015-04-04 02:10:38 +020066/* returns the frontend this stream was initiated from */
67static inline struct proxy *strm_fe(const struct stream *strm)
68{
69 return strm->sess->fe;
70}
71
72/* returns the listener this stream was initiated from */
73static inline struct listener *strm_li(const struct stream *strm)
74{
75 return strm->sess->listener;
76}
77
78/* returns a pointer to the origin of the session which created this stream */
79static inline enum obj_type *strm_orig(const struct stream *strm)
80{
81 return strm->sess->origin;
82}
83
Willy Tarreau87b09662015-04-03 00:22:06 +020084/* Remove the refcount from the stream to the tracked counters, and clear the
Willy Tarreau9ba2dcc2010-06-14 21:04:55 +020085 * pointer to ensure this is only performed once. The caller is responsible for
Willy Tarreaua68f7622015-09-21 17:48:24 +020086 * ensuring that the pointer is valid first. We must be extremely careful not
87 * to touch the entries we inherited from the session.
Willy Tarreau9ba2dcc2010-06-14 21:04:55 +020088 */
Willy Tarreau87b09662015-04-03 00:22:06 +020089static inline void stream_store_counters(struct stream *s)
Willy Tarreau9ba2dcc2010-06-14 21:04:55 +020090{
Willy Tarreauf059a0f2010-08-03 16:29:52 +020091 void *ptr;
Willy Tarreau20d46a52012-12-09 15:55:40 +010092 int i;
Emeric Brun819fc6f2017-06-13 19:37:32 +020093 struct stksess *ts;
Willy Tarreauf059a0f2010-08-03 16:29:52 +020094
Willy Tarreaub4c84932013-07-23 19:15:30 +020095 for (i = 0; i < MAX_SESS_STKCTR; i++) {
Emeric Brun819fc6f2017-06-13 19:37:32 +020096 ts = stkctr_entry(&s->stkctr[i]);
97 if (!ts)
Willy Tarreau20d46a52012-12-09 15:55:40 +010098 continue;
Willy Tarreaua68f7622015-09-21 17:48:24 +020099
100 if (stkctr_entry(&s->sess->stkctr[i]))
101 continue;
102
Emeric Brun819fc6f2017-06-13 19:37:32 +0200103 ptr = stktable_data_ptr(s->stkctr[i].table, ts, STKTABLE_DT_CONN_CUR);
104 if (ptr) {
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100105 HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &ts->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200106
Willy Tarreauf059a0f2010-08-03 16:29:52 +0200107 stktable_data_cast(ptr, conn_cur)--;
Emeric Brun819fc6f2017-06-13 19:37:32 +0200108
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100109 HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200110 }
Willy Tarreaucc08d2c2014-01-28 23:18:23 +0100111 stkctr_set_entry(&s->stkctr[i], NULL);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200112 stksess_kill_if_expired(s->stkctr[i].table, ts, 1);
Willy Tarreau38285c12010-06-18 16:35:43 +0200113 }
Willy Tarreau9ba2dcc2010-06-14 21:04:55 +0200114}
115
Willy Tarreau87b09662015-04-03 00:22:06 +0200116/* Remove the refcount from the stream counters tracked at the content level if
Willy Tarreauf059a0f2010-08-03 16:29:52 +0200117 * any, and clear the pointer to ensure this is only performed once. The caller
Willy Tarreaua68f7622015-09-21 17:48:24 +0200118 * is responsible for ensuring that the pointer is valid first. We must be
119 * extremely careful not to touch the entries we inherited from the session.
Willy Tarreau9ba2dcc2010-06-14 21:04:55 +0200120 */
Willy Tarreau87b09662015-04-03 00:22:06 +0200121static inline void stream_stop_content_counters(struct stream *s)
Willy Tarreau9ba2dcc2010-06-14 21:04:55 +0200122{
Emeric Brun819fc6f2017-06-13 19:37:32 +0200123 struct stksess *ts;
Willy Tarreauf059a0f2010-08-03 16:29:52 +0200124 void *ptr;
Willy Tarreau20d46a52012-12-09 15:55:40 +0100125 int i;
Willy Tarreaue3487932010-06-18 21:03:20 +0200126
Willy Tarreaub4c84932013-07-23 19:15:30 +0200127 for (i = 0; i < MAX_SESS_STKCTR; i++) {
Emeric Brun819fc6f2017-06-13 19:37:32 +0200128 ts = stkctr_entry(&s->stkctr[i]);
129 if (!ts)
Willy Tarreau20d46a52012-12-09 15:55:40 +0100130 continue;
Willy Tarreau0a4838c2010-08-06 20:11:05 +0200131
Willy Tarreaua68f7622015-09-21 17:48:24 +0200132 if (stkctr_entry(&s->sess->stkctr[i]))
133 continue;
134
Willy Tarreaucc08d2c2014-01-28 23:18:23 +0100135 if (!(stkctr_flags(&s->stkctr[i]) & STKCTR_TRACK_CONTENT))
Willy Tarreau20d46a52012-12-09 15:55:40 +0100136 continue;
137
Emeric Brun819fc6f2017-06-13 19:37:32 +0200138 ptr = stktable_data_ptr(s->stkctr[i].table, ts, STKTABLE_DT_CONN_CUR);
139 if (ptr) {
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100140 HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &ts->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200141
Willy Tarreau0a4838c2010-08-06 20:11:05 +0200142 stktable_data_cast(ptr, conn_cur)--;
Emeric Brun819fc6f2017-06-13 19:37:32 +0200143
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100144 HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200145 }
Willy Tarreaucc08d2c2014-01-28 23:18:23 +0100146 stkctr_set_entry(&s->stkctr[i], NULL);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200147 stksess_kill_if_expired(s->stkctr[i].table, ts, 1);
Willy Tarreau0a4838c2010-08-06 20:11:05 +0200148 }
Willy Tarreauf059a0f2010-08-03 16:29:52 +0200149}
Willy Tarreaue3487932010-06-18 21:03:20 +0200150
Willy Tarreauf059a0f2010-08-03 16:29:52 +0200151/* Increase total and concurrent connection count for stick entry <ts> of table
152 * <t>. The caller is responsible for ensuring that <t> and <ts> are valid
153 * pointers, and for calling this only once per connection.
154 */
Willy Tarreau87b09662015-04-03 00:22:06 +0200155static inline void stream_start_counters(struct stktable *t, struct stksess *ts)
Willy Tarreauf059a0f2010-08-03 16:29:52 +0200156{
157 void *ptr;
Willy Tarreau91c43d72010-06-20 11:19:22 +0200158
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100159 HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &ts->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200160
Willy Tarreauf059a0f2010-08-03 16:29:52 +0200161 ptr = stktable_data_ptr(t, ts, STKTABLE_DT_CONN_CUR);
162 if (ptr)
163 stktable_data_cast(ptr, conn_cur)++;
164
165 ptr = stktable_data_ptr(t, ts, STKTABLE_DT_CONN_CNT);
166 if (ptr)
167 stktable_data_cast(ptr, conn_cnt)++;
168
169 ptr = stktable_data_ptr(t, ts, STKTABLE_DT_CONN_RATE);
170 if (ptr)
171 update_freq_ctr_period(&stktable_data_cast(ptr, conn_rate),
172 t->data_arg[STKTABLE_DT_CONN_RATE].u, 1);
173 if (tick_isset(t->expire))
174 ts->expire = tick_add(now_ms, MS_TO_TICKS(t->expire));
Emeric Brun819fc6f2017-06-13 19:37:32 +0200175
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100176 HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock);
Willy Tarreauf059a0f2010-08-03 16:29:52 +0200177}
178
Willy Tarreau87b09662015-04-03 00:22:06 +0200179/* Enable tracking of stream counters as <stkctr> on stksess <ts>. The caller is
Willy Tarreauf059a0f2010-08-03 16:29:52 +0200180 * responsible for ensuring that <t> and <ts> are valid pointers. Some controls
181 * are performed to ensure the state can still change.
182 */
Willy Tarreau87b09662015-04-03 00:22:06 +0200183static inline void stream_track_stkctr(struct stkctr *ctr, struct stktable *t, struct stksess *ts)
Willy Tarreauf059a0f2010-08-03 16:29:52 +0200184{
Emeric Brun819fc6f2017-06-13 19:37:32 +0200185 /* Why this test ???? */
Willy Tarreaucc08d2c2014-01-28 23:18:23 +0100186 if (stkctr_entry(ctr))
Willy Tarreauf059a0f2010-08-03 16:29:52 +0200187 return;
188
Willy Tarreau20d46a52012-12-09 15:55:40 +0100189 ctr->table = t;
Willy Tarreaucc08d2c2014-01-28 23:18:23 +0100190 stkctr_set_entry(ctr, ts);
Willy Tarreau87b09662015-04-03 00:22:06 +0200191 stream_start_counters(t, ts);
Willy Tarreauf059a0f2010-08-03 16:29:52 +0200192}
193
Willy Tarreauda7ff642010-06-23 11:44:09 +0200194/* Increase the number of cumulated HTTP requests in the tracked counters */
Willy Tarreau87b09662015-04-03 00:22:06 +0200195static void inline stream_inc_http_req_ctr(struct stream *s)
Willy Tarreauda7ff642010-06-23 11:44:09 +0200196{
Emeric Brun819fc6f2017-06-13 19:37:32 +0200197 struct stksess *ts;
Willy Tarreauf059a0f2010-08-03 16:29:52 +0200198 void *ptr;
Willy Tarreau20d46a52012-12-09 15:55:40 +0100199 int i;
Willy Tarreauf059a0f2010-08-03 16:29:52 +0200200
Willy Tarreaub4c84932013-07-23 19:15:30 +0200201 for (i = 0; i < MAX_SESS_STKCTR; i++) {
Willy Tarreau8b7f8682015-04-04 16:29:12 +0200202 struct stkctr *stkctr = &s->stkctr[i];
Willy Tarreauf059a0f2010-08-03 16:29:52 +0200203
Emeric Brun819fc6f2017-06-13 19:37:32 +0200204 ts = stkctr_entry(stkctr);
205 if (!ts) {
Willy Tarreau8b7f8682015-04-04 16:29:12 +0200206 stkctr = &s->sess->stkctr[i];
Emeric Brun819fc6f2017-06-13 19:37:32 +0200207 ts = stkctr_entry(stkctr);
208 if (!ts)
Willy Tarreau8b7f8682015-04-04 16:29:12 +0200209 continue;
210 }
211
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100212 HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &ts->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200213
214 ptr = stktable_data_ptr(stkctr->table, ts, STKTABLE_DT_HTTP_REQ_CNT);
Willy Tarreauda7ff642010-06-23 11:44:09 +0200215 if (ptr)
216 stktable_data_cast(ptr, http_req_cnt)++;
217
Emeric Brun819fc6f2017-06-13 19:37:32 +0200218 ptr = stktable_data_ptr(stkctr->table, ts, STKTABLE_DT_HTTP_REQ_RATE);
Willy Tarreauda7ff642010-06-23 11:44:09 +0200219 if (ptr)
220 update_freq_ctr_period(&stktable_data_cast(ptr, http_req_rate),
Willy Tarreau8b7f8682015-04-04 16:29:12 +0200221 stkctr->table->data_arg[STKTABLE_DT_HTTP_REQ_RATE].u, 1);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200222
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100223 HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock);
Willy Tarreauda7ff642010-06-23 11:44:09 +0200224 }
225}
226
Willy Tarreau8b7f8682015-04-04 16:29:12 +0200227/* Increase the number of cumulated HTTP requests in the backend's tracked
228 * counters. We don't look up the session since it cannot happen in the bakcend.
229 */
Willy Tarreau87b09662015-04-03 00:22:06 +0200230static void inline stream_inc_be_http_req_ctr(struct stream *s)
Willy Tarreau5d5b5d82012-12-09 12:00:04 +0100231{
Emeric Brun819fc6f2017-06-13 19:37:32 +0200232 struct stksess *ts;
Willy Tarreau5d5b5d82012-12-09 12:00:04 +0100233 void *ptr;
Willy Tarreau20d46a52012-12-09 15:55:40 +0100234 int i;
Willy Tarreau5d5b5d82012-12-09 12:00:04 +0100235
Willy Tarreaub4c84932013-07-23 19:15:30 +0200236 for (i = 0; i < MAX_SESS_STKCTR; i++) {
Willy Tarreau8b7f8682015-04-04 16:29:12 +0200237 struct stkctr *stkctr = &s->stkctr[i];
238
Emeric Brun819fc6f2017-06-13 19:37:32 +0200239 ts = stkctr_entry(stkctr);
240 if (!ts)
Willy Tarreau20d46a52012-12-09 15:55:40 +0100241 continue;
Willy Tarreau5d5b5d82012-12-09 12:00:04 +0100242
Willy Tarreaucc08d2c2014-01-28 23:18:23 +0100243 if (!(stkctr_flags(&s->stkctr[i]) & STKCTR_TRACK_BACKEND))
Willy Tarreau20d46a52012-12-09 15:55:40 +0100244 continue;
245
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100246 HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &ts->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200247
248 ptr = stktable_data_ptr(stkctr->table, ts, STKTABLE_DT_HTTP_REQ_CNT);
Willy Tarreau5d5b5d82012-12-09 12:00:04 +0100249 if (ptr)
250 stktable_data_cast(ptr, http_req_cnt)++;
251
Emeric Brun819fc6f2017-06-13 19:37:32 +0200252 ptr = stktable_data_ptr(stkctr->table, ts, STKTABLE_DT_HTTP_REQ_RATE);
Willy Tarreau5d5b5d82012-12-09 12:00:04 +0100253 if (ptr)
254 update_freq_ctr_period(&stktable_data_cast(ptr, http_req_rate),
Willy Tarreau8b7f8682015-04-04 16:29:12 +0200255 stkctr->table->data_arg[STKTABLE_DT_HTTP_REQ_RATE].u, 1);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200256
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100257 HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock);
Willy Tarreau5d5b5d82012-12-09 12:00:04 +0100258 }
259}
260
Willy Tarreauda7ff642010-06-23 11:44:09 +0200261/* Increase the number of cumulated failed HTTP requests in the tracked
262 * counters. Only 4xx requests should be counted here so that we can
263 * distinguish between errors caused by client behaviour and other ones.
264 * Note that even 404 are interesting because they're generally caused by
265 * vulnerability scans.
266 */
Willy Tarreau87b09662015-04-03 00:22:06 +0200267static void inline stream_inc_http_err_ctr(struct stream *s)
Willy Tarreauda7ff642010-06-23 11:44:09 +0200268{
Emeric Brun819fc6f2017-06-13 19:37:32 +0200269 struct stksess *ts;
Willy Tarreauf059a0f2010-08-03 16:29:52 +0200270 void *ptr;
Willy Tarreau20d46a52012-12-09 15:55:40 +0100271 int i;
Willy Tarreauf059a0f2010-08-03 16:29:52 +0200272
Willy Tarreaub4c84932013-07-23 19:15:30 +0200273 for (i = 0; i < MAX_SESS_STKCTR; i++) {
Willy Tarreau8b7f8682015-04-04 16:29:12 +0200274 struct stkctr *stkctr = &s->stkctr[i];
Willy Tarreauf059a0f2010-08-03 16:29:52 +0200275
Emeric Brun819fc6f2017-06-13 19:37:32 +0200276 ts = stkctr_entry(stkctr);
277 if (!ts) {
Willy Tarreau8b7f8682015-04-04 16:29:12 +0200278 stkctr = &s->sess->stkctr[i];
Emeric Brun819fc6f2017-06-13 19:37:32 +0200279 ts = stkctr_entry(stkctr);
280 if (!ts)
Willy Tarreau8b7f8682015-04-04 16:29:12 +0200281 continue;
282 }
283
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100284 HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &ts->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200285
286 ptr = stktable_data_ptr(stkctr->table, ts, STKTABLE_DT_HTTP_ERR_CNT);
Willy Tarreauda7ff642010-06-23 11:44:09 +0200287 if (ptr)
288 stktable_data_cast(ptr, http_err_cnt)++;
289
Emeric Brun819fc6f2017-06-13 19:37:32 +0200290 ptr = stktable_data_ptr(stkctr->table, ts, STKTABLE_DT_HTTP_ERR_RATE);
Willy Tarreauda7ff642010-06-23 11:44:09 +0200291 if (ptr)
292 update_freq_ctr_period(&stktable_data_cast(ptr, http_err_rate),
Willy Tarreau8b7f8682015-04-04 16:29:12 +0200293 stkctr->table->data_arg[STKTABLE_DT_HTTP_ERR_RATE].u, 1);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200294
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100295 HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock);
Willy Tarreauda7ff642010-06-23 11:44:09 +0200296 }
297}
298
Willy Tarreau87b09662015-04-03 00:22:06 +0200299static void inline stream_add_srv_conn(struct stream *sess, struct server *srv)
Simon Hormanaf514952011-06-21 14:34:57 +0900300{
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100301 HA_SPIN_LOCK(SERVER_LOCK, &srv->lock);
Simon Hormanaf514952011-06-21 14:34:57 +0900302 sess->srv_conn = srv;
303 LIST_ADD(&srv->actconns, &sess->by_srv);
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100304 HA_SPIN_UNLOCK(SERVER_LOCK, &srv->lock);
Simon Hormanaf514952011-06-21 14:34:57 +0900305}
306
Willy Tarreau87b09662015-04-03 00:22:06 +0200307static void inline stream_del_srv_conn(struct stream *sess)
Simon Hormanaf514952011-06-21 14:34:57 +0900308{
Christopher Faulet29f77e82017-06-08 14:04:45 +0200309 struct server *srv = sess->srv_conn;
310
311 if (!srv)
Simon Hormanaf514952011-06-21 14:34:57 +0900312 return;
313
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100314 HA_SPIN_LOCK(SERVER_LOCK, &srv->lock);
Simon Hormanaf514952011-06-21 14:34:57 +0900315 sess->srv_conn = NULL;
316 LIST_DEL(&sess->by_srv);
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100317 HA_SPIN_UNLOCK(SERVER_LOCK, &srv->lock);
Simon Hormanaf514952011-06-21 14:34:57 +0900318}
319
Willy Tarreau87b09662015-04-03 00:22:06 +0200320static void inline stream_init_srv_conn(struct stream *sess)
Willy Tarreau9bd0d742011-07-20 00:17:39 +0200321{
322 sess->srv_conn = NULL;
323 LIST_INIT(&sess->by_srv);
324}
325
Christopher Fauleta73e59b2016-12-09 17:30:18 +0100326/* Callback used to wake up a stream when a buffer is available. The stream <s>
327 * is woken up is if it is not already running and if it is not already in the
328 * task run queue. This functions returns 1 is the stream is woken up, otherwise
329 * it returns 0. */
330static int inline stream_res_wakeup(struct stream *s)
Willy Tarreaua24adf02014-11-27 01:11:56 +0100331{
Emeric Brunff449172017-03-31 12:04:09 +0200332 if (s->task->state & TASK_RUNNING)
Christopher Fauleta73e59b2016-12-09 17:30:18 +0100333 return 0;
334 task_wakeup(s->task, TASK_WOKEN_RES);
335 return 1;
Willy Tarreaua24adf02014-11-27 01:11:56 +0100336}
337
Thierry FOURNIER5a363e72015-09-27 19:29:33 +0200338void service_keywords_register(struct action_kw_list *kw_list);
339
Willy Tarreau87b09662015-04-03 00:22:06 +0200340#endif /* _PROTO_STREAM_H */
Willy TARREAU3dc06442006-06-15 21:48:13 +0200341
Willy Tarreaubaaee002006-06-26 02:48:02 +0200342/*
343 * Local variables:
344 * c-indent-level: 8
345 * c-basic-offset: 8
346 * End:
347 */