25 lines
752 B
C
25 lines
752 B
C
#include <string.h>
|
|
|
|
#include "lnm/http/loop.h"
|
|
#include "lnm/loop.h"
|
|
|
|
lnm_http_step_err lnm_http_loop_step_body_to_buf(lnm_http_conn *conn) {
|
|
lnm_http_loop_ctx *ctx = conn->ctx;
|
|
|
|
if (ctx->req.body.buf == NULL) {
|
|
ctx->req.body.buf = malloc(ctx->req.body.expected_len * sizeof(char));
|
|
ctx->req.body.len = 0;
|
|
}
|
|
|
|
size_t to_read = LNM_MIN(conn->r.size - conn->r.read,
|
|
ctx->req.body.expected_len - ctx->req.body.len);
|
|
memcpy(&ctx->req.body.buf[ctx->req.body.len], &conn->r.buf[conn->r.read],
|
|
to_read);
|
|
ctx->req.body.len += to_read;
|
|
conn->r.read += to_read;
|
|
|
|
return ctx->req.body.len == ctx->req.body.expected_len
|
|
? lnm_http_step_err_done
|
|
: lnm_http_step_err_io_needed;
|
|
}
|