3
A brief file description
5
@section license License
7
Licensed to the Apache Software Foundation (ASF) under one
8
or more contributor license agreements. See the NOTICE file
9
distributed with this work for additional information
10
regarding copyright ownership. The ASF licenses this file
11
to you under the Apache License, Version 2.0 (the
12
"License"); you may not use this file except in compliance
13
with the License. You may obtain a copy of the License at
15
http://www.apache.org/licenses/LICENSE-2.0
17
Unless required by applicable law or agreed to in writing, software
18
distributed under the License is distributed on an "AS IS" BASIS,
19
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
See the License for the specific language governing permissions and
21
limitations under the License.
24
#include "ink_unused.h" /* MAGIC_EDITING_TAG */
25
/**************************************************************************
28
**************************************************************************/
30
#include "P_EventSystem.h"
33
// General Buffer Allocator
35
inkcoreapi Allocator ioBufAllocator[DEFAULT_BUFFER_SIZES];
36
inkcoreapi ClassAllocator<MIOBuffer> ioAllocator("ioAllocator", DEFAULT_BUFFER_NUMBER);
37
inkcoreapi ClassAllocator<IOBufferData> ioDataAllocator("ioDataAllocator", DEFAULT_BUFFER_NUMBER);
38
inkcoreapi ClassAllocator<IOBufferBlock> ioBlockAllocator("ioBlockAllocator", DEFAULT_BUFFER_NUMBER);
39
int64_t default_large_iobuffer_size = DEFAULT_LARGE_BUFFER_SIZE;
40
int64_t default_small_iobuffer_size = DEFAULT_SMALL_BUFFER_SIZE;
41
int64_t max_iobuffer_size = DEFAULT_BUFFER_SIZES - 1;
47
init_buffer_allocators()
51
for (int i = 0; i < DEFAULT_BUFFER_SIZES; i++) {
52
int64_t s = DEFAULT_BUFFER_BASE_SIZE * (((int64_t)1) << i);
53
int64_t a = DEFAULT_BUFFER_ALIGNMENT;
54
int n = i <= default_large_iobuffer_size ? DEFAULT_BUFFER_NUMBER : DEFAULT_HUGE_BUFFER_NUMBER;
58
name = NEW(new char[64]);
59
snprintf(name, 64, "ioBufAllocator[%d]", i);
60
ioBufAllocator[i].re_init(name, s, n, a);
65
MIOBuffer::remove_append(IOBufferReader * r)
69
Ptr<IOBufferBlock> b = r->block;
70
r->block = r->block->next;
71
b->_start += r->start_offset;
72
if (b->start() >= b->end()) {
73
r->start_offset = -r->start_offset;
80
r->mbuf->_writer = NULL;
85
MIOBuffer::write(const void *abuf, int64_t alen)
87
const char *buf = (const char*)abuf;
92
int64_t f = _writer->write_avail();
93
f = f < len ? f : len;
95
::memcpy(_writer->end(), buf, f);
104
_writer = _writer->next;
111
#ifdef WRITE_AND_TRANSFER
113
* Same functionality as write but for the one small difference.
114
* The space available in the last block is taken from the original
115
* and this space becomes available to the copy.
119
MIOBuffer::write_and_transfer_left_over_space(IOBufferReader * r, int64_t alen, int64_t offset)
121
int64_t rval = write(r, alen, offset);
122
// reset the end markers of the original so that it cannot
123
// make use of the space in the current block
124
if (r->mbuf->_writer)
125
r->mbuf->_writer->_buf_end = r->mbuf->_writer->_end;
126
// reset the end marker of the clone so that it can make
127
// use of the space in the current block
129
_writer->_buf_end = _writer->data->data() + _writer->block_size();
138
MIOBuffer::write(IOBufferReader * r, int64_t alen, int64_t offset)
141
IOBufferBlock *b = r->block;
142
offset += r->start_offset;
144
while (b && len > 0) {
145
int64_t max_bytes = b->read_avail();
147
if (max_bytes <= 0) {
153
if (len<0 || len>= max_bytes)
157
IOBufferBlock *bb = b->clone();
158
bb->_start += offset;
159
bb->_buf_end = bb->_end = bb->_start + bytes;
169
MIOBuffer::puts(char *s, int64_t len)
173
while (pc < buf_end()) {
176
if (!*pb || *pb == '\n') {
177
int64_t n = (int64_t) (pb - s);
178
memcpy(end(), s, n + 1); // Upto and including '\n'
190
IOBufferReader::read(void *ab, int64_t len)
193
int64_t max_bytes = read_avail();
194
int64_t bytes = len <= max_bytes ? len : max_bytes;
198
int64_t l = block_read_avail();
201
::memcpy(b, start(), l);
210
IOBufferReader::memchr(char c, int64_t len, int64_t offset)
212
IOBufferBlock *b = block;
213
offset += start_offset;
217
int64_t max_bytes = b->read_avail();
219
if (max_bytes <= 0) {
225
if (len<0 || len>= max_bytes)
229
char *s = b->start() + offset;
230
char *p = (char *) ink_memchr(s, c, bytes);
232
return (int64_t) (o - start_offset + p - s);
243
IOBufferReader::memcpy(const void *ap, int64_t len, int64_t offset)
246
IOBufferBlock *b = block;
247
offset += start_offset;
250
int64_t max_bytes = b->read_avail();
252
if (max_bytes <= 0) {
258
if (len<0 || len>= max_bytes)
262
::memcpy(p, b->start() + offset, bytes);