blob: 583c517d136d38b212ca9be4fadaba52e33563d6 [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 Tarreaue09e0ce2007-03-18 16:31:29 +01005 Copyright (C) 2000-2007 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 Tarreau014b4fe2006-10-15 22:57:13 +020028#include <sys/time.h>
29#include <sys/types.h>
Willy Tarreau54469402006-07-29 16:59:06 +020030
31/* The BF_* macros designate Buffer Flags, which may be ORed in the bit field
32 * member 'flags' in struct buffer.
33 */
34#define BF_SHUTR_PENDING 1
35#define BF_SHUTR_DONE 2
Willy Tarreaufa645582007-06-03 15:59:52 +020036#define BF_SHUTR_STATUS (BF_SHUTR_PENDING|BF_SHUTR_DONE)
37
Willy Tarreau54469402006-07-29 16:59:06 +020038#define BF_SHUTW_PENDING 4
39#define BF_SHUTW_DONE 8
Willy Tarreaufa645582007-06-03 15:59:52 +020040#define BF_SHUTW_STATUS (BF_SHUTW_PENDING|BF_SHUTW_DONE)
Willy Tarreau0f9f5052006-07-29 17:39:25 +020041
Willy Tarreau54469402006-07-29 16:59:06 +020042#define BF_PARTIAL_READ 16
43#define BF_COMPLETE_READ 32
44#define BF_READ_ERROR 64
Willy Tarreau0f9f5052006-07-29 17:39:25 +020045#define BF_READ_NULL 128
46#define BF_READ_STATUS (BF_PARTIAL_READ|BF_COMPLETE_READ|BF_READ_ERROR|BF_READ_NULL)
47#define BF_CLEAR_READ (~BF_READ_STATUS)
Willy Tarreau54469402006-07-29 16:59:06 +020048
Willy Tarreau0f9f5052006-07-29 17:39:25 +020049#define BF_PARTIAL_WRITE 256
50#define BF_COMPLETE_WRITE 512
51#define BF_WRITE_ERROR 1024
52#define BF_WRITE_NULL 2048
53#define BF_WRITE_STATUS (BF_PARTIAL_WRITE|BF_COMPLETE_WRITE|BF_WRITE_ERROR|BF_WRITE_NULL)
54#define BF_CLEAR_WRITE (~BF_WRITE_STATUS)
Willy Tarreau54469402006-07-29 16:59:06 +020055
Willy Tarreau8a7af602008-05-03 23:07:14 +020056#define BF_STREAMER 4096
57#define BF_STREAMER_FAST 8192
Willy Tarreau54469402006-07-29 16:59:06 +020058
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 Tarreaud7971282006-07-29 18:36:34 +020068 struct timeval rex; /* expiration date for a read */
69 struct timeval wex; /* expiration date for a write */
70 struct timeval cex; /* expiration date for a connect */
Willy Tarreaud825eef2007-05-12 22:35:00 +020071 struct timeval rto; /* read timeout */
72 struct timeval wto; /* write timeout */
73 struct timeval cto; /* connect timeout */
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 */