/* XXX 4 bytes unused */
/* Blocks representing the HTTP message itself */
- struct htx_blk blocks[0] __attribute__((aligned(8)));
+ char blocks[0] __attribute__((aligned(8)));
};
}
/* Converts a position to the corresponding relative address */
-static inline uint32_t htx_pos_to_idx(const struct htx *htx, uint32_t pos)
+static inline uint32_t htx_pos_to_addr(const struct htx *htx, uint32_t pos)
{
- return ((htx->size / sizeof(htx->blocks[0])) - pos - 1);
+ return htx->size - (pos + 1) * sizeof(struct htx_blk);
}
/* Returns the position of the block <blk>. It is the caller responsibility to
* be sure <blk> is part of <htx>. */
static inline uint32_t htx_get_blk_pos(const struct htx *htx, const struct htx_blk *blk)
{
- return (htx->blocks + (htx->size / sizeof(htx->blocks[0])) - blk - 1);
+ return ((htx->blocks + htx->size - (char *)blk) / sizeof(struct htx_blk) - 1);
}
/* Returns the block at the position <pos>. It is the caller responsibility to
* be sure the block at the position <pos> exists. */
static inline struct htx_blk *htx_get_blk(const struct htx *htx, uint32_t pos)
{
- return ((struct htx_blk *)(htx->blocks) + htx_pos_to_idx(htx, pos));
+ return (struct htx_blk *)(htx->blocks + htx_pos_to_addr(htx, pos));
}
/* Returns the type of the block <blk> */
if (htx->tail == -1)
return 0;
- return ((htx->tail + 1 - htx->head) * sizeof(htx->blocks[0]));
+ return ((htx->tail + 1 - htx->head) * sizeof(struct htx_blk));
}
/* Returns the space used (payload + metadata) in <htx> */
{
uint32_t free = htx_free_space(htx);
- if (free < sizeof(htx->blocks[0]))
+ if (free < sizeof(struct htx_blk))
return 0;
- return (free - sizeof(htx->blocks[0]));
+ return (free - sizeof(struct htx_blk));
}
/* Returns the maximum size for a block, not exceeding <max> bytes. <max> may be
if (max != -1 && free > max)
free = max;
- if (free < sizeof(htx->blocks[0]))
+ if (free < sizeof(struct htx_blk))
return 0;
- return (free - sizeof(htx->blocks[0]));
+ return (free - sizeof(struct htx_blk));
}
/* Returns 1 if the message has less than 1/4 of its capacity free, otherwise 0 */
* message.
*/
tail = htx->tail + 1;
- if (sizeof(htx->blocks[0]) * htx_pos_to_idx(htx, tail) >= htx->tail_addr)
+ if (htx_pos_to_addr(htx, tail) >= htx->tail_addr)
;
else if (htx->head > 0) {
htx_defrag_blks(htx);
tail = htx->tail + 1;
- BUG_ON(sizeof(htx->blocks[0]) * htx_pos_to_idx(htx, tail) < htx->tail_addr);
+ BUG_ON(htx_pos_to_addr(htx, tail) < htx->tail_addr);
}
else
goto defrag;
* used, the other one is never used again, until the next defrag.
*/
headroom = (htx->end_addr - htx->head_addr);
- tailroom = (!htx->head_addr
- ? sizeof(htx->blocks[0]) * htx_pos_to_idx(htx, tail) - htx->tail_addr
- : 0);
+ tailroom = (!htx->head_addr ? htx_pos_to_addr(htx, tail) - htx->tail_addr : 0);
BUG_ON((int32_t)headroom < 0);
BUG_ON((int32_t)tailroom < 0);
BUG_ON(htx->head == -1);
headroom = (htx->end_addr - htx->head_addr);
- tailroom = sizeof(htx->blocks[0]) * htx_pos_to_idx(htx, htx->tail) - htx->tail_addr;
+ tailroom = (htx_pos_to_addr(htx, htx->tail) - htx->tail_addr);
BUG_ON((int32_t)headroom < 0);
BUG_ON((int32_t)tailroom < 0);
* Same type and enough space: append data
*/
headroom = (htx->end_addr - htx->head_addr);
- tailroom = sizeof(htx->blocks[0]) * htx_pos_to_idx(htx, htx->tail) - htx->tail_addr;
+ tailroom = (htx_pos_to_addr(htx, htx->tail) - htx->tail_addr);
BUG_ON((int32_t)headroom < 0);
BUG_ON((int32_t)tailroom < 0);
if (!htx->head_addr) {
if (tailblk->addr+sz != htx->tail_addr)
goto add_new_block;
- room = sizeof(htx->blocks[0]) * htx_pos_to_idx(htx, htx->tail) - htx->tail_addr;
+ room = (htx_pos_to_addr(htx, htx->tail) - htx->tail_addr);
}
else {
if (tailblk->addr+sz != htx->head_addr)