Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1 | /* |
| 2 | include/types/buffers.h |
| 3 | Buffer management definitions, macros and inline functions. |
| 4 | |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 5 | Copyright (C) 2000-2008 Willy Tarreau - w@1wt.eu |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 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 | */ |
| 21 | |
| 22 | #ifndef _TYPES_BUFFERS_H |
| 23 | #define _TYPES_BUFFERS_H |
| 24 | |
Willy Tarreau | e3ba5f0 | 2006-06-29 18:54:54 +0200 | [diff] [blame] | 25 | #include <common/config.h> |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 26 | #include <common/memory.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 27 | |
Willy Tarreau | 5446940 | 2006-07-29 16:59:06 +0200 | [diff] [blame] | 28 | /* The BF_* macros designate Buffer Flags, which may be ORed in the bit field |
Willy Tarreau | e393fe2 | 2008-08-16 22:18:07 +0200 | [diff] [blame] | 29 | * 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 Tarreau | 5446940 | 2006-07-29 16:59:06 +0200 | [diff] [blame] | 32 | */ |
Willy Tarreau | e393fe2 | 2008-08-16 22:18:07 +0200 | [diff] [blame] | 33 | #define BF_EMPTY 1 /* buffer is empty */ |
| 34 | #define BF_FULL 2 /* buffer cannot accept any more data (l >= rlim-data) */ |
| 35 | |
Willy Tarreau | ba392ce | 2008-08-16 21:13:23 +0200 | [diff] [blame] | 36 | #define BF_SHUTR 4 /* producer has already shut down */ |
| 37 | #define BF_SHUTW 8 /* consumer has already shut down */ |
Willy Tarreau | 0f9f505 | 2006-07-29 17:39:25 +0200 | [diff] [blame] | 38 | |
Willy Tarreau | 5446940 | 2006-07-29 16:59:06 +0200 | [diff] [blame] | 39 | #define BF_PARTIAL_READ 16 |
| 40 | #define BF_COMPLETE_READ 32 |
| 41 | #define BF_READ_ERROR 64 |
Willy Tarreau | 0f9f505 | 2006-07-29 17:39:25 +0200 | [diff] [blame] | 42 | #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 Tarreau | 5446940 | 2006-07-29 16:59:06 +0200 | [diff] [blame] | 45 | |
Willy Tarreau | 0f9f505 | 2006-07-29 17:39:25 +0200 | [diff] [blame] | 46 | #define BF_PARTIAL_WRITE 256 |
| 47 | #define BF_COMPLETE_WRITE 512 |
Willy Tarreau | dc0a6a0 | 2008-08-03 20:38:13 +0200 | [diff] [blame] | 48 | #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 Tarreau | 5446940 | 2006-07-29 16:59:06 +0200 | [diff] [blame] | 52 | |
Willy Tarreau | dc0a6a0 | 2008-08-03 20:38:13 +0200 | [diff] [blame] | 53 | #define BF_STREAMER 4096 |
| 54 | #define BF_STREAMER_FAST 8192 |
Willy Tarreau | 5446940 | 2006-07-29 16:59:06 +0200 | [diff] [blame] | 55 | |
Willy Tarreau | d9f4836 | 2008-08-16 16:39:26 +0200 | [diff] [blame] | 56 | #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 Tarreau | 0f9f505 | 2006-07-29 17:39:25 +0200 | [diff] [blame] | 59 | |
Willy Tarreau | 2df28e8 | 2008-08-17 15:20:19 +0200 | [diff] [blame] | 60 | |
| 61 | /* Analysers (buffer->analysers). |
| 62 | * Those bits indicate that there are some processing to do on the buffer |
| 63 | * contents. It will probably evolved into a linked list later. Those |
| 64 | * analysers could be compared to higher level processors. |
| 65 | * The field is blanked by buffer_init() and only by analysers themselves |
| 66 | * afterwards. |
| 67 | */ |
| 68 | #define AN_REQ_INSPECT 0x00000001 /* inspect request contents */ |
| 69 | #define AN_REQ_HTTP_HDR 0x00000002 /* inspect HTTP request headers */ |
| 70 | #define AN_REQ_HTTP_BODY 0x00000004 /* inspect HTTP request body */ |
| 71 | #define AN_RTR_HTTP_HDR 0x00000008 /* inspect HTTP response headers */ |
| 72 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 73 | /* describes a chunk of string */ |
| 74 | struct chunk { |
| 75 | char *str; /* beginning of the string itself. Might not be 0-terminated */ |
| 76 | int len; /* size of the string from first to last char. <0 = uninit. */ |
| 77 | }; |
| 78 | |
| 79 | struct buffer { |
Willy Tarreau | aad2e49 | 2006-10-15 23:32:18 +0200 | [diff] [blame] | 80 | unsigned int flags; /* BF_* */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 81 | int rex; /* expiration date for a read, in ticks */ |
Willy Tarreau | 26ed74d | 2008-08-17 12:11:14 +0200 | [diff] [blame] | 82 | int wex; /* expiration date for a write or connect, in ticks */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 83 | int rto; /* read timeout, in ticks */ |
| 84 | int wto; /* write timeout, in ticks */ |
| 85 | int cto; /* connect timeout, in ticks */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 86 | unsigned int l; /* data length */ |
Willy Tarreau | e09e0ce | 2007-03-18 16:31:29 +0100 | [diff] [blame] | 87 | char *r, *w, *lr; /* read ptr, write ptr, last read */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 88 | char *rlim; /* read limit, used for header rewriting */ |
Willy Tarreau | 2df28e8 | 2008-08-17 15:20:19 +0200 | [diff] [blame] | 89 | unsigned int analysers; /* bit field indicating what to do on the buffer */ |
Willy Tarreau | 8a7af60 | 2008-05-03 23:07:14 +0200 | [diff] [blame] | 90 | unsigned char xfer_large; /* number of consecutive large xfers */ |
| 91 | unsigned char xfer_small; /* number of consecutive small xfers */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 92 | unsigned long long total; /* total data read */ |
| 93 | char data[BUFSIZE]; |
| 94 | }; |
| 95 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 96 | |
| 97 | #endif /* _TYPES_BUFFERS_H */ |
| 98 | |
| 99 | /* |
| 100 | * Local variables: |
| 101 | * c-indent-level: 8 |
| 102 | * c-basic-offset: 8 |
| 103 | * End: |
| 104 | */ |