Skip to content

Commit 1dd1b34

Browse files
committed
libunit-wasm: Add a luw_req_buf_copy() function
This is analogous to luw_req_buf_append() but rather than appending request data to the buffer it simply overwrites what's currently there. This is needed to take advantage of the new ability to receive >4GiB requests/payloads. On a new request you would call luw_init_ctx(), luw_set_req_buf() & open(2). On subsequent calls to the request_handler (for this same HTTP request/upload) you would call this new function and then write out the data to a file. E.g /* In the request_handler */ if (total_bytes_wrote == 0) { luw_init_ctx(&ctx, addr, 0); luw_set_req_buf(&ctx, &request_buf, LUW_SRB_NONE); fd = open("/var/tmp/large-file.dat", O_CREAT|O_TRUNC|O_WRONLY, 0666); } else { luw_req_buf_copy(&ctx, addr); } buf = luw_get_http_content(&ctx); bytes_wrote = write(fd, buf, luw_get_http_content_sent(&ctx)); total_bytes_wrote += bytes_wrote; if (total_bytes_wrote == luw_get_http_content_len(&ctx)) { close(fd); total_bytes_wrote = 0; luw_http_response_end(); } Signed-off-by: Andrew Clayton <[email protected]>
1 parent 263541e commit 1dd1b34

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/c/include/unit/unit-wasm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ extern size_t luw_get_response_data_size(const luw_ctx_t *ctx);
238238
extern int luw_mem_writep(luw_ctx_t *ctx, const char *fmt, ...);
239239
extern size_t luw_mem_writep_data(luw_ctx_t *ctx, const u8 *src, size_t size);
240240
extern void luw_req_buf_append(luw_ctx_t *ctx, const u8 *src);
241+
extern void luw_req_buf_copy(luw_ctx_t *ctx, const u8 *src);
241242
extern size_t luw_mem_fill_buf_from_req(luw_ctx_t *ctx, size_t from);
242243
extern void luw_mem_reset(luw_ctx_t *ctx);
243244
extern void luw_http_set_response_status(luw_http_status_t status);

src/c/libunit-wasm.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,17 @@ void luw_req_buf_append(luw_ctx_t *ctx, const u8 *src)
304304
ctx->req->total_content_sent = req->total_content_sent;
305305
}
306306

307+
/* Copy data from the request to the previously setup request_buffer. */
308+
void luw_req_buf_copy(luw_ctx_t *ctx, const u8 *src)
309+
{
310+
struct luw_req *req = (struct luw_req *)src;
311+
312+
memcpy(ctx->reqp + ctx->req->content_off, src + req->content_off,
313+
req->request_size);
314+
ctx->req->content_sent = req->content_sent;
315+
ctx->req->total_content_sent = req->total_content_sent;
316+
}
317+
307318
/*
308319
* Convenience function to fill the response buffer with data from
309320
* the request buffer.

0 commit comments

Comments
 (0)