Skip to content
This repository was archived by the owner on Feb 26, 2025. It is now read-only.

Commit fecce73

Browse files
authored
Merge pull request #62 from golemcloud/c-http-example-fixes
c-example-http fixes
2 parents 1668f29 + 7fe1b22 commit fecce73

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

examples/c/c-example-http/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.PHONY: build bindings compile clean
2+
13
build: compile
24
wasm-tools component new component_name.module.wasm -o component_name.wasm --adapt adapters/tier1/wasi_snapshot_preview1.wasm
35

@@ -9,4 +11,4 @@ compile: bindings
911

1012
clean:
1113
rm -rf component_name
12-
rm *.wasm
14+
rm -f *.wasm

examples/c/c-example-http/main.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ uint64_t exports_pack_name_api_get() {
2424
}
2525

2626

27-
void set_string(c_example_http_string_t* ret, const char* str) {
27+
void set_string(component_name_string_t* ret, const char* str) {
2828
ret->ptr = (uint8_t*)str;
2929
ret->len = strlen(str);
3030
}
@@ -36,13 +36,13 @@ void set_string_field(wasi_http_types_field_value_t* ret, const char* str) {
3636

3737
#define log(...) { fprintf (stderr, __VA_ARGS__); fflush(stderr); }
3838

39-
void exports_pack_name_api_send(c_example_http_string_t *ret) {
39+
void exports_pack_name_api_send(component_name_string_t *ret) {
4040
log("Setting up the outgoing request\n");
4141
// Setting up the outgoing request
4242
wasi_http_types_own_fields_t headers;
4343
wasi_http_types_header_error_t headers_err;
44-
c_example_http_list_tuple2_field_key_field_value_t entries;
45-
entries.ptr = malloc(2 * sizeof(c_example_http_tuple2_field_key_field_value_t));
44+
component_name_list_tuple2_field_key_field_value_t entries;
45+
entries.ptr = malloc(2 * sizeof(component_name_tuple2_field_key_field_value_t));
4646
entries.len = 2;
4747
set_string(&entries.ptr[0].f0, "Content-Type");
4848
set_string_field(&entries.ptr[0].f1, "application/json");
@@ -71,7 +71,7 @@ void exports_pack_name_api_send(c_example_http_string_t *ret) {
7171
return;
7272
}
7373

74-
c_example_http_string_t path;
74+
component_name_string_t path;
7575
set_string(&path, "/post");
7676
if (!wasi_http_types_method_outgoing_request_set_path_with_query(
7777
wasi_http_types_borrow_outgoing_request(request),
@@ -93,7 +93,7 @@ void exports_pack_name_api_send(c_example_http_string_t *ret) {
9393
return;
9494
}
9595

96-
c_example_http_string_t authority;
96+
component_name_string_t authority;
9797
set_string(&authority, "httpbin.org");
9898
if (!wasi_http_types_method_outgoing_request_set_authority(
9999
wasi_http_types_borrow_outgoing_request(request),
@@ -122,7 +122,7 @@ void exports_pack_name_api_send(c_example_http_string_t *ret) {
122122
log("Writing the outgoing request stream\n");
123123

124124
wasi_io_streams_stream_error_t stream_err;
125-
c_example_http_list_u8_t body_data;
125+
component_name_list_u8_t body_data;
126126
body_data.ptr = malloc(256);
127127
sprintf((char*)body_data.ptr, "{ \"count\": %llu }", total);
128128
body_data.len = strlen((char*)body_data.ptr);
@@ -231,7 +231,7 @@ void exports_pack_name_api_send(c_example_http_string_t *ret) {
231231
pollable_list.ptr = malloc(sizeof(wasi_io_poll_borrow_pollable_t));
232232
pollable_list.ptr[0] = wasi_io_poll_borrow_pollable(pollable);
233233

234-
c_example_http_list_u32_t poll_result;
234+
component_name_list_u32_t poll_result;
235235
wasi_io_poll_poll(&pollable_list, &poll_result);
236236
wasi_io_poll_pollable_drop_own(pollable);
237237
}
@@ -265,7 +265,7 @@ void exports_pack_name_api_send(c_example_http_string_t *ret) {
265265
uint64_t len = 0;
266266

267267
while (!eof) {
268-
c_example_http_list_u8_t chunk;
268+
component_name_list_u8_t chunk;
269269
wasi_io_streams_stream_error_t stream_err;
270270
if (wasi_io_streams_method_input_stream_blocking_read(wasi_io_streams_borrow_input_stream(incoming_body_stream), 1024, &chunk, &stream_err)) {
271271
len += chunk.len;

0 commit comments

Comments
 (0)