blob: c35ef37162541fb983ccfc6ed93e69b828cea7f2 [file] [log] [blame]
Willy Tarreaubaaee002006-06-26 02:48:02 +02001/*
2 include/types/buffers.h
3 Buffer management definitions, macros and inline functions.
4
Willy Tarreau0c303ee2008-07-07 00:09:58 +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 _TYPES_BUFFERS_H
23#define _TYPES_BUFFERS_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>
Willy Tarreaubaaee002006-06-26 02:48:02 +020027
Willy Tarreau54469402006-07-29 16:59:06 +020028/* The BF_* macros designate Buffer Flags, which may be ORed in the bit field
Willy Tarreau3da77c52008-08-29 09:58:42 +020029 * member 'flags' in struct buffer. Here we have several types of flags :
30 *
31 * - pure status flags, reported by the lower layer, which must be cleared
32 * before doing further I/O :
33 * BF_*_NULL, BF_*_PARTIAL
34 *
35 * - pure status flags, reported by mid-layer, which must also be cleared
36 * before doing further I/O :
37 * BF_*_TIMEOUT, BF_*_ERROR
38 *
39 * - read-only indicators reported by lower levels :
40 * BF_STREAMER, BF_STREAMER_FAST
41 *
42 * - write-once status flags reported by the mid-level : BF_SHUTR, BF_SHUTW
43 *
44 * - persistent control flags managed only by higher level :
45 * BF_SHUT*_NOW, BF_*_ENA, BF_HIJACK
46 *
47 * The flags have been arranged for readability, so that the read and write
48 * bits have se same position in a byte (read being the lower byte and write
49 * the second one).
Willy Tarreau54469402006-07-29 16:59:06 +020050 */
Willy Tarreaue393fe22008-08-16 22:18:07 +020051
Willy Tarreau3da77c52008-08-29 09:58:42 +020052#define BF_READ_NULL 0x000001 /* last read detected on producer side */
53#define BF_READ_PARTIAL 0x000002 /* some data were read from producer */
54#define BF_READ_TIMEOUT 0x000004 /* timeout while waiting for producer */
55#define BF_READ_ERROR 0x000008 /* unrecoverable error on producer side */
56#define BF_READ_ACTIVITY (BF_READ_NULL|BF_READ_PARTIAL|BF_READ_ERROR)
57#define BF_READ_STATUS (BF_READ_NULL|BF_READ_PARTIAL|BF_READ_ERROR|BF_READ_TIMEOUT)
58#define BF_CLEAR_READ (~BF_READ_STATUS)
Willy Tarreau0f9f5052006-07-29 17:39:25 +020059
Willy Tarreau3da77c52008-08-29 09:58:42 +020060#define BF_FULL 0x000010 /* buffer cannot accept any more data (l >= rlim-data) */
61#define BF_SHUTR 0x000020 /* producer has already shut down */
62#define BF_SHUTR_NOW 0x000040 /* the producer must shut down for reads immediately */
63#define BF_READ_ENA 0x000080 /* producer is allowed to feed data into the buffer */
Willy Tarreau54469402006-07-29 16:59:06 +020064
Willy Tarreau3da77c52008-08-29 09:58:42 +020065#define BF_WRITE_NULL 0x000100 /* write(0) or connect() succeeded on consumer side */
66#define BF_WRITE_PARTIAL 0x000200 /* some data were written to the consumer */
67#define BF_WRITE_TIMEOUT 0x000400 /* timeout while waiting for consumer */
68#define BF_WRITE_ERROR 0x000800 /* unrecoverable error on consumer side */
69#define BF_WRITE_ACTIVITY (BF_WRITE_NULL|BF_WRITE_PARTIAL|BF_WRITE_ERROR)
70#define BF_WRITE_STATUS (BF_WRITE_NULL|BF_WRITE_PARTIAL|BF_WRITE_ERROR|BF_WRITE_TIMEOUT)
71#define BF_CLEAR_WRITE (~BF_WRITE_STATUS)
Willy Tarreau54469402006-07-29 16:59:06 +020072
Willy Tarreau3da77c52008-08-29 09:58:42 +020073#define BF_EMPTY 0x001000 /* buffer is empty */
74#define BF_SHUTW 0x002000 /* consumer has already shut down */
75#define BF_SHUTW_NOW 0x004000 /* the consumer must shut down for writes immediately */
76#define BF_WRITE_ENA 0x008000 /* consumer is allowed to forward all buffer contents */
Willy Tarreau54469402006-07-29 16:59:06 +020077
Willy Tarreau3da77c52008-08-29 09:58:42 +020078#define BF_STREAMER 0x010000 /* the producer is identified as streaming data */
79#define BF_STREAMER_FAST 0x020000 /* the consumer seems to eat the stream very fast */
Willy Tarreau0f9f5052006-07-29 17:39:25 +020080
Willy Tarreaufa7e1022008-10-19 07:30:41 +020081/* When either BF_SHUTR_NOW or BF_HIJACK is set, it is strictly forbidden for
82 * the stream interface to alter the buffer contents. When BF_SHUTW_NOW is set,
83 * it is strictly forbidden for the stream interface to send anything from the
84 * buffer.
85 */
Willy Tarreau3da77c52008-08-29 09:58:42 +020086#define BF_HIJACK 0x040000 /* the producer is temporarily replaced */
Willy Tarreaufa7e1022008-10-19 07:30:41 +020087
Willy Tarreau3da77c52008-08-29 09:58:42 +020088/* Masks which define input bits for stream interfaces and stream analysers */
89#define BF_MASK_INTERFACE_I (BF_FULL|BF_HIJACK|BF_READ_ENA|BF_READ_STATUS|BF_SHUTR_NOW|BF_SHUTR|BF_SHUTW)
90#define BF_MASK_INTERFACE_O (BF_EMPTY|BF_HIJACK|BF_WRITE_ENA|BF_WRITE_STATUS|BF_SHUTW_NOW|BF_SHUTR|BF_SHUTW)
Willy Tarreauf9839bd2008-08-27 23:57:16 +020091#define BF_MASK_INTERFACE (BF_MASK_INTF_I | BF_MASK_INTF_O)
92
Willy Tarreau3da77c52008-08-29 09:58:42 +020093#define BF_MASK_ANALYSER (BF_FULL|BF_READ_STATUS|BF_SHUTR|BF_WRITE_ERROR)
94#define BF_MASK_HIJACKER (BF_FULL|BF_WRITE_STATUS|BF_WRITE_TIMEOUT|BF_SHUTW)
95
Willy Tarreau2df28e82008-08-17 15:20:19 +020096
97/* Analysers (buffer->analysers).
98 * Those bits indicate that there are some processing to do on the buffer
99 * contents. It will probably evolved into a linked list later. Those
100 * analysers could be compared to higher level processors.
101 * The field is blanked by buffer_init() and only by analysers themselves
102 * afterwards.
103 */
104#define AN_REQ_INSPECT 0x00000001 /* inspect request contents */
105#define AN_REQ_HTTP_HDR 0x00000002 /* inspect HTTP request headers */
106#define AN_REQ_HTTP_BODY 0x00000004 /* inspect HTTP request body */
Willy Tarreaufa7e1022008-10-19 07:30:41 +0200107#define AN_REQ_HTTP_TARPIT 0x00000008 /* wait for end of HTTP tarpit */
108#define AN_RTR_HTTP_HDR 0x00000010 /* inspect HTTP response headers */
Willy Tarreau2df28e82008-08-17 15:20:19 +0200109
Willy Tarreaubaaee002006-06-26 02:48:02 +0200110/* describes a chunk of string */
111struct chunk {
112 char *str; /* beginning of the string itself. Might not be 0-terminated */
113 int len; /* size of the string from first to last char. <0 = uninit. */
114};
115
116struct buffer {
Willy Tarreauaad2e492006-10-15 23:32:18 +0200117 unsigned int flags; /* BF_* */
Willy Tarreau0c303ee2008-07-07 00:09:58 +0200118 int rex; /* expiration date for a read, in ticks */
Willy Tarreau26ed74d2008-08-17 12:11:14 +0200119 int wex; /* expiration date for a write or connect, in ticks */
Willy Tarreau0c303ee2008-07-07 00:09:58 +0200120 int rto; /* read timeout, in ticks */
121 int wto; /* write timeout, in ticks */
122 int cto; /* connect timeout, in ticks */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200123 unsigned int l; /* data length */
Willy Tarreaue09e0ce2007-03-18 16:31:29 +0100124 char *r, *w, *lr; /* read ptr, write ptr, last read */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200125 char *rlim; /* read limit, used for header rewriting */
Willy Tarreau2df28e82008-08-17 15:20:19 +0200126 unsigned int analysers; /* bit field indicating what to do on the buffer */
Willy Tarreauffab5b42008-08-17 18:03:28 +0200127 int analyse_exp; /* expiration date for current analysers (if set) */
Willy Tarreau8a7af602008-05-03 23:07:14 +0200128 unsigned char xfer_large; /* number of consecutive large xfers */
129 unsigned char xfer_small; /* number of consecutive small xfers */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200130 unsigned long long total; /* total data read */
Willy Tarreaufa7e1022008-10-19 07:30:41 +0200131 struct stream_interface *prod; /* producer attached to this buffer */
132 struct stream_interface *cons; /* consumer attached to this buffer */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200133 char data[BUFSIZE];
134};
135
Willy Tarreaubaaee002006-06-26 02:48:02 +0200136
137#endif /* _TYPES_BUFFERS_H */
138
139/*
140 * Local variables:
141 * c-indent-level: 8
142 * c-basic-offset: 8
143 * End:
144 */