blob: 1692f2115d5f5dbdca1bb7f789d25aabd38a56eb [file] [log] [blame]
Willy Tarreau1122d9c2012-02-27 19:31:50 +010012012/02/27 - Operations on haproxy buffers - w@1wt.eu
2
3
41) Definitions
5--------------
6
7A buffer is a unidirectional storage between two stream interfaces which are
8most often composed of a socket file descriptor. This storage is fixed sized
9and circular, which means that once data reach the end of the buffer, it loops
10back at the beginning of the buffer :
11
12
13 Representation of a non-wrapping buffer
14 ---------------------------------------
15
16
17 beginning end
18 | -------- length --------> |
19 V V
20 +-------------------------------------------+
21 | <--------------- size ----------------> |
22 +-------------------------------------------+
23
24
25 Representation of a wrapping buffer
26 -----------------------------------
27
28 end beginning
29 +------> | | -------------+
30 | V V |
31 | +-------------------------------------------+ |
32 | | <--------------- size ----------------> | |
33 | +-------------------------------------------+ |
34 | |
35 +--------------------- length -----------------------+
36
37
38Buffers are read by two entities :
39 - stream interfaces
40 - analysers
41
42Buffers are filled by two entities :
43 - stream interfaces
44 - hijackers
45
46A stream interface writes at the input of a buffer and reads at its output. An
47analyser has to parse incoming buffer contents, so it reads the input. It does
48not really write the output though it may change the buffer's contents at the
49input, possibly causing data moves. A hijacker it able to write at the output
50of a buffer. Hijackers are not used anymore at the moment though error outputs
51still work the same way.
52
53Buffers are referenced in the session. Each session has two buffers which
54interconnect the two stream interfaces. One buffer is called the request
55buffer, it sees traffic flowing from the client to the server. The other buffer
56is the response buffer, it sees traffic flowing from the server to the client.
57
58By convention, sessions are represented as 2 buffers one on top of the other,
59and with 2 stream interfaces connected to the two buffers. The client connects
60to the left stream interface (which then acts as a server), and the right
61stream interface (which acts as a client) connects to the server. The data
62circulate clockwise, so the upper buffer is the request buffer and the lower
63buffer is the response buffer :
64
65 ,------------------------.
66 ,-----> | request buffer | ------.
67 from ,--./ `------------------------' \,--. to
68 client ( ) ( ) server
69 `--' ,------------------------. /`--'
70 ^------- | response buffer | <-----'
71 `------------------------'
72
732) Operations
74-------------
75
76Socket-based stream interfaces write to buffers directly from the I/O layer
77without relying on any specific function.
78
79Function-based stream interfaces do use a number of non-uniform functions to
80read from the buffer's output and to write to the buffer's input. More suited
81names could be :
82
83 int buffer_output_peek_at(buf, ofs, ptr, size);
84 int buffer_output_peek(buf, ptr, size);
85 int buffer_output_read(buf, ptr, size);
86 int buffer_output_skip(buf, size);
87 int buffer_input_write(buf, ptr, size);
88
89Right now some stream interfaces use the following functions which also happen
90to automatically schedule the response for automatic forward :
91
92 buffer_put_block() [peers]
93 buffer_put_chunk() -> buffer_put_block()
94 buffer_feed_chunk() -> buffer_put_chunk() -> buffer_put_block() [dumpstats]
95 buffer_feed() -> buffer_put_string() -> buffer_put_block() [dumpstats]
96
97
98The following stream-interface oriented functions are not used :
99
100 buffer_get_char()
101 buffer_write_chunk()
102
103
104Analysers read data from the buffers' input, and may sometimes write data
105there too (or trim data). More suited names could be :
106
107 int buffer_input_peek_at(buf, ofs, ptr, size);
108 int buffer_input_truncate_at(buf, ofs);
109 int buffer_input_peek(buf, ptr, size);
110 int buffer_input_read(buf, ptr, size);
111 int buffer_input_skip(buf, size);
112 int buffer_input_cut(buf, size);
113 int buffer_input_truncate(buf);
114
115
116Functions that are available and need to be renamed :
117 - buffer_skip : buffer_output_skip
118 - buffer_ignore : buffer_input_skip ? => not exactly, more like
119 buffer_output_skip() without affecting sendmax !
120 - buffer_cut_tail : deletes all pending data after sendmax.
121 -> buffer_input_truncate(). Used by si_retnclose() only.
122 - buffer_contig_data : buffer_output_contig_data
123 - buffer_pending : buffer_input_pending_data
124 - buffer_contig_space : buffer_input_contig_space
125
126
127It looks like buf->lr could be removed and be stored in the HTTP message struct
128since it's only used at the HTTP level.