mirror of
https://github.com/bytecodealliance/wasm-micro-runtime.git
synced 2025-07-15 16:58:34 +00:00
import http sample
This commit is contained in:
parent
98bf69cf89
commit
8a27f5b064
188
product-mini/platforms/zephyr/simple-http/CMakeLists.txt
Normal file
188
product-mini/platforms/zephyr/simple-http/CMakeLists.txt
Normal file
|
@ -0,0 +1,188 @@
|
||||||
|
# Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||||
|
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||||
|
|
||||||
|
cmake_minimum_required(VERSION 3.8.2)
|
||||||
|
|
||||||
|
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
||||||
|
project(wamr)
|
||||||
|
|
||||||
|
enable_language (ASM)
|
||||||
|
|
||||||
|
set (WAMR_BUILD_PLATFORM "zephyr")
|
||||||
|
|
||||||
|
############################################################################################################################
|
||||||
|
# __ __ __ __ _____ _____ ____ _ _ ______ _____ _____ _ _ _____ _______ _____ ____ _ _ #
|
||||||
|
# \ \ / /\ | \/ | __ \ / ____/ __ \| \ | | ____|_ _/ ____| | | | __ \ /\|__ __|_ _/ __ \| \ | | #
|
||||||
|
# \ \ /\ / / \ | \ / | |__) | | | | | | | \| | |__ | || | __| | | | |__) | / \ | | | || | | | \| | #
|
||||||
|
# \ \/ \/ / /\ \ | |\/| | _ / | | | | | | . ` | __| | || | |_ | | | | _ / / /\ \ | | | || | | | . ` | #
|
||||||
|
# \ /\ / ____ \| | | | | \ \ | |___| |__| | |\ | | _| || |__| | |__| | | \ \ / ____ \| | _| || |__| | |\ | #
|
||||||
|
# \/ \/_/ \_\_| |_|_| \_\ \_____\____/|_| \_|_| |_____\_____|\____/|_| \_\/_/ \_\_| |_____\____/|_| \_| #
|
||||||
|
############################################################################################################################
|
||||||
|
|
||||||
|
# Build as X86_32 by default, change to "AARCH64[sub]", "ARM[sub]", "THUMB[sub]", "MIPS" or "XTENSA"
|
||||||
|
# if we want to support arm, thumb, mips or xtensa
|
||||||
|
|
||||||
|
set (WAMR_BUILD_TARGET "THUMB")
|
||||||
|
set (WAMR_BUILD_INTERP 1)
|
||||||
|
set (WAMR_BUILD_AOT 1)
|
||||||
|
set (WAMR_BUILD_LIBC_BUILTIN 1)
|
||||||
|
set (WAMR_BUILD_LIBC_WASI 1) # 1 to use sockets
|
||||||
|
set (WAMR_BUILD_LIB_PTHREAD 0) # 1 to use sockets => cause errors
|
||||||
|
set (WAMR_BUILD_GLOBAL_HEAP_POOL 1)
|
||||||
|
set (WAMR_BUILD_GLOBAL_HEAP_SIZE 131072) # 128 KB
|
||||||
|
|
||||||
|
###################################################
|
||||||
|
# _____ ______ _______ ______ _ ___ __ #
|
||||||
|
# / ____| ____|__ __| | ____| \ | \ \ / / #
|
||||||
|
# | (___ | |__ | | | |__ | \| |\ \ / / #
|
||||||
|
# \___ \| __| | | | __| | . ` | \ \/ / #
|
||||||
|
# ____) | |____ | | | |____| |\ | \ / #
|
||||||
|
# |_____/|______| |_| |______|_| \_| \/ #
|
||||||
|
###################################################
|
||||||
|
|
||||||
|
# Check if WAMR_ROOT_DIR is set
|
||||||
|
if(DEFINED ENV{WAMR_ROOT_DIR})
|
||||||
|
set(WAMR_ROOT_DIR $ENV{WAMR_ROOT_DIR})
|
||||||
|
else()
|
||||||
|
message(FATAL_ERROR "'WAMR_ROOT_DIR' need to be specified")
|
||||||
|
endif()
|
||||||
|
message("wasi-sdk was found at ${WAMR_ROOT_DIR}")
|
||||||
|
|
||||||
|
# Check if WASI_SDK_PATH is set
|
||||||
|
if(NOT $ENV{WASI_SDK_PATH} STREQUAL "")
|
||||||
|
set(WASI_SDK_PATH $ENV{WASI_SDK_PATH})
|
||||||
|
else()
|
||||||
|
find_program(WASM_C_COMPILER clang /opt/wasi-sdk/bin NO_DEFAULT_PATH)
|
||||||
|
if(NOT WASM_C_COMPILER)
|
||||||
|
message(FATAL_ERROR "'wasi-sdk' not found, please ensure wasi-sdk is installed.\
|
||||||
|
You can download and install it from\
|
||||||
|
https://github.com/WebAssembly/wasi-sdk/releases")
|
||||||
|
else()
|
||||||
|
set(WASI_SDK_PATH /opt/wasi-sdk)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
message("wasi-sdk was found at ${WASI_SDK_PATH}")
|
||||||
|
|
||||||
|
# Check if WAMR_APP_FRAMEWORK_DIR is set
|
||||||
|
if (DEFINED ENV{WAMR_APP_FRAMEWORK_DIR})
|
||||||
|
set(WAMR_APP_FRAMEWORK_DIR $ENV{WAMR_APP_FRAMEWORK_DIR})
|
||||||
|
else()
|
||||||
|
message(FATAL_ERROR "'wamr-app-framework' not found, please ensure they are installed.\
|
||||||
|
You can download and install them from\
|
||||||
|
https://github.com/bytecodealliance/wamr-app-framework")
|
||||||
|
endif()
|
||||||
|
message("wamr-app-framework was found at ${WAMR_APP_FRAMEWORK_DIR}")
|
||||||
|
|
||||||
|
# set the WAMR_SDK_DIR with the path specified in the environment variable
|
||||||
|
set(WAMR_SDK_DIR
|
||||||
|
${WAMR_APP_FRAMEWORK_DIR}/wamr-sdk
|
||||||
|
)
|
||||||
|
|
||||||
|
# set the WAMR_LIBC_BUILTIN_DIR with the path specified in the environment variable
|
||||||
|
set(WAMR_LIBC_BUILTIN_DIR
|
||||||
|
${WAMR_SDK_DIR}/wamr-sdk/app/libc-builtin-sysroot
|
||||||
|
)
|
||||||
|
|
||||||
|
# set the WAMR_SDK_PACKAGE_OUT_DIR
|
||||||
|
set(WAMR_SDK_PACKAGE_OUT_DIR
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/wamr-sdk/app-sdk/wamr-app-framework
|
||||||
|
)
|
||||||
|
|
||||||
|
# temp
|
||||||
|
set (PYTHON_EXECUTABLE
|
||||||
|
/usr/bin/python
|
||||||
|
)
|
||||||
|
# ~temp
|
||||||
|
|
||||||
|
# # Reset linker flags
|
||||||
|
# set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
|
||||||
|
# set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
|
||||||
|
|
||||||
|
include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)
|
||||||
|
#include (${SHARED_DIR}/utils/uncommon/shared_uncommon.cmake) # in socket-api sample
|
||||||
|
|
||||||
|
# Build the WAMR runtime
|
||||||
|
target_sources(app PRIVATE
|
||||||
|
${WAMR_RUNTIME_LIB_SOURCE}
|
||||||
|
src/main.c)
|
||||||
|
|
||||||
|
####################################################################################################
|
||||||
|
# ____ _ _ _____ _ _____ __ __ _____ __ __ __ __ ____ _____
|
||||||
|
# | _ \| | | |_ _| | | __ \ \ \ / /\ / ____| \/ | | \/ |/ __ \| __ \
|
||||||
|
# | |_) | | | | | | | | | | | | \ \ /\ / / \ | (___ | \ / | | \ / | | | | | | |
|
||||||
|
# | _ <| | | | | | | | | | | | \ \/ \/ / /\ \ \___ \| |\/| | | |\/| | | | | | | |
|
||||||
|
# | |_) | |__| |_| |_| |____| |__| | \ /\ / ____ \ ____) | | | | | | | | |__| | |__| |
|
||||||
|
# |____/ \____/|_____|______|_____/ \/ \/_/ \_\_____/|_| |_| |_| |_|\____/|_____/
|
||||||
|
####################################################################################################
|
||||||
|
|
||||||
|
add_dependencies(app wamr-sdk)
|
||||||
|
|
||||||
|
include(ExternalProject)
|
||||||
|
# include(${WAMR_ROOT_DIR}/core/iwasm/libraries/lib-socket/lib_socket_wasi.cmake)
|
||||||
|
ExternalProject_Add(wamr-sdk
|
||||||
|
SOURCE_DIR
|
||||||
|
${WAMR_SDK_DIR}/app
|
||||||
|
BINARY_DIR
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/wamr-sdk
|
||||||
|
CONFIGURE_COMMAND
|
||||||
|
${CMAKE_COMMAND} -G${CMAKE_GENERATOR} ${WAMR_SDK_DIR}/app
|
||||||
|
-DWAMR_BUILD_SDK_PROFILE=simple
|
||||||
|
-DCONFIG_PATH=${CMAKE_CURRENT_SOURCE_DIR}/wamr_sdk_config.cmake
|
||||||
|
-DCMAKE_TOOLCHAIN_FILE=${WAMR_SDK_DIR}/app/wamr_toolchain.cmake
|
||||||
|
-DOUT_DIR=${CMAKE_CURRENT_BINARY_DIR}/wamr-sdk
|
||||||
|
-DWASI_SDK_DIR=${WASI_SDK_PATH}
|
||||||
|
BUILD_COMMAND
|
||||||
|
${CMAKE_COMMAND} --build .
|
||||||
|
INSTALL_COMMAND
|
||||||
|
""
|
||||||
|
BUILD_BYPRODUCTS
|
||||||
|
${WAMR_SDK_PACKAGE_OUT_DIR}/include/wasm_app.h
|
||||||
|
${WAMR_SDK_PACKAGE_OUT_DIR}/lib/libapp_framework.a
|
||||||
|
USES_TERMINAL
|
||||||
|
)
|
||||||
|
|
||||||
|
set(WASM_APPS
|
||||||
|
http_get
|
||||||
|
)
|
||||||
|
|
||||||
|
foreach(WASM_APP ${WASM_APPS})
|
||||||
|
# Build a wasm module
|
||||||
|
add_custom_target(${WASM_APP} ALL
|
||||||
|
COMMENT
|
||||||
|
"Building ${WASM_APP}.wasm .."
|
||||||
|
COMMAND
|
||||||
|
${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/wasm-apps
|
||||||
|
COMMAND
|
||||||
|
${WASI_SDK_PATH}/bin/clang -O3
|
||||||
|
-I${WAMR_LIBC_BUILTIN_DIR}/include
|
||||||
|
-I${WAMR_SDK_PACKAGE_OUT_DIR}/include
|
||||||
|
-I/usr/include/ # temp
|
||||||
|
-L${WAMR_SDK_PACKAGE_OUT_DIR}/lib
|
||||||
|
-lapp_framework
|
||||||
|
-z stack-size=8192 -Wl,--initial-memory=65536
|
||||||
|
-Wl,--no-entry -nostdlib -Wl,--allow-undefined
|
||||||
|
-Wl,--export=__heap_base,--export=__data_end
|
||||||
|
-Wl,--export=main
|
||||||
|
-o ${CMAKE_CURRENT_BINARY_DIR}/wasm-apps/${WASM_APP}.wasm
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/wasm-apps/${WASM_APP}.c
|
||||||
|
DEPENDS
|
||||||
|
wamr-sdk
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/wasm-apps/${WASM_APP}.c
|
||||||
|
BYPRODUCTS
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/wasm-apps/${WASM_APP}.wasm
|
||||||
|
USES_TERMINAL
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# Run python script to generate the header file
|
||||||
|
add_custom_command(
|
||||||
|
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/src/${WASM_APP}.h
|
||||||
|
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/to_c_header.py
|
||||||
|
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/wasm-apps/${WASM_APP}.wasm
|
||||||
|
COMMENT "Generating .h file from .wasm file..."
|
||||||
|
)
|
||||||
|
|
||||||
|
# Add the generated header file as a target
|
||||||
|
add_custom_target(${WASM_APP}.h ALL DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src/${WASM_APP}.h)
|
||||||
|
|
||||||
|
endforeach()
|
16
product-mini/platforms/zephyr/simple-http/README.md
Normal file
16
product-mini/platforms/zephyr/simple-http/README.md
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
# Simple http
|
||||||
|
This is a simple http client that make a GET request to a server.
|
||||||
|
|
||||||
|
## Setup
|
||||||
|
TODO
|
||||||
|
|
||||||
|
## Run Command
|
||||||
|
Replace `nucleo_h743zi` with your board name.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
ZEPHYR_BASE=~/zephyrproject/zephyr \
|
||||||
|
WAMR_ROOT_DIR=~/wasm-micro-runtime \
|
||||||
|
WASI_SDK_PATH=~/wasi-sdk-21.0 \
|
||||||
|
WAMR_APP_FRAMEWORK_DIR=~/wamr-app-framework \
|
||||||
|
west build . -b nucleo_h563zi -p always -- -DWAMR_BUILD_TARGET=THUMBV8 -DCONFIG_LOG_MODE_IMMEDIATE=y
|
||||||
|
```
|
|
@ -0,0 +1,4 @@
|
||||||
|
# Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||||
|
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||||
|
|
||||||
|
CONFIG_ARM_MPU=y
|
|
@ -0,0 +1,4 @@
|
||||||
|
# Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||||
|
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||||
|
|
||||||
|
CONFIG_ARM_MMU=n
|
7
product-mini/platforms/zephyr/simple-http/prj.conf
Normal file
7
product-mini/platforms/zephyr/simple-http/prj.conf
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
# Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||||
|
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||||
|
|
||||||
|
CONFIG_STACK_SENTINEL=y
|
||||||
|
CONFIG_PRINTK=y
|
||||||
|
CONFIG_LOG=y
|
||||||
|
CONFIG_POSIX_API=n
|
1
product-mini/platforms/zephyr/simple-http/src/http_get.h
Normal file
1
product-mini/platforms/zephyr/simple-http/src/http_get.h
Normal file
File diff suppressed because one or more lines are too long
231
product-mini/platforms/zephyr/simple-http/src/main.c
Normal file
231
product-mini/platforms/zephyr/simple-http/src/main.c
Normal file
|
@ -0,0 +1,231 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||||
|
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include "bh_platform.h"
|
||||||
|
#include "bh_assert.h"
|
||||||
|
#include "bh_log.h"
|
||||||
|
#include "wasm_export.h"
|
||||||
|
#include "http_get.h"
|
||||||
|
|
||||||
|
// For libc_wasi_parse_context_t
|
||||||
|
// #if WASM_ENABLE_LIBC_WASI != 0
|
||||||
|
// #include "libc_wasi.c"
|
||||||
|
// #endif
|
||||||
|
|
||||||
|
#define CONFIG_GLOBAL_HEAP_BUF_SIZE WASM_GLOBAL_HEAP_SIZE
|
||||||
|
#define CONFIG_APP_STACK_SIZE 8192
|
||||||
|
#define CONFIG_APP_HEAP_SIZE 8192
|
||||||
|
|
||||||
|
#ifdef CONFIG_NO_OPTIMIZATIONS
|
||||||
|
#define CONFIG_MAIN_THREAD_STACK_SIZE 8192
|
||||||
|
#else
|
||||||
|
#define CONFIG_MAIN_THREAD_STACK_SIZE 4096
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static int app_argc;
|
||||||
|
static char **app_argv;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find the unique main function from a WASM module instance
|
||||||
|
* and execute that function.
|
||||||
|
*
|
||||||
|
* @param module_inst the WASM module instance
|
||||||
|
* @param argc the number of arguments
|
||||||
|
* @param argv the arguments array
|
||||||
|
*
|
||||||
|
* @return true if the main function is called, false otherwise.
|
||||||
|
*/
|
||||||
|
bool
|
||||||
|
wasm_application_execute_main(wasm_module_inst_t module_inst, int argc,
|
||||||
|
char *argv[]);
|
||||||
|
|
||||||
|
static void *
|
||||||
|
app_instance_main(wasm_module_inst_t module_inst)
|
||||||
|
{
|
||||||
|
const char *exception;
|
||||||
|
wasm_function_inst_t func;
|
||||||
|
wasm_exec_env_t exec_env;
|
||||||
|
unsigned argv[2] = { 0 };
|
||||||
|
|
||||||
|
// main fuction called on_init in module
|
||||||
|
if (wasm_runtime_lookup_function(module_inst, "main")
|
||||||
|
|| wasm_runtime_lookup_function(module_inst, "__main_argc_argv")) {
|
||||||
|
LOG_VERBOSE("Calling main function\n");
|
||||||
|
wasm_application_execute_main(module_inst, app_argc, app_argv);
|
||||||
|
}
|
||||||
|
else if ((func = wasm_runtime_lookup_function(module_inst, "app_main"))) {
|
||||||
|
exec_env =
|
||||||
|
wasm_runtime_create_exec_env(module_inst, CONFIG_APP_HEAP_SIZE);
|
||||||
|
if (!exec_env) {
|
||||||
|
os_printf("Create exec env failed\n");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG_VERBOSE("Calling app_main function\n");
|
||||||
|
wasm_runtime_call_wasm(exec_env, func, 0, argv);
|
||||||
|
|
||||||
|
if (!wasm_runtime_get_exception(module_inst)) {
|
||||||
|
os_printf("result: 0x%x\n", argv[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
wasm_runtime_destroy_exec_env(exec_env);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
os_printf("Failed to lookup function main or app_main to call\n");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((exception = wasm_runtime_get_exception(module_inst)))
|
||||||
|
os_printf("%s\n", exception);
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if WASM_ENABLE_GLOBAL_HEAP_POOL != 0
|
||||||
|
static char global_heap_buf[CONFIG_GLOBAL_HEAP_BUF_SIZE] = { 0 };
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void
|
||||||
|
iwasm_main(void *arg1, void *arg2, void *arg3)
|
||||||
|
{
|
||||||
|
// time
|
||||||
|
int start, end;
|
||||||
|
start = k_uptime_get_32();
|
||||||
|
// .wasm file
|
||||||
|
uint8 *wasm_file_buf = NULL;
|
||||||
|
uint32 wasm_file_size;
|
||||||
|
// Runtime args
|
||||||
|
wasm_module_t wasm_module = NULL;
|
||||||
|
wasm_module_inst_t wasm_module_inst = NULL;
|
||||||
|
RuntimeInitArgs init_args;
|
||||||
|
char error_buf[128];
|
||||||
|
|
||||||
|
#if WASM_ENABLE_LOG != 0
|
||||||
|
int log_verbose_level = 2;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
(void)arg1;
|
||||||
|
(void)arg2;
|
||||||
|
(void)arg3;
|
||||||
|
|
||||||
|
memset(&init_args, 0, sizeof(RuntimeInitArgs));
|
||||||
|
|
||||||
|
#if WASM_ENABLE_GLOBAL_HEAP_POOL != 0
|
||||||
|
init_args.mem_alloc_type = Alloc_With_Pool;
|
||||||
|
init_args.mem_alloc_option.pool.heap_buf = global_heap_buf;
|
||||||
|
init_args.mem_alloc_option.pool.heap_size = sizeof(global_heap_buf);
|
||||||
|
#elif (defined(CONFIG_COMMON_LIBC_MALLOC) \
|
||||||
|
&& CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE != 0) \
|
||||||
|
|| defined(CONFIG_NEWLIB_LIBC)
|
||||||
|
init_args.mem_alloc_type = Alloc_With_System_Allocator;
|
||||||
|
#else
|
||||||
|
#error "memory allocation scheme is not defined."
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Use the address pool in wasm-micro-runtime
|
||||||
|
// #if WASM_ENABLE_LIBC_WASI != 0
|
||||||
|
// #define HUMAN_READABLE_ADDRESS "192.0.2.10\\24"
|
||||||
|
// libc_wasi_parse_context_t wasi_parse_ctx;
|
||||||
|
// memset(&wasi_parse_ctx, 0, sizeof(wasi_parse_ctx));
|
||||||
|
|
||||||
|
// libc_wasi_parse_result_t result = libc_wasi_parse(HUMAN_READABLE_ADDRESS, &wasi_parse_ctx);
|
||||||
|
// switch (result) {
|
||||||
|
// case LIBC_WASI_PARSE_RESULT_OK:
|
||||||
|
// continue;
|
||||||
|
// case LIBC_WASI_PARSE_RESULT_NEED_HELP:
|
||||||
|
// return;
|
||||||
|
// case LIBC_WASI_PARSE_RESULT_BAD_PARAM:
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
// libc_wasi_init(wasm_module, argc, argv, &wasi_parse_ctx);
|
||||||
|
// #endif
|
||||||
|
|
||||||
|
/* initialize runtime environment */
|
||||||
|
if (!wasm_runtime_full_init(&init_args)) {
|
||||||
|
printf("Init runtime environment failed.\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if WASM_ENABLE_LOG != 0
|
||||||
|
bh_log_set_verbose_level(log_verbose_level);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* load WASM byte buffer from byte buffer of include file */
|
||||||
|
wasm_file_buf = (uint8 *)wasm_test_file;
|
||||||
|
wasm_file_size = sizeof(wasm_test_file);
|
||||||
|
|
||||||
|
/* load WASM module */
|
||||||
|
if (!(wasm_module = wasm_runtime_load(wasm_file_buf, wasm_file_size,
|
||||||
|
error_buf, sizeof(error_buf)))) {
|
||||||
|
printf("%s\n", error_buf);
|
||||||
|
goto fail1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* instantiate the module */
|
||||||
|
if (!(wasm_module_inst = wasm_runtime_instantiate(
|
||||||
|
wasm_module, CONFIG_APP_STACK_SIZE, CONFIG_APP_HEAP_SIZE,
|
||||||
|
error_buf, sizeof(error_buf)))) {
|
||||||
|
printf("%s\n", error_buf);
|
||||||
|
goto fail2;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* invoke the main function */
|
||||||
|
app_instance_main(wasm_module_inst);
|
||||||
|
|
||||||
|
//
|
||||||
|
// #if WASM_ENABLE_LIBC_WASI != 0
|
||||||
|
// if (ret == 0) {
|
||||||
|
// /* propagate wasi exit code. */
|
||||||
|
// ret = wasm_runtime_get_wasi_exit_code(wasm_module_inst);
|
||||||
|
// }
|
||||||
|
// #endif
|
||||||
|
|
||||||
|
/* destroy the module instance */
|
||||||
|
wasm_runtime_deinstantiate(wasm_module_inst);
|
||||||
|
|
||||||
|
fail2:
|
||||||
|
/* unload the module */
|
||||||
|
wasm_runtime_unload(wasm_module);
|
||||||
|
|
||||||
|
fail1:
|
||||||
|
/* destroy runtime environment */
|
||||||
|
wasm_runtime_destroy();
|
||||||
|
|
||||||
|
end = k_uptime_get_32();
|
||||||
|
|
||||||
|
printf("elapsed: %d\n", (end - start));
|
||||||
|
}
|
||||||
|
|
||||||
|
#define MAIN_THREAD_STACK_SIZE (CONFIG_MAIN_THREAD_STACK_SIZE)
|
||||||
|
#define MAIN_THREAD_PRIORITY 5
|
||||||
|
|
||||||
|
K_THREAD_STACK_DEFINE(iwasm_main_thread_stack, MAIN_THREAD_STACK_SIZE);
|
||||||
|
static struct k_thread iwasm_main_thread;
|
||||||
|
|
||||||
|
bool
|
||||||
|
iwasm_init(void)
|
||||||
|
{
|
||||||
|
k_tid_t tid = k_thread_create(
|
||||||
|
&iwasm_main_thread, iwasm_main_thread_stack, MAIN_THREAD_STACK_SIZE,
|
||||||
|
iwasm_main, NULL, NULL, NULL, MAIN_THREAD_PRIORITY, 0, K_NO_WAIT);
|
||||||
|
return tid ? true : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if KERNEL_VERSION_NUMBER < 0x030400 /* version 3.4.0 */
|
||||||
|
void
|
||||||
|
main(void)
|
||||||
|
{
|
||||||
|
iwasm_init();
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
int
|
||||||
|
main(void)
|
||||||
|
{
|
||||||
|
iwasm_init();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif
|
46
product-mini/platforms/zephyr/simple-http/src/test_wasm.h
Normal file
46
product-mini/platforms/zephyr/simple-http/src/test_wasm.h
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||||
|
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The byte array buffer is the file content of a test wasm binary file,
|
||||||
|
* which is compiled by wasi-sdk toolchain from C source file of:
|
||||||
|
* product-mini/app-samples/hello-world/main.c.
|
||||||
|
*/
|
||||||
|
unsigned char __aligned(4) wasm_test_file[] = {
|
||||||
|
0x00, 0x61, 0x73, 0x6D, 0x01, 0x00, 0x00, 0x00, 0x01, 0x10, 0x03, 0x60,
|
||||||
|
0x01, 0x7F, 0x01, 0x7F, 0x60, 0x02, 0x7F, 0x7F, 0x01, 0x7F, 0x60, 0x01,
|
||||||
|
0x7F, 0x00, 0x02, 0x31, 0x04, 0x03, 0x65, 0x6E, 0x76, 0x04, 0x70, 0x75,
|
||||||
|
0x74, 0x73, 0x00, 0x00, 0x03, 0x65, 0x6E, 0x76, 0x06, 0x6D, 0x61, 0x6C,
|
||||||
|
0x6C, 0x6F, 0x63, 0x00, 0x00, 0x03, 0x65, 0x6E, 0x76, 0x06, 0x70, 0x72,
|
||||||
|
0x69, 0x6E, 0x74, 0x66, 0x00, 0x01, 0x03, 0x65, 0x6E, 0x76, 0x04, 0x66,
|
||||||
|
0x72, 0x65, 0x65, 0x00, 0x02, 0x03, 0x02, 0x01, 0x01, 0x04, 0x05, 0x01,
|
||||||
|
0x70, 0x01, 0x01, 0x01, 0x05, 0x03, 0x01, 0x00, 0x01, 0x06, 0x13, 0x03,
|
||||||
|
0x7F, 0x01, 0x41, 0xC0, 0x28, 0x0B, 0x7F, 0x00, 0x41, 0xBA, 0x08, 0x0B,
|
||||||
|
0x7F, 0x00, 0x41, 0xC0, 0x28, 0x0B, 0x07, 0x2C, 0x04, 0x06, 0x6D, 0x65,
|
||||||
|
0x6D, 0x6F, 0x72, 0x79, 0x02, 0x00, 0x0A, 0x5F, 0x5F, 0x64, 0x61, 0x74,
|
||||||
|
0x61, 0x5F, 0x65, 0x6E, 0x64, 0x03, 0x01, 0x0B, 0x5F, 0x5F, 0x68, 0x65,
|
||||||
|
0x61, 0x70, 0x5F, 0x62, 0x61, 0x73, 0x65, 0x03, 0x02, 0x04, 0x6D, 0x61,
|
||||||
|
0x69, 0x6E, 0x00, 0x04, 0x0A, 0xB2, 0x01, 0x01, 0xAF, 0x01, 0x01, 0x03,
|
||||||
|
0x7F, 0x23, 0x80, 0x80, 0x80, 0x80, 0x00, 0x41, 0x20, 0x6B, 0x22, 0x02,
|
||||||
|
0x24, 0x80, 0x80, 0x80, 0x80, 0x00, 0x41, 0x9B, 0x88, 0x80, 0x80, 0x00,
|
||||||
|
0x10, 0x80, 0x80, 0x80, 0x80, 0x00, 0x1A, 0x02, 0x40, 0x02, 0x40, 0x41,
|
||||||
|
0x80, 0x08, 0x10, 0x81, 0x80, 0x80, 0x80, 0x00, 0x22, 0x03, 0x0D, 0x00,
|
||||||
|
0x41, 0xA8, 0x88, 0x80, 0x80, 0x00, 0x10, 0x80, 0x80, 0x80, 0x80, 0x00,
|
||||||
|
0x1A, 0x41, 0x7F, 0x21, 0x04, 0x0C, 0x01, 0x0B, 0x20, 0x02, 0x20, 0x03,
|
||||||
|
0x36, 0x02, 0x10, 0x41, 0x80, 0x88, 0x80, 0x80, 0x00, 0x20, 0x02, 0x41,
|
||||||
|
0x10, 0x6A, 0x10, 0x82, 0x80, 0x80, 0x80, 0x00, 0x1A, 0x41, 0x00, 0x21,
|
||||||
|
0x04, 0x20, 0x03, 0x41, 0x04, 0x6A, 0x41, 0x00, 0x2F, 0x00, 0x91, 0x88,
|
||||||
|
0x80, 0x80, 0x00, 0x3B, 0x00, 0x00, 0x20, 0x03, 0x41, 0x00, 0x28, 0x00,
|
||||||
|
0x8D, 0x88, 0x80, 0x80, 0x00, 0x36, 0x00, 0x00, 0x20, 0x02, 0x20, 0x03,
|
||||||
|
0x36, 0x02, 0x00, 0x41, 0x93, 0x88, 0x80, 0x80, 0x00, 0x20, 0x02, 0x10,
|
||||||
|
0x82, 0x80, 0x80, 0x80, 0x00, 0x1A, 0x20, 0x03, 0x10, 0x83, 0x80, 0x80,
|
||||||
|
0x80, 0x00, 0x0B, 0x20, 0x02, 0x41, 0x20, 0x6A, 0x24, 0x80, 0x80, 0x80,
|
||||||
|
0x80, 0x00, 0x20, 0x04, 0x0B, 0x0B, 0x41, 0x01, 0x00, 0x41, 0x80, 0x08,
|
||||||
|
0x0B, 0x3A, 0x62, 0x75, 0x66, 0x20, 0x70, 0x74, 0x72, 0x3A, 0x20, 0x25,
|
||||||
|
0x70, 0x0A, 0x00, 0x31, 0x32, 0x33, 0x34, 0x0A, 0x00, 0x62, 0x75, 0x66,
|
||||||
|
0x3A, 0x20, 0x25, 0x73, 0x00, 0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x77,
|
||||||
|
0x6F, 0x72, 0x6C, 0x64, 0x21, 0x00, 0x6D, 0x61, 0x6C, 0x6C, 0x6F, 0x63,
|
||||||
|
0x20, 0x62, 0x75, 0x66, 0x20, 0x66, 0x61, 0x69, 0x6C, 0x65, 0x64, 0x00
|
||||||
|
};
|
|
@ -0,0 +1,41 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||||
|
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||||
|
*/
|
||||||
|
|
||||||
|
unsigned char __aligned(4) wasm_test_file[] = {
|
||||||
|
0x00, 0x61, 0x73, 0x6D, 0x01, 0x00, 0x00, 0x00, 0x01, 0x10, 0x03, 0x60,
|
||||||
|
0x01, 0x7F, 0x01, 0x7F, 0x60, 0x02, 0x7F, 0x7F, 0x01, 0x7F, 0x60, 0x01,
|
||||||
|
0x7F, 0x00, 0x02, 0x31, 0x04, 0x03, 0x65, 0x6E, 0x76, 0x04, 0x70, 0x75,
|
||||||
|
0x74, 0x73, 0x00, 0x00, 0x03, 0x65, 0x6E, 0x76, 0x06, 0x6D, 0x61, 0x6C,
|
||||||
|
0x6C, 0x6F, 0x63, 0x00, 0x00, 0x03, 0x65, 0x6E, 0x76, 0x06, 0x70, 0x72,
|
||||||
|
0x69, 0x6E, 0x74, 0x66, 0x00, 0x01, 0x03, 0x65, 0x6E, 0x76, 0x04, 0x66,
|
||||||
|
0x72, 0x65, 0x65, 0x00, 0x02, 0x03, 0x02, 0x01, 0x01, 0x04, 0x05, 0x01,
|
||||||
|
0x70, 0x01, 0x01, 0x01, 0x05, 0x03, 0x01, 0x00, 0x01, 0x06, 0x12, 0x03,
|
||||||
|
0x7F, 0x01, 0x41, 0xC0, 0x01, 0x0B, 0x7F, 0x00, 0x41, 0x3A, 0x0B, 0x7F,
|
||||||
|
0x00, 0x41, 0xC0, 0x01, 0x0B, 0x07, 0x2C, 0x04, 0x06, 0x6D, 0x65, 0x6D,
|
||||||
|
0x6F, 0x72, 0x79, 0x02, 0x00, 0x04, 0x6D, 0x61, 0x69, 0x6E, 0x00, 0x04,
|
||||||
|
0x0A, 0x5F, 0x5F, 0x64, 0x61, 0x74, 0x61, 0x5F, 0x65, 0x6E, 0x64, 0x03,
|
||||||
|
0x01, 0x0B, 0x5F, 0x5F, 0x68, 0x65, 0x61, 0x70, 0x5F, 0x62, 0x61, 0x73,
|
||||||
|
0x65, 0x03, 0x02, 0x0A, 0xB1, 0x01, 0x01, 0xAE, 0x01, 0x01, 0x03, 0x7F,
|
||||||
|
0x23, 0x80, 0x80, 0x80, 0x80, 0x00, 0x41, 0x20, 0x6B, 0x22, 0x02, 0x24,
|
||||||
|
0x80, 0x80, 0x80, 0x80, 0x00, 0x41, 0x9B, 0x80, 0x80, 0x80, 0x00, 0x10,
|
||||||
|
0x80, 0x80, 0x80, 0x80, 0x00, 0x1A, 0x02, 0x40, 0x02, 0x40, 0x41, 0x10,
|
||||||
|
0x10, 0x81, 0x80, 0x80, 0x80, 0x00, 0x22, 0x03, 0x0D, 0x00, 0x41, 0xA8,
|
||||||
|
0x80, 0x80, 0x80, 0x00, 0x10, 0x80, 0x80, 0x80, 0x80, 0x00, 0x1A, 0x41,
|
||||||
|
0x7F, 0x21, 0x04, 0x0C, 0x01, 0x0B, 0x20, 0x02, 0x20, 0x03, 0x36, 0x02,
|
||||||
|
0x10, 0x41, 0x80, 0x80, 0x80, 0x80, 0x00, 0x20, 0x02, 0x41, 0x10, 0x6A,
|
||||||
|
0x10, 0x82, 0x80, 0x80, 0x80, 0x00, 0x1A, 0x41, 0x00, 0x21, 0x04, 0x20,
|
||||||
|
0x03, 0x41, 0x04, 0x6A, 0x41, 0x00, 0x2F, 0x00, 0x91, 0x80, 0x80, 0x80,
|
||||||
|
0x00, 0x3B, 0x00, 0x00, 0x20, 0x03, 0x41, 0x00, 0x28, 0x00, 0x8D, 0x80,
|
||||||
|
0x80, 0x80, 0x00, 0x36, 0x00, 0x00, 0x20, 0x02, 0x20, 0x03, 0x36, 0x02,
|
||||||
|
0x00, 0x41, 0x93, 0x80, 0x80, 0x80, 0x00, 0x20, 0x02, 0x10, 0x82, 0x80,
|
||||||
|
0x80, 0x80, 0x00, 0x1A, 0x20, 0x03, 0x10, 0x83, 0x80, 0x80, 0x80, 0x00,
|
||||||
|
0x0B, 0x20, 0x02, 0x41, 0x20, 0x6A, 0x24, 0x80, 0x80, 0x80, 0x80, 0x00,
|
||||||
|
0x20, 0x04, 0x0B, 0x0B, 0x40, 0x01, 0x00, 0x41, 0x00, 0x0B, 0x3A, 0x62,
|
||||||
|
0x75, 0x66, 0x20, 0x70, 0x74, 0x72, 0x3A, 0x20, 0x25, 0x70, 0x0A, 0x00,
|
||||||
|
0x31, 0x32, 0x33, 0x34, 0x0A, 0x00, 0x62, 0x75, 0x66, 0x3A, 0x20, 0x25,
|
||||||
|
0x73, 0x00, 0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x77, 0x6F, 0x72, 0x6C,
|
||||||
|
0x64, 0x21, 0x00, 0x6D, 0x61, 0x6C, 0x6C, 0x6F, 0x63, 0x20, 0x62, 0x75,
|
||||||
|
0x66, 0x20, 0x66, 0x61, 0x69, 0x6C, 0x65, 0x64, 0x00
|
||||||
|
};
|
25
product-mini/platforms/zephyr/simple-http/to_c_header.py
Normal file
25
product-mini/platforms/zephyr/simple-http/to_c_header.py
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
# Python script to convert wasm file to byte array in a .h file
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
|
CWD = os.getcwd()
|
||||||
|
|
||||||
|
CMAKE_CURRENT_BINARY_DIR = os.getenv('CMAKE_CURRENT_BINARY_DIR', CWD)
|
||||||
|
CMAKE_CURRENT_SOURCE_DIR = os.getenv('CMAKE_CURRENT_SOURCE_DIR', f'{CWD}/../src')
|
||||||
|
|
||||||
|
print('CMAKE_CURRENT_BINARY_DIR:', CMAKE_CURRENT_BINARY_DIR)
|
||||||
|
print('CMAKE_CURRENT_SOURCE_DIR:', CMAKE_CURRENT_SOURCE_DIR)
|
||||||
|
|
||||||
|
# Open the wasm file in binary mode and read the data
|
||||||
|
with open(f'{CMAKE_CURRENT_BINARY_DIR}/wasm-apps/http_get.wasm', 'rb') as f:
|
||||||
|
wasm_bytes = f.read()
|
||||||
|
|
||||||
|
# Convert the bytes to a comma-separated string of hex values
|
||||||
|
byte_array = ', '.join(f'0x{byte:02x}' for byte in wasm_bytes)
|
||||||
|
|
||||||
|
# Create the output string
|
||||||
|
output = f'unsigned char __aligned(4) wasm_test_file[] = {{ {byte_array} }};'
|
||||||
|
|
||||||
|
# Write the output string to the .h file
|
||||||
|
with open(f'{CMAKE_CURRENT_SOURCE_DIR}/http_get.h', 'w') as f:
|
||||||
|
f.write(output)
|
|
@ -0,0 +1,9 @@
|
||||||
|
set (WAMR_BUILD_PLATFORM "linux")
|
||||||
|
set (WAMR_BUILD_TARGET X86_64)
|
||||||
|
set (WAMR_BUILD_INTERP 1)
|
||||||
|
set (WAMR_BUILD_AOT 1)
|
||||||
|
set (WAMR_BUILD_JIT 0)
|
||||||
|
set (WAMR_BUILD_LIBC_BUILTIN 1)
|
||||||
|
set (WAMR_BUILD_LIBC_WASI 1)
|
||||||
|
set (WAMR_BUILD_APP_FRAMEWORK 1)
|
||||||
|
set (WAMR_BUILD_APP_LIST WAMR_APP_BUILD_BASE WAMR_APP_BUILD_SENSOR WAMR_APP_BUILD_CONNECTION)
|
127
product-mini/platforms/zephyr/simple-http/wasm-apps/http_get.c
Normal file
127
product-mini/platforms/zephyr/simple-http/wasm-apps/http_get.c
Normal file
|
@ -0,0 +1,127 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2017 Linaro Limited
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#if !defined(__ZEPHYR__) || defined(CONFIG_POSIX_API)
|
||||||
|
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <netdb.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#else
|
||||||
|
#include <zephyr/net/socket.h>
|
||||||
|
#include <zephyr/kernel.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// #ifdef __wasi__
|
||||||
|
// #include <wasi_socket_ext.h>
|
||||||
|
// #endif
|
||||||
|
|
||||||
|
|
||||||
|
/* HTTP server to connect to */
|
||||||
|
#define HTTP_HOST "192.0.2.10"
|
||||||
|
/* Port to connect to, as string */
|
||||||
|
#define HTTP_PORT "8000"
|
||||||
|
/* HTTP path to request */
|
||||||
|
#define HTTP_PATH "/"
|
||||||
|
|
||||||
|
|
||||||
|
#define SSTRLEN(s) (sizeof(s) - 1)
|
||||||
|
#define CHECK(r) { if (r == -1) { printf("Error %d: " #r "\n", errno); exit(1); } }
|
||||||
|
|
||||||
|
#define REQUEST "GET " HTTP_PATH " HTTP/1.0\r\nHost: " HTTP_HOST "\r\n\r\n"
|
||||||
|
|
||||||
|
static char response[1024];
|
||||||
|
|
||||||
|
void dump_addrinfo(const struct addrinfo *ai)
|
||||||
|
{
|
||||||
|
printf("addrinfo @%p: ai_family=%d, ai_socktype=%d, ai_protocol=%d, "
|
||||||
|
"sa_family=%d, sin_port=%x\n",
|
||||||
|
ai, ai->ai_family, ai->ai_socktype, ai->ai_protocol,
|
||||||
|
ai->ai_addr->sa_family,
|
||||||
|
((struct sockaddr_in *)ai->ai_addr)->sin_port);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
static struct addrinfo hints;
|
||||||
|
struct addrinfo *res;
|
||||||
|
int st, sock;
|
||||||
|
|
||||||
|
printf("Preparing HTTP GET request for http://" HTTP_HOST
|
||||||
|
":" HTTP_PORT HTTP_PATH "\n");
|
||||||
|
|
||||||
|
hints.ai_family = AF_INET;
|
||||||
|
hints.ai_socktype = SOCK_STREAM;
|
||||||
|
st = getaddrinfo(HTTP_HOST, HTTP_PORT, &hints, &res);
|
||||||
|
printf("getaddrinfo status: %d\n", st);
|
||||||
|
|
||||||
|
if (st != 0) {
|
||||||
|
printf("Unable to resolve address, quitting\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
dump_addrinfo(res);
|
||||||
|
|
||||||
|
//sock = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
|
||||||
|
sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||||
|
|
||||||
|
CHECK(sock);
|
||||||
|
printf("sock = %d\n", sock);
|
||||||
|
|
||||||
|
CHECK(connect(sock, res->ai_addr, res->ai_addrlen));
|
||||||
|
// int rc = 0;
|
||||||
|
// for(int i = 0; i < 10; i++){
|
||||||
|
// rc = connect(sock, res->ai_addr, res->ai_addrlen);
|
||||||
|
// if (rc == 0) {
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// else{
|
||||||
|
// printf("[Debug] Connect try %d: status %d\n", i+1, errno);
|
||||||
|
// close(sock);
|
||||||
|
// k_sleep(K_MSEC(100)); // 10 mil seconds
|
||||||
|
// sock = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
|
||||||
|
// if (sock < 0) {
|
||||||
|
// printf("[Error] Unable to create socket, exiting...");
|
||||||
|
// exit(1);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// k_sleep(K_MSEC(1000 * 5)); // 5 seconds
|
||||||
|
// }
|
||||||
|
// if(rc){
|
||||||
|
// printf("[Error] Unable to Connect exiting...");
|
||||||
|
// exit(1);
|
||||||
|
// }
|
||||||
|
|
||||||
|
CHECK(send(sock, REQUEST, SSTRLEN(REQUEST), 0));
|
||||||
|
|
||||||
|
printf("Response:\n\n");
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
int len = recv(sock, response, sizeof(response) - 1, 0);
|
||||||
|
|
||||||
|
if (len < 0) {
|
||||||
|
printf("Error reading response\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (len == 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
response[len] = 0;
|
||||||
|
printf("%s", response);
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
|
(void)close(sock);
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -0,0 +1,91 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||||
|
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _WAMR_LIB_PTHREAD_H
|
||||||
|
#define _WAMR_LIB_PTHREAD_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
/* Data type define of pthread, mutex, cond and key */
|
||||||
|
typedef unsigned int pthread_t;
|
||||||
|
typedef unsigned int pthread_mutex_t;
|
||||||
|
typedef unsigned int pthread_cond_t;
|
||||||
|
typedef unsigned int pthread_key_t;
|
||||||
|
|
||||||
|
/* Thread APIs */
|
||||||
|
int
|
||||||
|
pthread_create(pthread_t *thread, const void *attr,
|
||||||
|
void *(*start_routine)(void *), void *arg);
|
||||||
|
|
||||||
|
int
|
||||||
|
pthread_join(pthread_t thread, void **retval);
|
||||||
|
|
||||||
|
int
|
||||||
|
pthread_detach(pthread_t thread);
|
||||||
|
|
||||||
|
int
|
||||||
|
pthread_cancel(pthread_t thread);
|
||||||
|
|
||||||
|
pthread_t
|
||||||
|
pthread_self(void);
|
||||||
|
|
||||||
|
void
|
||||||
|
pthread_exit(void *retval);
|
||||||
|
|
||||||
|
/* Mutex APIs */
|
||||||
|
int
|
||||||
|
pthread_mutex_init(pthread_mutex_t *mutex, const void *attr);
|
||||||
|
|
||||||
|
int
|
||||||
|
pthread_mutex_lock(pthread_mutex_t *mutex);
|
||||||
|
|
||||||
|
int
|
||||||
|
pthread_mutex_unlock(pthread_mutex_t *mutex);
|
||||||
|
|
||||||
|
int
|
||||||
|
pthread_mutex_destroy(pthread_mutex_t *mutex);
|
||||||
|
|
||||||
|
/* Cond APIs */
|
||||||
|
int
|
||||||
|
pthread_cond_init(pthread_cond_t *cond, const void *attr);
|
||||||
|
|
||||||
|
int
|
||||||
|
pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex);
|
||||||
|
|
||||||
|
int
|
||||||
|
pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex,
|
||||||
|
uint64_t useconds);
|
||||||
|
|
||||||
|
int
|
||||||
|
pthread_cond_signal(pthread_cond_t *cond);
|
||||||
|
|
||||||
|
int
|
||||||
|
pthread_cond_broadcast(pthread_cond_t *cond);
|
||||||
|
|
||||||
|
int
|
||||||
|
pthread_cond_destroy(pthread_cond_t *cond);
|
||||||
|
|
||||||
|
/* Pthread key APIs */
|
||||||
|
int
|
||||||
|
pthread_key_create(pthread_key_t *key, void (*destructor)(void *));
|
||||||
|
|
||||||
|
int
|
||||||
|
pthread_setspecific(pthread_key_t key, const void *value);
|
||||||
|
|
||||||
|
void *
|
||||||
|
pthread_getspecific(pthread_key_t key);
|
||||||
|
|
||||||
|
int
|
||||||
|
pthread_key_delete(pthread_key_t key);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* end of _WAMR_LIB_PTHREAD_H */
|
Loading…
Reference in New Issue
Block a user