summaryrefslogtreecommitdiffhomepage
path: root/examples (follow)
AgeCommit message (Collapse)AuthorFilesLines
2023-10-17examples/rust: Do some simplification around unsafe {} blocksAndrew Clayton3-26/+18
We can put the unsafe keyword as part of the function definition, getting rid of the unsafe {} blocks in the functions themselves. Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2023-10-17examples/rust: Further simplify hello-worldAndrew Clayton1-4/+0
In this example we don't need the request buf. Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2023-10-11examples/c: Remove a duplicate word from large-upload.cAndrew Clayton1-1/+1
Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2023-09-25examples: Add C and Rust examples of handling large uploadsAndrew Clayton5-2/+159
The programs demonstrate handling requests with payloads larger than 4GiB which means they need to be written out to disk and so also demonstrates the use of the file-system access mechanism. Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2023-09-25examples/rust: Amend upload-reflector for recent changesAndrew Clayton1-1/+2
The previous commit changed uwr_get_http_content_len() to return a u64 to allow for uploads larger than 4GiB, which now means this generates compiler errors about type mismatches, expected usize got u64. Cast the return value of uwr_get_http_content_len() to usize to match that of TOTAL_RESPONSE_SENT. (Making TOTAL_RESPONSE_SENT a u64 creates a larger trail of problems). Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2023-09-25libunit-wasm: Allow uploads larger than 4GiBAndrew Clayton1-1/+1
Currently Wasm modules are limited to a 32bit address space (until at least the memory64 work is completed). All the counters etc in the request structure were u32's. Which matched with the 32bit memory limitation. However there is really no need to not allow >4GiB uploads that can be saved off to disk or some such. To do this we need to increase the ->content_len & ->total_content_sent members to u64's and also adjust the return types of (luw,uwr}_get_http_content_len() and {luw,uwr}_get_http_total_content_sent() similarly. However because we need the request structure to have the exact same layout on 32bit (for Wasm modules) as it does on 64bit we need to re-jig the order of some of these members and add a four-byte padding member. Thus the request structure now looks like on 32bit (as shown by pahole(1)) struct luw_req { u32 method_off; /* 0 4 */ u32 method_len; /* 4 4 */ u32 version_off; /* 8 4 */ u32 version_len; /* 12 4 */ u32 path_off; /* 16 4 */ u32 path_len; /* 20 4 */ u32 query_off; /* 24 4 */ u32 query_len; /* 28 4 */ u32 remote_off; /* 32 4 */ u32 remote_len; /* 36 4 */ u32 local_addr_off; /* 40 4 */ u32 local_addr_len; /* 44 4 */ u32 local_port_off; /* 48 4 */ u32 local_port_len; /* 52 4 */ u32 server_name_off; /* 56 4 */ u32 server_name_len; /* 60 4 */ /* --- cacheline 1 boundary (64 bytes) --- */ u64 content_len; /* 64 8 */ u64 total_content_sent; /* 72 8 */ u32 content_sent; /* 80 4 */ u32 content_off; /* 84 4 */ u32 request_size; /* 88 4 */ u32 nr_fields; /* 92 4 */ u32 tls; /* 96 4 */ char __pad[4]; /* 100 4 */ struct luw_hdr_field fields[]; /* 104 0 */ /* size: 104, cachelines: 2, members: 25 */ /* last cacheline: 40 bytes */ }; and the same structure (taken from Unit) compiled as 64bit struct nxt_wasm_request_s { uint32_t method_off; /* 0 4 */ uint32_t method_len; /* 4 4 */ uint32_t version_off; /* 8 4 */ uint32_t version_len; /* 12 4 */ uint32_t path_off; /* 16 4 */ uint32_t path_len; /* 20 4 */ uint32_t query_off; /* 24 4 */ uint32_t query_len; /* 28 4 */ uint32_t remote_off; /* 32 4 */ uint32_t remote_len; /* 36 4 */ uint32_t local_addr_off; /* 40 4 */ uint32_t local_addr_len; /* 44 4 */ uint32_t local_port_off; /* 48 4 */ uint32_t local_port_len; /* 52 4 */ uint32_t server_name_off; /* 56 4 */ uint32_t server_name_len; /* 60 4 */ /* --- cacheline 1 boundary (64 bytes) --- */ uint64_t content_len; /* 64 8 */ uint64_t total_content_sent; /* 72 8 */ uint32_t content_sent; /* 80 4 */ uint32_t content_off; /* 84 4 */ uint32_t request_size; /* 88 4 */ uint32_t nfields; /* 92 4 */ uint32_t tls; /* 96 4 */ char __pad[4]; /* 100 4 */ nxt_wasm_http_field_t fields[]; /* 104 0 */ /* size: 104, cachelines: 2, members: 25 */ /* last cacheline: 40 bytes */ }; We can see the structures have the same layout, same size and no padding. We need the __pad member as otherwise I saw gcc and clang on Alpine Linux automatically add the 'packed' attribute to the structure which made the two structures not match. Link: <https://github.com/WebAssembly/memory64> Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2023-09-05examples/rust: Slightly simplify hello-worldAndrew Clayton1-4/+3
There is no need in this case to declare REQUEST_BUF as a global variable. Declaring it local to uwr_request_handler() lets us get rid of the unsafe code blocks. Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2023-08-30unit-wasm 0.2.0v0.2.0Andrew Clayton3-3/+3
Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2023-08-30examples/rust: Update for new API additionsAndrew Clayton2-7/+3
Update the echo-request and upload-reflector examples for the new uwr_http_add_header_content_type() and uwr_http_add_header_content_len() functions. Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2023-08-29examples/rust: Reduce the scope of an unsafe block in echo-requestAndrew Clayton1-3/+1
Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2023-08-29examples/rust: Fix building of the hello world demoAndrew Clayton1-2/+2
When I renamed it from minimal to hello-world, it stopped being built due to the make target name being the same as the directory name (hello-world). Rename the make target to rust-hello-world which also matches the naming of the rest of the targets. Fixes: 656c036 ("examples/rust: Add a minimal hello world rust example") Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2023-08-29examples/rust: Add a minimal hello world rust exampleAndrew Clayton3-3/+60
This is about the smallest it can be. Its Unit application config would look like "applications": { "rust-hello-world": { "type": "wasm", "module": "/path/to/unit-wasm/examples/rust/hello-world/target/wasm32-wasi/debug/rust_hello_world.wasm", "request_handler": "uwr_request_handler", "malloc_handler": "luw_malloc_handler", "free_handler": "luw_free_handler" } } Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2023-08-28examples/rust: Update unit-wasm dependency versionAndrew Clayton2-2/+2
luw_http_add_header() no longer takes an idx argument. Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2023-08-28libunit-wasm: Remove the idx argument from luw_http_add_header()Andrew Clayton4-8/+6
This was used to specify the index of the response header being added, starting at 0 and incrementing by one for each header. Instead of having the programmer specify this, track it internally. We add an extra check in luw_http_add_header() to make sure we aren't trying to add more headers than we said with luw_http_init_headers(), if we are, simply return. This updates the API-C.md and the various examples and 'rusty' API wrapper. Suggested-by: Liam Crilly <liam@nginx.com> Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2023-08-28Revert "Adding echo Request with body Parsing"Andrew Clayton3-203/+0
This reverts commit 011c3ba3f7bc466a04101f81d4f6186001b7aad4. This was committed in error... Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2023-08-28Adding echo Request with body ParsingTimo Stark3-0/+203
2023-08-26examples/rust: Update unit-wasm dependency versionAndrew Clayton2-2/+2
This is for the new 'rusty' API. Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2023-08-26examples/rust: Bump the versionsAndrew Clayton2-2/+2
Seeing as these are now using the 'rusty' API bump their versions to 0.2.0 Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2023-08-25Rust: Port the Rust Wasm demos to the new 'rusty' wrappersAndrew Clayton2-239/+137
rusty is a thin wrapper over the generated libunit-wasm bindings to provide a more native rust like interface. This gets rid of all the casting and ugly string handling. It massively reduces the amount of unsafe {} blocks needed, though some still are... All in all this provides a nice code cleanup. Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2023-08-21Initial commitv0.1.0Andrew Clayton18-0/+1325
libunit-wasm and example C and Rust WebAssembly modules for NGINX Unit. Co-developed-by: Timo Stark <t.stark@nginx.com> Co-developed-by: Liam Crilly <liam@nginx.com> Signed-off-by: Andrew Clayton <a.clayton@nginx.com>