mirror of
https://github.com/haproxy/haproxy.git
synced 2026-02-23 01:42:05 -05:00
srv_state has been removed from HTTP state machines, and states
have been split in either TCP states or analyzers. For instance,
the TARPIT state has just become a simple analyzer.
New flags have been added to the struct buffer to compensate this.
The high-level stream processors sometimes need to force a disconnection
without touching a file-descriptor (eg: report an error). But if
they touched BF_SHUTW or BF_SHUTR, the file descriptor would not
be closed. Thus, the two SHUT?_NOW flags have been added so that
an application can request a forced close which the stream interface
will be forced to obey.
During this change, a new BF_HIJACK flag was added. It will
be used for data generation, eg during a stats dump. It
prevents the producer on a buffer from sending data into it.
BF_SHUTR_NOW /* the producer must shut down for reads ASAP */
BF_SHUTW_NOW /* the consumer must shut down for writes ASAP */
BF_HIJACK /* the producer is temporarily replaced */
BF_SHUTW_NOW has precedence over BF_HIJACK. BF_HIJACK has
precedence over BF_MAY_FORWARD (so that it does not need it).
New functions buffer_shutr_now(), buffer_shutw_now(), buffer_abort()
are provided to manipulate BF_SHUT* flags.
A new type "stream_interface" has been added to describe both
sides of a buffer. A stream interface has states and error
reporting. The session now has two stream interfaces (one per
side). Each buffer has stream_interface pointers to both
consumer and producer sides.
The server-side file descriptor has moved to its stream interface,
so that even the buffer has access to it.
process_srv() has been split into three parts :
- tcp_get_connection() obtains a connection to the server
- tcp_connection_failed() tests if a previously attempted
connection has succeeded or not.
- process_srv_data() only manages the data phase, and in
this sense should be roughly equivalent to process_cli.
Little code has been removed, and a lot of old code has been
left in comments for now.
117 lines
5 KiB
C
117 lines
5 KiB
C
/*
|
|
include/types/buffers.h
|
|
Buffer management definitions, macros and inline functions.
|
|
|
|
Copyright (C) 2000-2008 Willy Tarreau - w@1wt.eu
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
modify it under the terms of the GNU Lesser General Public
|
|
License as published by the Free Software Foundation, version 2.1
|
|
exclusively.
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Lesser General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
License along with this library; if not, write to the Free Software
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
*/
|
|
|
|
#ifndef _TYPES_BUFFERS_H
|
|
#define _TYPES_BUFFERS_H
|
|
|
|
#include <common/config.h>
|
|
#include <common/memory.h>
|
|
|
|
/* The BF_* macros designate Buffer Flags, which may be ORed in the bit field
|
|
* member 'flags' in struct buffer. Some of them are persistent (BF_SHUT*),
|
|
* some of them (BF_EMPTY,BF_FULL) may only be set by the low-level read/write
|
|
* functions as well as those who change the buffer's read limit.
|
|
*/
|
|
#define BF_EMPTY 1 /* buffer is empty */
|
|
#define BF_FULL 2 /* buffer cannot accept any more data (l >= rlim-data) */
|
|
|
|
#define BF_SHUTR 4 /* producer has already shut down */
|
|
#define BF_SHUTW 8 /* consumer has already shut down */
|
|
|
|
#define BF_PARTIAL_READ 16
|
|
#define BF_COMPLETE_READ 32
|
|
#define BF_READ_ERROR 64
|
|
#define BF_READ_NULL 128
|
|
#define BF_READ_STATUS (BF_PARTIAL_READ|BF_COMPLETE_READ|BF_READ_ERROR|BF_READ_NULL)
|
|
#define BF_CLEAR_READ (~BF_READ_STATUS)
|
|
|
|
#define BF_PARTIAL_WRITE 256
|
|
#define BF_COMPLETE_WRITE 512
|
|
#define BF_WRITE_ERROR 1024
|
|
#define BF_WRITE_NULL 2048
|
|
#define BF_WRITE_STATUS (BF_PARTIAL_WRITE|BF_COMPLETE_WRITE|BF_WRITE_ERROR|BF_WRITE_NULL)
|
|
#define BF_CLEAR_WRITE (~BF_WRITE_STATUS)
|
|
|
|
#define BF_STREAMER 4096
|
|
#define BF_STREAMER_FAST 8192
|
|
|
|
#define BF_MAY_FORWARD 16384 /* consumer side is allowed to forward the data */
|
|
#define BF_READ_TIMEOUT 32768 /* timeout while waiting for producer */
|
|
#define BF_WRITE_TIMEOUT 65536 /* timeout while waiting for consumer */
|
|
|
|
/* When either BF_SHUTR_NOW or BF_HIJACK is set, it is strictly forbidden for
|
|
* the stream interface to alter the buffer contents. When BF_SHUTW_NOW is set,
|
|
* it is strictly forbidden for the stream interface to send anything from the
|
|
* buffer.
|
|
*/
|
|
#define BF_SHUTR_NOW 131072 /* the producer must shut down for reads ASAP */
|
|
#define BF_SHUTW_NOW 262144 /* the consumer must shut down for writes ASAP */
|
|
#define BF_HIJACK 524288 /* the producer is temporarily replaced */
|
|
|
|
|
|
/* Analysers (buffer->analysers).
|
|
* Those bits indicate that there are some processing to do on the buffer
|
|
* contents. It will probably evolved into a linked list later. Those
|
|
* analysers could be compared to higher level processors.
|
|
* The field is blanked by buffer_init() and only by analysers themselves
|
|
* afterwards.
|
|
*/
|
|
#define AN_REQ_INSPECT 0x00000001 /* inspect request contents */
|
|
#define AN_REQ_HTTP_HDR 0x00000002 /* inspect HTTP request headers */
|
|
#define AN_REQ_HTTP_BODY 0x00000004 /* inspect HTTP request body */
|
|
#define AN_REQ_HTTP_TARPIT 0x00000008 /* wait for end of HTTP tarpit */
|
|
#define AN_RTR_HTTP_HDR 0x00000010 /* inspect HTTP response headers */
|
|
|
|
/* describes a chunk of string */
|
|
struct chunk {
|
|
char *str; /* beginning of the string itself. Might not be 0-terminated */
|
|
int len; /* size of the string from first to last char. <0 = uninit. */
|
|
};
|
|
|
|
struct buffer {
|
|
unsigned int flags; /* BF_* */
|
|
int rex; /* expiration date for a read, in ticks */
|
|
int wex; /* expiration date for a write or connect, in ticks */
|
|
int rto; /* read timeout, in ticks */
|
|
int wto; /* write timeout, in ticks */
|
|
int cto; /* connect timeout, in ticks */
|
|
unsigned int l; /* data length */
|
|
char *r, *w, *lr; /* read ptr, write ptr, last read */
|
|
char *rlim; /* read limit, used for header rewriting */
|
|
unsigned int analysers; /* bit field indicating what to do on the buffer */
|
|
int analyse_exp; /* expiration date for current analysers (if set) */
|
|
unsigned char xfer_large; /* number of consecutive large xfers */
|
|
unsigned char xfer_small; /* number of consecutive small xfers */
|
|
unsigned long long total; /* total data read */
|
|
struct stream_interface *prod; /* producer attached to this buffer */
|
|
struct stream_interface *cons; /* consumer attached to this buffer */
|
|
char data[BUFSIZE];
|
|
};
|
|
|
|
|
|
#endif /* _TYPES_BUFFERS_H */
|
|
|
|
/*
|
|
* Local variables:
|
|
* c-indent-level: 8
|
|
* c-basic-offset: 8
|
|
* End:
|
|
*/
|