-
Notifications
You must be signed in to change notification settings - Fork 1
/
body-factory.en.html
360 lines (340 loc) · 31.8 KB
/
body-factory.en.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
<title>Body Factory Refactoring — AMC Traffic Server Documentation</title>
<link rel="stylesheet" type="text/css" href="_static/pygments.css" />
<link rel="stylesheet" type="text/css" href="_static/sphinxdoc.css" />
<link rel="stylesheet" type="text/css" href="_static/graphviz.css" />
<script data-url_root="./" id="documentation_options" src="_static/documentation_options.js"></script>
<script src="_static/jquery.js"></script>
<script src="_static/underscore.js"></script>
<script src="_static/doctools.js"></script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="Layer 4 Proxying" href="l4r.en.html" />
<link rel="prev" title="Errata" href="errata.en.html" />
</head><body>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="l4r.en.html" title="Layer 4 Proxying"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="errata.en.html" title="Errata"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">SWOC Docs</a> »</li>
<li class="nav-item nav-item-1"><a href="ats-projects.en.html" accesskey="U">Traffic Server Projects</a> »</li>
<li class="nav-item nav-item-this"><a href="">Body Factory Refactoring</a></li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<section id="body-factory-refactoring">
<h1>Body Factory Refactoring<a class="headerlink" href="#body-factory-refactoring" title="Permalink to this headline">¶</a></h1>
<p>The core logic used to generate proxy replies is convoluted and fragile. It has needed to be cleaned
up for a long time both to make it more robust and maintainable but also to add features that are
currently hard to do. There are also arbitrary internal limits which are entirely artifacts of the
implementation.</p>
<p>The goal is to replace all of this with <code class="code docutils literal notranslate"><span class="pre">MIOBuffer</span></code> to get the following benefits:</p>
<ul class="simple">
<li><p>Remove arbitrary limits.</p></li>
<li><p>Remove all direct memory allocation, use only <code class="code docutils literal notranslate"><span class="pre">IOBufferBlock</span></code> based allocations.</p></li>
<li><p>Reduce costs of using the generated bodies later. An <code class="code docutils literal notranslate"><span class="pre">MIOBuffer</span></code> can be directly fed to an
output tunnel or even a socket without additional copies or allocations.</p></li>
<li><p>Simplify the code. All output is done directly to an <code class="code docutils literal notranslate"><span class="pre">MIOBuffer</span></code>.</p></li>
</ul>
<p>The basic plan is to extend the <code class="code docutils literal notranslate"><span class="pre">BufferWriter</span></code> class to have one that takes an
<code class="code docutils literal notranslate"><span class="pre">MIOBuffer</span></code> as its output target. This would make it basically equivalent to C++ I/O stream operators
but using Traffic Server core mechanisms.</p>
<section id="implementation">
<h2>Implementation<a class="headerlink" href="#implementation" title="Permalink to this headline">¶</a></h2>
<p>The starting change is</p>
<ol class="arabic simple">
<li><p>change <code class="code docutils literal notranslate"><span class="pre">HttpTransact::State::internal_msg_buffer</span></code> from a <code class="code docutils literal notranslate"><span class="pre">char*</span></code> to :<cite>MIOBuffer</cite></p></li>
<li><p>remove <code class="code docutils literal notranslate"><span class="pre">HttpTransact::State::internal_msg_size</span></code></p></li>
<li><p>remove <code class="code docutils literal notranslate"><span class="pre">HttpTransact::State::internal_msg_size_fast_allocator_size</span></code></p></li>
<li><p>change <code class="code docutils literal notranslate"><span class="pre">HttpTransact::State::internal_msg_buffer_type</span></code> to <code class="code docutils literal notranslate"><span class="pre">ats_scoped_str</span></code>. This is
used to populate the <code class="docutils literal notranslate"><span class="pre">Content-Type</span></code> header and so doesn’t need to be a variable sized buffer.
It could probably be made a fixed size string of some reasonable length (~128 bytes) without loss
of generality.</p></li>
</ol>
<p>This has a large and extensive ripple of changes that achieve the
goals of this project. Chasing these down and fixing them will be the bulk of the effort. There are
a few others issues to be careful about</p>
<ul class="simple">
<li><p>Some mark is needed to track if there is a body at all - there is a semantic difference between a
body of length zero and no body at all.</p></li>
</ul>
</section>
<section id="further-work">
<h2>Further Work<a class="headerlink" href="#further-work" title="Permalink to this headline">¶</a></h2>
<p>A new “Format” class could be done which processes the current log style format strings in a generic
and modular way. The body factory would be updated to use these new classes.</p>
</section>
<section id="documentation">
<h2>Documentation<a class="headerlink" href="#documentation" title="Permalink to this headline">¶</a></h2>
<p>The following sections are intended as documentation to be added to the Traffic Server documentation set.</p>
</section>
<section id="tshttptxnapplylogformat">
<h2>TSHttpTxnApplyLogFormat<a class="headerlink" href="#tshttptxnapplylogformat" title="Permalink to this headline">¶</a></h2>
<section id="synopsis">
<h3>Synopsis<a class="headerlink" href="#synopsis" title="Permalink to this headline">¶</a></h3>
<p><cite>#include <ts/ts.h></cite></p>
<dl class="c function">
<dt class="sig sig-object c" id="c.TSHttpTxnApplyLogFormat">
<a class="reference internal" href="external-types.en.html#c.TSReturnCode" title="TSReturnCode"><span class="n"><span class="pre">TSReturnCode</span></span></a><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">TSHttpTxnApplyLogFormat</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="external-types.en.html#c.TSHttpTxn" title="TSHttpTxn"><span class="n"><span class="pre">TSHttpTxn</span></span></a><span class="w"> </span><span class="n"><span class="pre">txnp</span></span>, <span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">format</span></span>, <a class="reference internal" href="external-types.en.html#c.TSIOBuffer" title="TSIOBuffer"><span class="n"><span class="pre">TSIOBuffer</span></span></a><span class="w"> </span><span class="n"><span class="pre">out</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.TSHttpTxnApplyLogFormat" title="Permalink to this definition">¶</a><br /></dt>
<dd></dd></dl>
</section>
<section id="description">
<h3>Description<a class="headerlink" href="#description" title="Permalink to this headline">¶</a></h3>
<p>Apply the log <em>format</em> string to the transaction <em>txnp</em> placing the result in the buffer
<em>out</em>. The format is identical to <a class="reference internal" href="external-types.en.html#custom-logging-fields"><span class="std std-ref">custom log formats</span></a>. The result
is appended to <em>out</em> in ASCII format. <em>out</em> must be created by the plugin.</p>
</section>
<section id="see-also">
<h3>See also<a class="headerlink" href="#see-also" title="Permalink to this headline">¶</a></h3>
<p><em class="manpage">TSIOBufferCreate(3ts)</em>, <em class="manpage">TSIOBufferReaderAlloc(3ts)</em></p>
</section>
</section>
<section id="tshttptxnerrorbodyset">
<h2>TSHttpTxnErrorBodySet<a class="headerlink" href="#tshttptxnerrorbodyset" title="Permalink to this headline">¶</a></h2>
<p>Sets an error type body to a transaction.</p>
<section id="id1">
<h3>Synopsis<a class="headerlink" href="#id1" title="Permalink to this headline">¶</a></h3>
<p><cite>#include <ts/ts.h></cite></p>
<dl class="c function">
<dt class="sig sig-object c" id="c.TSHttpTxnErrorBodySet">
<span class="kt"><span class="pre">void</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">TSHttpTxnErrorBodySet</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="external-types.en.html#c.TSHttpTxn" title="TSHttpTxn"><span class="n"><span class="pre">TSHttpTxn</span></span></a><span class="w"> </span><span class="n"><span class="pre">txnp</span></span>, <span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">buf</span></span>, <span class="n"><span class="pre">size_t</span></span><span class="w"> </span><span class="n"><span class="pre">buflength</span></span>, <span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">mimetype</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.TSHttpTxnErrorBodySet" title="Permalink to this definition">¶</a><br /></dt>
<dd></dd></dl>
</section>
<section id="id2">
<h3>Description<a class="headerlink" href="#id2" title="Permalink to this headline">¶</a></h3>
<p>Note that both string arguments must be allocated with <a class="reference internal" href="external-types.en.html#c.TSmalloc" title="TSmalloc"><code class="xref c c-func docutils literal notranslate"><span class="pre">TSmalloc()</span></code></a> or
<a class="reference internal" href="external-types.en.html#c.TSstrdup" title="TSstrdup"><code class="xref c c-func docutils literal notranslate"><span class="pre">TSstrdup()</span></code></a>. The <em>mimetype</em> is optional, and if not provided it
defaults to <code class="docutils literal notranslate"><span class="pre">text/html</span></code>. Sending an empty string would prevent setting
a content type header (but that is not adviced).</p>
</section>
</section>
<section id="tsiobufferreader">
<h2>TSIOBufferReader<a class="headerlink" href="#tsiobufferreader" title="Permalink to this headline">¶</a></h2>
<p>Traffic Server IO buffer reader API.</p>
<section id="id3">
<h3>Synopsis<a class="headerlink" href="#id3" title="Permalink to this headline">¶</a></h3>
<p><cite>#include <ts/ts.h></cite></p>
<dl class="c function">
<dt class="sig sig-object c" id="c.TSIOBufferReaderAlloc">
<a class="reference internal" href="external-types.en.html#c.TSIOBufferReader" title="TSIOBufferReader"><span class="n"><span class="pre">TSIOBufferReader</span></span></a><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">TSIOBufferReaderAlloc</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="external-types.en.html#c.TSIOBuffer" title="TSIOBuffer"><span class="n"><span class="pre">TSIOBuffer</span></span></a><span class="w"> </span><span class="n"><span class="pre">bufp</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.TSIOBufferReaderAlloc" title="Permalink to this definition">¶</a><br /></dt>
<dd></dd></dl>
<dl class="c function">
<dt class="sig sig-object c" id="c.TSIOBufferReaderClone">
<a class="reference internal" href="external-types.en.html#c.TSIOBufferReader" title="TSIOBufferReader"><span class="n"><span class="pre">TSIOBufferReader</span></span></a><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">TSIOBufferReaderClone</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="external-types.en.html#c.TSIOBufferReader" title="TSIOBufferReader"><span class="n"><span class="pre">TSIOBufferReader</span></span></a><span class="w"> </span><span class="n"><span class="pre">readerp</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.TSIOBufferReaderClone" title="Permalink to this definition">¶</a><br /></dt>
<dd></dd></dl>
<dl class="c function">
<dt class="sig sig-object c" id="c.TSIOBufferReaderFree">
<span class="kt"><span class="pre">void</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">TSIOBufferReaderFree</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="external-types.en.html#c.TSIOBufferReader" title="TSIOBufferReader"><span class="n"><span class="pre">TSIOBufferReader</span></span></a><span class="w"> </span><span class="n"><span class="pre">readerp</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.TSIOBufferReaderFree" title="Permalink to this definition">¶</a><br /></dt>
<dd></dd></dl>
<dl class="c function">
<dt class="sig sig-object c" id="c.TSIOBufferReaderConsume">
<span class="kt"><span class="pre">void</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">TSIOBufferReaderConsume</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="external-types.en.html#c.TSIOBufferReader" title="TSIOBufferReader"><span class="n"><span class="pre">TSIOBufferReader</span></span></a><span class="w"> </span><span class="n"><span class="pre">readerp</span></span>, <a class="reference internal" href="external-types.en.html#c.int64_t" title="int64_t"><span class="n"><span class="pre">int64_t</span></span></a><span class="w"> </span><span class="n"><span class="pre">nbytes</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.TSIOBufferReaderConsume" title="Permalink to this definition">¶</a><br /></dt>
<dd></dd></dl>
<dl class="c function">
<dt class="sig sig-object c" id="c.TSIOBufferReaderStart">
<a class="reference internal" href="external-types.en.html#c.TSIOBufferBlock" title="TSIOBufferBlock"><span class="n"><span class="pre">TSIOBufferBlock</span></span></a><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">TSIOBufferReaderStart</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="external-types.en.html#c.TSIOBufferReader" title="TSIOBufferReader"><span class="n"><span class="pre">TSIOBufferReader</span></span></a><span class="w"> </span><span class="n"><span class="pre">readerp</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.TSIOBufferReaderStart" title="Permalink to this definition">¶</a><br /></dt>
<dd></dd></dl>
<dl class="c function">
<dt class="sig sig-object c" id="c.TSIOBufferReaderAvail">
<a class="reference internal" href="external-types.en.html#c.int64_t" title="int64_t"><span class="n"><span class="pre">int64_t</span></span></a><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">TSIOBufferReaderAvail</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="external-types.en.html#c.TSIOBufferReader" title="TSIOBufferReader"><span class="n"><span class="pre">TSIOBufferReader</span></span></a><span class="w"> </span><span class="n"><span class="pre">readerp</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.TSIOBufferReaderAvail" title="Permalink to this definition">¶</a><br /></dt>
<dd></dd></dl>
<dl class="c function">
<dt class="sig sig-object c" id="c.TSIOBufferReaderIsAvailAtLeast">
<span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">TSIOBufferReaderIsAvailAtLeast</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="external-types.en.html#c.TSIOBufferReader" title="TSIOBufferReader"><span class="n"><span class="pre">TSIOBufferReader</span></span></a>, <a class="reference internal" href="external-types.en.html#c.int64_t" title="int64_t"><span class="n"><span class="pre">int64_t</span></span></a><span class="w"> </span><span class="n"><span class="pre">nbytes</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.TSIOBufferReaderIsAvailAtLeast" title="Permalink to this definition">¶</a><br /></dt>
<dd></dd></dl>
<dl class="c function">
<dt class="sig sig-object c" id="c.TSIOBufferReaderRead">
<a class="reference internal" href="external-types.en.html#c.int64_t" title="int64_t"><span class="n"><span class="pre">int64_t</span></span></a><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">TSIOBufferReaderRead</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="external-types.en.html#c.TSIOBufferReader" title="TSIOBufferReader"><span class="n"><span class="pre">TSIOBufferReader</span></span></a><span class="w"> </span><span class="n"><span class="pre">reader</span></span>, <span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="kt"><span class="pre">void</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">buf</span></span>, <a class="reference internal" href="external-types.en.html#c.int64_t" title="int64_t"><span class="n"><span class="pre">int64_t</span></span></a><span class="w"> </span><span class="n"><span class="pre">length</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.TSIOBufferReaderRead" title="Permalink to this definition">¶</a><br /></dt>
<dd></dd></dl>
<dl class="c function">
<dt class="sig sig-object c" id="c.TSIOBufferReaderIterate">
<span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">TSIOBufferReaderIterate</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="external-types.en.html#c.TSIOBufferReader" title="TSIOBufferReader"><span class="n"><span class="pre">TSIOBufferReader</span></span></a><span class="w"> </span><span class="n"><span class="pre">reader</span></span>, <a class="reference internal" href="#c.TSIOBufferBlockFunc" title="TSIOBufferBlockFunc"><span class="n"><span class="pre">TSIOBufferBlockFunc</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">func</span></span>, <span class="kt"><span class="pre">void</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">context</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.TSIOBufferReaderIterate" title="Permalink to this definition">¶</a><br /></dt>
<dd></dd></dl>
<dl class="c type">
<dt class="sig sig-object c" id="c.TSIOBufferBlockFunc">
<span class="k"><span class="pre">type</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">TSIOBufferBlockFunc</span></span></span><a class="headerlink" href="#c.TSIOBufferBlockFunc" title="Permalink to this definition">¶</a><br /></dt>
<dd><p><code class="docutils literal notranslate"><span class="pre">int</span> <span class="pre">(*TSIOBufferBlockFunc)(void</span> <span class="pre">const*</span> <span class="pre">data,</span> <span class="pre">int64_t</span> <span class="pre">nbytes,</span> <span class="pre">void*</span> <span class="pre">context)</span></code></p>
<p><em>data</em> is the data in the <a class="reference internal" href="external-types.en.html#c.TSIOBufferBlock" title="TSIOBufferBlock"><code class="xref c c-type docutils literal notranslate"><span class="pre">TSIOBufferBlock</span></code></a> and is <em>nbytes</em> long. <em>context</em> is
opaque data provided to the API call along with this function and passed on to the function. This
function should return <code class="docutils literal notranslate"><span class="pre">true</span></code> to continue iteration or <code class="docutils literal notranslate"><span class="pre">false</span></code> to terminate iteration.</p>
</dd></dl>
</section>
<section id="id4">
<h3>Description<a class="headerlink" href="#id4" title="Permalink to this headline">¶</a></h3>
<p><a class="reference internal" href="external-types.en.html#c.TSIOBufferReader" title="TSIOBufferReader"><code class="xref c c-type docutils literal notranslate"><span class="pre">TSIOBufferReader</span></code></a> is an read accessor for <a class="reference internal" href="external-types.en.html#c.TSIOBuffer" title="TSIOBuffer"><code class="xref c c-type docutils literal notranslate"><span class="pre">TSIOBuffer</span></code></a>. It represents a location in
the contents of the buffer. A buffer can have multiple readers and each reader consumes data in the
buffer independently. Data which for which there are no readers is discarded from the buffer. This
has two very important consequences –</p>
<ul class="simple">
<li><dl class="simple">
<dt>Data for which there are no readers and no writer will be discarded. In effect this means without</dt><dd><p>any readers only the current write buffer block will be maintained, older buffer blocks will
disappear.</p>
</dd>
</dl>
</li>
<li><p>Conversely keeping a reader around unused will pin the buffer data in memory. This can be useful or harmful.</p></li>
</ul>
<p>A buffer has a fixed amount of possible readers (currently 5) which is determined at compile
time. Reader allocation is fast and cheap until this maxium is reached at which point it fails.</p>
<dl class="simple">
<dt><a class="reference internal" href="#c.TSIOBufferReaderAlloc" title="TSIOBufferReaderAlloc"><code class="xref c c-func docutils literal notranslate"><span class="pre">TSIOBufferReaderAlloc()</span></code></a> allocates a reader for the IO buffer <em>bufp</em>. This should only be</dt><dd><p>called on a newly allocated buffer. If not the location of the reader in the buffer will be
indeterminate. Use <a class="reference internal" href="#c.TSIOBufferReaderClone" title="TSIOBufferReaderClone"><code class="xref c c-func docutils literal notranslate"><span class="pre">TSIOBufferReaderClone()</span></code></a> to get another reader if the buffer is
already in use.</p>
</dd>
</dl>
<p><a class="reference internal" href="#c.TSIOBufferReaderClone" title="TSIOBufferReaderClone"><code class="xref c c-func docutils literal notranslate"><span class="pre">TSIOBufferReaderClone()</span></code></a> allocates a reader and sets its position in the buffer to be the same as <em>reader</em>.</p>
<dl class="simple">
<dt><a class="reference internal" href="#c.TSIOBufferReaderFree" title="TSIOBufferReaderFree"><code class="xref c c-func docutils literal notranslate"><span class="pre">TSIOBufferReaderFree()</span></code></a> de-allocates the reader. Any data referenced only by this reader is</dt><dd><p>discarded from the buffer.</p>
</dd>
<dt><a class="reference internal" href="#c.TSIOBufferReaderConsume" title="TSIOBufferReaderConsume"><code class="xref c c-func docutils literal notranslate"><span class="pre">TSIOBufferReaderConsume()</span></code></a> advances the position of <em>reader</em> in its IO buffer by the</dt><dd><p>the smaller of <em>nbytes</em> and the maximum available in the buffer.</p>
</dd>
</dl>
<p><a class="reference internal" href="#c.TSIOBufferReaderStart" title="TSIOBufferReaderStart"><code class="xref c c-func docutils literal notranslate"><span class="pre">TSIOBufferReaderStart()</span></code></a> returns the IO buffer block containing the position of
<em>reader</em>.</p>
<blockquote>
<div><div class="admonition note">
<p class="admonition-title">Note</p>
<p>The byte at the position of <em>reader</em> is in the block but is not necessarily the first byte of the block.</p>
</div>
</div></blockquote>
<dl class="simple">
<dt><a class="reference internal" href="#c.TSIOBufferReaderAvail" title="TSIOBufferReaderAvail"><code class="xref c c-func docutils literal notranslate"><span class="pre">TSIOBufferReaderAvail()</span></code></a> returns the number of bytes which <em>reader</em> could consume. That is</dt><dd><p>the number of bytes in the IO buffer starting at the current position of <em>reader</em>.</p>
</dd>
<dt><a class="reference internal" href="#c.TSIOBufferReaderIsAvailAtLeast" title="TSIOBufferReaderIsAvailAtLeast"><code class="xref c c-func docutils literal notranslate"><span class="pre">TSIOBufferReaderIsAvailAtLeast()</span></code></a> return <code class="docutils literal notranslate"><span class="pre">true</span></code> if the available number of bytes for</dt><dd><p><em>reader</em> is at least <em>nbytes</em>, <code class="docutils literal notranslate"><span class="pre">false</span></code> if not. This can be more efficient than
<a class="reference internal" href="#c.TSIOBufferReaderAvail" title="TSIOBufferReaderAvail"><code class="xref c c-func docutils literal notranslate"><span class="pre">TSIOBufferReaderAvail()</span></code></a> because the latter must walk all the IO buffer blocks in the IO
buffer. This function returns as soon as the return value can be determined. In particular a
value of <code class="docutils literal notranslate"><span class="pre">1</span></code> for <em>nbytes</em> means only the first buffer block will be checked.</p>
</dd>
<dt><a class="reference internal" href="#c.TSIOBufferReaderRead" title="TSIOBufferReaderRead"><code class="xref c c-func docutils literal notranslate"><span class="pre">TSIOBufferReaderRead()</span></code></a> reads data from <em>reader</em>. This first copies data from the IO</dt><dd><p>buffer for <em>reader</em> to the target buffer <em>bufp</em>, starting at <em>reader`s
position, and then advances (as with :func:`TSIOBufferReaderConsume</em>) <em>reader`s
position past the copied data. The amount of data read in this fashion is the smaller of the
amount of data available in the IO buffer for :arg:`reader</em> and the size of the target buffer
(<em>length</em>).</p>
</dd>
</dl>
<p><a class="reference internal" href="#c.TSIOBufferReaderIterate" title="TSIOBufferReaderIterate"><code class="xref c c-func docutils literal notranslate"><span class="pre">TSIOBufferReaderIterate()</span></code></a> iterates over the blocks for <em>reader</em>. For each block
<em>func</em> is called with with the data for the block and <em>context</em>. The <em>context</em> is an
opaque type to this function and is passed unchanged to <em>func</em>. It is intended to be used as
context for <em>func</em>. If <em>func</em> returns <code class="docutils literal notranslate"><span class="pre">false</span></code> the iteration terminates. If <em>func</em>
returns true the block is consumed. The return value for <a class="reference internal" href="#c.TSIOBufferReaderIterate" title="TSIOBufferReaderIterate"><code class="xref c c-func docutils literal notranslate"><span class="pre">TSIOBufferReaderIterate()</span></code></a> is the
return value from the last call to <em>func</em>.</p>
<blockquote>
<div><div class="admonition note">
<p class="admonition-title">Note</p>
<p>If it would be a problem for the iteration to consume the data (especially in cases where
<code class="docutils literal notranslate"><span class="pre">false</span></code> might be returned) the reader can be cloned via <a class="reference internal" href="#c.TSIOBufferReaderClone" title="TSIOBufferReaderClone"><code class="xref c c-func docutils literal notranslate"><span class="pre">TSIOBufferReaderClone()</span></code></a> to
keep the data in the IO buffer and available. If not needed the reader can be destroyed or
if needed the original reader can be destroyed and replaced by the clone.</p>
</div>
</div></blockquote>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Destroying a <a class="reference internal" href="external-types.en.html#c.TSIOBuffer" title="TSIOBuffer"><code class="xref c c-type docutils literal notranslate"><span class="pre">TSIOBuffer</span></code></a> will de-allocate and destroy all readers for that buffer.</p>
</div>
</section>
<section id="id5">
<h3>See also<a class="headerlink" href="#id5" title="Permalink to this headline">¶</a></h3>
<p><em class="manpage">TSIOBufferCreate(3ts)</em></p>
</section>
</section>
</section>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<p class="logo"><a href="index.html">
<img class="logo" src="_static/balcora-gate-400x400.jpg" alt="Logo"/>
</a></p>
<h3><a href="index.html">Table of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">Body Factory Refactoring</a><ul>
<li><a class="reference internal" href="#implementation">Implementation</a></li>
<li><a class="reference internal" href="#further-work">Further Work</a></li>
<li><a class="reference internal" href="#documentation">Documentation</a></li>
<li><a class="reference internal" href="#tshttptxnapplylogformat">TSHttpTxnApplyLogFormat</a><ul>
<li><a class="reference internal" href="#synopsis">Synopsis</a></li>
<li><a class="reference internal" href="#description">Description</a></li>
<li><a class="reference internal" href="#see-also">See also</a></li>
</ul>
</li>
<li><a class="reference internal" href="#tshttptxnerrorbodyset">TSHttpTxnErrorBodySet</a><ul>
<li><a class="reference internal" href="#id1">Synopsis</a></li>
<li><a class="reference internal" href="#id2">Description</a></li>
</ul>
</li>
<li><a class="reference internal" href="#tsiobufferreader">TSIOBufferReader</a><ul>
<li><a class="reference internal" href="#id3">Synopsis</a></li>
<li><a class="reference internal" href="#id4">Description</a></li>
<li><a class="reference internal" href="#id5">See also</a></li>
</ul>
</li>
</ul>
</li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="errata.en.html"
title="previous chapter">Errata</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="l4r.en.html"
title="next chapter">Layer 4 Proxying</a></p>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/body-factory.en.rst.txt"
rel="nofollow">Show Source</a></li>
</ul>
</div>
<div id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
<input type="submit" value="Go" />
</form>
</div>
</div>
<script>$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="l4r.en.html" title="Layer 4 Proxying"
>next</a> |</li>
<li class="right" >
<a href="errata.en.html" title="Errata"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">SWOC Docs</a> »</li>
<li class="nav-item nav-item-1"><a href="ats-projects.en.html" >Traffic Server Projects</a> »</li>
<li class="nav-item nav-item-this"><a href="">Body Factory Refactoring</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
© Copyright 2017, amc@apache.org.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 4.1.2.
</div>
</body>
</html>