void conn_add_data(struct connection *conn, uint8_t *data, int n, struct buf_ptr *start, struct buf_ptr *end) { struct mhdr *queue = &conn->info->local_data; struct context *ctx = conn->ctx; struct mbuf *buf = mbuf_queue_get(ctx, queue); int remain = n, wlen, size, len = 0; if (remain > 0 && start != NULL) { start->pos = buf->last; start->buf = buf; } while (remain > 0) { wlen = mbuf_write_size(buf); size = remain < wlen ? remain : wlen; memcpy(buf->last, data + len, size); buf->last += size; len += size; remain -= size; if (remain <= 0 && end != NULL) { end->pos = buf->last; end->buf = buf; } if (wlen - size <= 0) { buf = mbuf_queue_get(ctx, queue); } } }
void mbuf_queue_copy(struct context *ctx, struct mhdr *q, uint8_t *data, int n) { struct mbuf *buf = mbuf_queue_get(ctx, q); int remain = n, wlen, size, len = 0; while (remain > 0) { wlen = mbuf_write_size(buf); size = remain < wlen ? remain : wlen; memcpy(buf->last, data + len, size); buf->last += size; len += size; remain -= size; if (wlen - size <= 0) { buf = mbuf_queue_get(ctx, q); } } }