diff options
author | Andrew Clayton <a.clayton@nginx.com> | 2023-12-01 21:02:48 +0000 |
---|---|---|
committer | Andrew Clayton <a.clayton@nginx.com> | 2023-12-01 21:06:47 +0000 |
commit | 838509e0cd56a4ca81746163816c2005b3770b68 (patch) | |
tree | 0b16e3e1f5b709c3f3b00bf14fb2e0190dee2510 /c/wasi-http | |
parent | 76a6880605195d253dd4837204a252816bd5a396 (diff) | |
download | project_blackbird-838509e0cd56a4ca81746163816c2005b3770b68.tar.gz project_blackbird-838509e0cd56a4ca81746163816c2005b3770b68.tar.bz2 |
wasi-http/echo-request: Simplify a little
Use the 'blocking' versions of the stream read/write functions.
Things seemed to work fine previously. However with a version of this
that works under the enw Unit wasm module, it didn't and I needed to use
the _input_stream_blocking_read() &
_output_stream_blocking_write_and_flush() functions.
The latter does also allow for a little less code. Let's also use those
functions here...
Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
Diffstat (limited to 'c/wasi-http')
-rw-r--r-- | c/wasi-http/echo-request/component.c | 24 |
1 files changed, 9 insertions, 15 deletions
diff --git a/c/wasi-http/echo-request/component.c b/c/wasi-http/echo-request/component.c index cecf390..fde450a 100644 --- a/c/wasi-http/echo-request/component.c +++ b/c/wasi-http/echo-request/component.c @@ -62,7 +62,6 @@ void exports_wasi_http_incoming_handler_handle( wasi_io_streams_borrow_output_stream_t b_out_stream; wasi_io_streams_list_u8_t stream_data; wasi_io_streams_stream_error_t stream_err; - wasi_http_types_error_code_t http_err; wasi_http_types_header_error_t hdr_err; wasi_http_types_field_key_t key; wasi_http_types_field_value_t value; @@ -114,10 +113,10 @@ void exports_wasi_http_incoming_handler_handle( ex("wasi_http_types_method_incoming_body_stream() failed\n"); b_in_stream = wasi_io_streams_borrow_input_stream(in_stream); - ok = wasi_io_streams_method_input_stream_read(b_in_stream, - 8 * 1024*1024, - &data, - &in_stream_err); + ok = wasi_io_streams_method_input_stream_blocking_read(b_in_stream, + 8 * 1024*1024, + &data, + &in_stream_err); if (method.tag == WASI_HTTP_TYPES_METHOD_POST || method.tag == WASI_HTTP_TYPES_METHOD_PUT) { @@ -155,19 +154,14 @@ void exports_wasi_http_incoming_handler_handle( stream_data.len = size; stream_data.ptr = (uint8_t *)out_ptr; - ok = wasi_io_streams_method_output_stream_write(b_out_stream, - &stream_data, - &stream_err); + ok = wasi_io_streams_method_output_stream_blocking_write_and_flush( + b_out_stream, + &stream_data, + &stream_err); if (!ok) - ex("wasi_io_streams_method_output_stream_write() failed\n"); + ex("wasi_io_streams_method_output_stream_blocking_write_and_flush() failed\n"); free(out_ptr); wasi_http_types_static_response_outparam_set(response_out, &rerr); - - wasi_io_streams_output_stream_drop_borrow(out_stream); - - ok = wasi_http_types_static_outgoing_body_finish(body, NULL, &http_err); - if (!ok) - ex("wasi_http_types_static_outgoing_body_finish() failed\n"); } |