blob: 83190104c5d0f798e6289557418264a3be890c95 [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
29 * member 'flags' in struct buffer.
30 */
Willy Tarreau89edf5e2008-08-03 17:25:14 +020031#define BF_SHUTR_PENDING 1 /* ignored if BF_SHUTW_DONE */
32#define BF_SHUTR_DONE 2 /* takes precedence over BF_SHUTR_PENDING */
Willy Tarreaufa645582007-06-03 15:59:52 +020033#define BF_SHUTR_STATUS (BF_SHUTR_PENDING|BF_SHUTR_DONE)
34
Willy Tarreau89edf5e2008-08-03 17:25:14 +020035#define BF_SHUTW_PENDING 4 /* ignored if BF_SHUTW_DONE */
36#define BF_SHUTW_DONE 8 /* takes precedence over BF_SHUTW_PENDING */
Willy Tarreaufa645582007-06-03 15:59:52 +020037#define BF_SHUTW_STATUS (BF_SHUTW_PENDING|BF_SHUTW_DONE)
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 Tarreaubaaee002006-06-26 02:48:02 +020060/* describes a chunk of string */
61struct chunk {
62 char *str; /* beginning of the string itself. Might not be 0-terminated */
63 int len; /* size of the string from first to last char. <0 = uninit. */
64};
65
66struct buffer {
Willy Tarreauaad2e492006-10-15 23:32:18 +020067 unsigned int flags; /* BF_* */
Willy Tarreau0c303ee2008-07-07 00:09:58 +020068 int rex; /* expiration date for a read, in ticks */
69 int wex; /* expiration date for a write, in ticks */
70 int cex; /* expiration date for a connect, in ticks */
71 int rto; /* read timeout, in ticks */
72 int wto; /* write timeout, in ticks */
73 int cto; /* connect timeout, in ticks */
Willy Tarreaubaaee002006-06-26 02:48:02 +020074 unsigned int l; /* data length */
Willy Tarreaue09e0ce2007-03-18 16:31:29 +010075 char *r, *w, *lr; /* read ptr, write ptr, last read */
Willy Tarreaubaaee002006-06-26 02:48:02 +020076 char *rlim; /* read limit, used for header rewriting */
Willy Tarreau8a7af602008-05-03 23:07:14 +020077 unsigned char xfer_large; /* number of consecutive large xfers */
78 unsigned char xfer_small; /* number of consecutive small xfers */
Willy Tarreaubaaee002006-06-26 02:48:02 +020079 unsigned long long total; /* total data read */
80 char data[BUFSIZE];
81};
82
Willy Tarreaubaaee002006-06-26 02:48:02 +020083
84#endif /* _TYPES_BUFFERS_H */
85
86/*
87 * Local variables:
88 * c-indent-level: 8
89 * c-basic-offset: 8
90 * End:
91 */