void HdrHeap::attach_block(IOBufferBlock* b, const char* use_start) Attaches data from an IOBuffer block to as a read-only string heap. Looks through existing to expand an existing string heap entry if necessary Because the block may contain data at the front of it that we don't want (and will end up getting marshalled) use_start specificies where we start using the block (INKqa07409)
| 165 | // use_start specificies where we start using the block (INKqa07409) |
| 166 | // |
| 167 | int |
| 168 | HdrHeap::attach_block(IOBufferBlock *b, const char *use_start) |
| 169 | { |
| 170 | ink_assert(m_writeable); |
| 171 | |
| 172 | RETRY: |
| 173 | |
| 174 | // It's my contention that since heaps are add to the first available slot, one you find an empty |
| 175 | // slot it's not possible that a heap ptr for this block exists in a later slot |
| 176 | |
| 177 | for (auto &heap : m_ronly_heap) { |
| 178 | if (heap.m_heap_start == nullptr) { |
| 179 | // Add block to heap in this slot |
| 180 | heap.m_heap_start = static_cast<char const *>(use_start); |
| 181 | heap.m_heap_len = static_cast<int>(b->end() - b->start()); |
| 182 | heap.m_ref_count_ptr = b->data.object(); |
| 183 | // printf("Attaching block at %X for %d in slot %d\n", |
| 184 | // m_ronly_heap[i].m_heap_start, |
| 185 | // m_ronly_heap[i].m_heap_len, |
| 186 | // i); |
| 187 | return &heap - m_ronly_heap; |
| 188 | } else if (heap.m_heap_start == b->buf()) { |
| 189 | // This block is already on the heap so just extend |
| 190 | // it's range |
| 191 | heap.m_heap_len = static_cast<int>(b->end() - b->buf()); |
| 192 | // printf("Extending block at %X to %d in slot %d\n", |
| 193 | // m_ronly_heap[i].m_heap_start, |
| 194 | // m_ronly_heap[i].m_heap_len, |
| 195 | // i); |
| 196 | return &heap - m_ronly_heap; |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | // We didn't find an open block slot so we'll have to create one |
| 201 | coalesce_str_heaps(); |
| 202 | goto RETRY; |
| 203 | } |