blob: d67c9324169265d74f6a7c71eb8e70612939c0b3 [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 Tarreaue393fe22008-08-16 22:18:07 +020029 * member 'flags' in struct buffer. Some of them are persistent (BF_SHUT*),
30 * some of them (BF_EMPTY,BF_FULL) may only be set by the low-level read/write
31 * functions as well as those who change the buffer's read limit.
Willy Tarreau54469402006-07-29 16:59:06 +020032 */
Willy Tarreaue393fe22008-08-16 22:18:07 +020033#define BF_EMPTY 1 /* buffer is empty */
34#define BF_FULL 2 /* buffer cannot accept any more data (l >= rlim-data) */
35
Willy Tarreauba392ce2008-08-16 21:13:23 +020036#define BF_SHUTR 4 /* producer has already shut down */
37#define BF_SHUTW 8 /* consumer has already shut down */
Willy Tarreau0f9f5052006-07-29 17:39:25 +020038
Willy Tarreau54469402006-07-29 16:59:06 +020039#define BF_PARTIAL_READ 16
40#define BF_COMPLETE_READ 32
41#define BF_READ_ERROR 64
Willy Tarreau0f9f5052006-07-29 17:39:25 +020042#define BF_READ_NULL 128
43#define BF_READ_STATUS (BF_PARTIAL_READ|BF_COMPLETE_READ|BF_READ_ERROR|BF_READ_NULL)
44#define BF_CLEAR_READ (~BF_READ_STATUS)
Willy Tarreau54469402006-07-29 16:59:06 +020045
Willy Tarreau0f9f5052006-07-29 17:39:25 +020046#define BF_PARTIAL_WRITE 256
47#define BF_COMPLETE_WRITE 512
Willy Tarreaudc0a6a02008-08-03 20:38:13 +020048#define BF_WRITE_ERROR 1024
49#define BF_WRITE_NULL 2048
50#define BF_WRITE_STATUS (BF_PARTIAL_WRITE|BF_COMPLETE_WRITE|BF_WRITE_ERROR|BF_WRITE_NULL)
51#define BF_CLEAR_WRITE (~BF_WRITE_STATUS)
Willy Tarreau54469402006-07-29 16:59:06 +020052
Willy Tarreaudc0a6a02008-08-03 20:38:13 +020053#define BF_STREAMER 4096
54#define BF_STREAMER_FAST 8192
Willy Tarreau54469402006-07-29 16:59:06 +020055
Willy Tarreaud9f48362008-08-16 16:39:26 +020056#define BF_MAY_FORWARD 16384 /* consumer side is allowed to forward the data */
57#define BF_READ_TIMEOUT 32768 /* timeout while waiting for producer */
58#define BF_WRITE_TIMEOUT 65536 /* timeout while waiting for consumer */
Willy Tarreau0f9f5052006-07-29 17:39:25 +020059
Willy Tarreaufa7e1022008-10-19 07:30:41 +020060/* When either BF_SHUTR_NOW or BF_HIJACK is set, it is strictly forbidden for
61 * the stream interface to alter the buffer contents. When BF_SHUTW_NOW is set,
62 * it is strictly forbidden for the stream interface to send anything from the
63 * buffer.
64 */
65#define BF_SHUTR_NOW 131072 /* the producer must shut down for reads ASAP */
66#define BF_SHUTW_NOW 262144 /* the consumer must shut down for writes ASAP */
67#define BF_HIJACK 524288 /* the producer is temporarily replaced */
68
Willy Tarreauf9839bd2008-08-27 23:57:16 +020069/* masks which define input bits for stream interfaces and stream analysers */
70#define BF_MASK_INTERFACE_I (BF_FULL|BF_HIJACK|BF_READ_NULL|BF_SHUTR|BF_SHUTR_NOW|BF_SHUTW)
71#define BF_MASK_INTERFACE_O (BF_EMPTY|BF_HIJACK|BF_MAY_FORWARD|BF_SHUTR|BF_SHUTW|BF_SHUTW_NOW)
72#define BF_MASK_INTERFACE (BF_MASK_INTF_I | BF_MASK_INTF_O)
73
Willy Tarreau3a16b2c2008-08-28 08:54:27 +020074#define BF_MASK_ANALYSER (BF_FULL|BF_READ_NULL|BF_READ_ERROR|BF_READ_TIMEOUT|BF_SHUTR|BF_WRITE_ERROR)
Willy Tarreau72b179a2008-08-28 16:01:32 +020075#define BF_MASK_INJECTER (BF_FULL|BF_WRITE_STATUS|BF_WRITE_TIMEOUT|BF_SHUTW)
Willy Tarreau2df28e82008-08-17 15:20:19 +020076
77/* Analysers (buffer->analysers).
78 * Those bits indicate that there are some processing to do on the buffer
79 * contents. It will probably evolved into a linked list later. Those
80 * analysers could be compared to higher level processors.
81 * The field is blanked by buffer_init() and only by analysers themselves
82 * afterwards.
83 */
84#define AN_REQ_INSPECT 0x00000001 /* inspect request contents */
85#define AN_REQ_HTTP_HDR 0x00000002 /* inspect HTTP request headers */
86#define AN_REQ_HTTP_BODY 0x00000004 /* inspect HTTP request body */
Willy Tarreaufa7e1022008-10-19 07:30:41 +020087#define AN_REQ_HTTP_TARPIT 0x00000008 /* wait for end of HTTP tarpit */
88#define AN_RTR_HTTP_HDR 0x00000010 /* inspect HTTP response headers */
Willy Tarreau2df28e82008-08-17 15:20:19 +020089
Willy Tarreaubaaee002006-06-26 02:48:02 +020090/* describes a chunk of string */
91struct chunk {
92 char *str; /* beginning of the string itself. Might not be 0-terminated */
93 int len; /* size of the string from first to last char. <0 = uninit. */
94};
95
96struct buffer {
Willy Tarreauaad2e492006-10-15 23:32:18 +020097 unsigned int flags; /* BF_* */
Willy Tarreau0c303ee2008-07-07 00:09:58 +020098 int rex; /* expiration date for a read, in ticks */
Willy Tarreau26ed74d2008-08-17 12:11:14 +020099 int wex; /* expiration date for a write or connect, in ticks */
Willy Tarreau0c303ee2008-07-07 00:09:58 +0200100 int rto; /* read timeout, in ticks */
101 int wto; /* write timeout, in ticks */
102 int cto; /* connect timeout, in ticks */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200103 unsigned int l; /* data length */
Willy Tarreaue09e0ce2007-03-18 16:31:29 +0100104 char *r, *w, *lr; /* read ptr, write ptr, last read */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200105 char *rlim; /* read limit, used for header rewriting */
Willy Tarreau2df28e82008-08-17 15:20:19 +0200106 unsigned int analysers; /* bit field indicating what to do on the buffer */
Willy Tarreauffab5b42008-08-17 18:03:28 +0200107 int analyse_exp; /* expiration date for current analysers (if set) */
Willy Tarreau8a7af602008-05-03 23:07:14 +0200108 unsigned char xfer_large; /* number of consecutive large xfers */
109 unsigned char xfer_small; /* number of consecutive small xfers */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200110 unsigned long long total; /* total data read */
Willy Tarreaufa7e1022008-10-19 07:30:41 +0200111 struct stream_interface *prod; /* producer attached to this buffer */
112 struct stream_interface *cons; /* consumer attached to this buffer */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200113 char data[BUFSIZE];
114};
115
Willy Tarreaubaaee002006-06-26 02:48:02 +0200116
117#endif /* _TYPES_BUFFERS_H */
118
119/*
120 * Local variables:
121 * c-indent-level: 8
122 * c-basic-offset: 8
123 * End:
124 */