Merge pull request #1392 from bytecodealliance/main

Merge main into dev/socket
This commit is contained in:
Wenyong Huang
2022-08-20 12:31:10 +08:00
committed by GitHub
209 changed files with 26189 additions and 1212 deletions

View File

@ -1,7 +1,7 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
cmake_minimum_required (VERSION 2.8)
cmake_minimum_required (VERSION 2.9)
if (NOT WAMR_BUILD_PLATFORM STREQUAL "windows")
project (basic)

View File

@ -1,7 +1,7 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
cmake_minimum_required (VERSION 2.8)
cmake_minimum_required (VERSION 2.9)
project (wasm_runtime_wgl)

View File

@ -1,7 +1,7 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
cmake_minimum_required (VERSION 2.8.2)
cmake_minimum_required (VERSION 2.9)
message ("vgl_native_ui_app...")
project (vgl_native_ui_app)

View File

@ -1,7 +1,7 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
cmake_minimum_required (VERSION 2.8)
cmake_minimum_required (VERSION 2.9)
project (vgl_wasm_runtime)

View File

@ -5,9 +5,11 @@
#include <stdio.h>
#include <pthread.h>
#include <semaphore.h>
static pthread_mutex_t mutex;
static pthread_cond_t cond;
static sem_t *sem;
static void *
thread(void *arg)
@ -24,6 +26,7 @@ thread(void *arg)
pthread_cond_signal(&cond);
pthread_mutex_unlock(&mutex);
sem_post(sem);
printf("thread exit \n");
@ -45,10 +48,18 @@ main(int argc, char *argv[])
goto fail1;
}
// O_CREAT and S_IRGRPS_IRGRP | S_IWGRP on linux (glibc), initial value is 0
if (!(sem = sem_open("tessstsem", 0100, 0x10 | 0x20, 0))) {
printf("Failed to open sem. %p\n", sem);
goto fail2;
}
pthread_mutex_lock(&mutex);
if (pthread_create(&tid, NULL, thread, &num) != 0) {
printf("Failed to create thread.\n");
goto fail2;
pthread_mutex_unlock(&mutex);
goto fail3;
}
printf("cond wait start\n");
@ -56,12 +67,22 @@ main(int argc, char *argv[])
pthread_mutex_unlock(&mutex);
printf("cond wait success.\n");
if (sem_wait(sem) != 0) {
printf("Failed to wait sem.\n");
}
else {
printf("sem wait success.\n");
}
if (pthread_join(tid, NULL) != 0) {
printf("Failed to join thread.\n");
}
ret = 0;
fail3:
sem_close(sem);
sem_unlink("tessstsem");
fail2:
pthread_cond_destroy(&cond);
fail1:

View File

@ -1,7 +1,7 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
cmake_minimum_required (VERSION 2.8)
cmake_minimum_required (VERSION 2.9)
if (NOT WAMR_BUILD_PLATFORM STREQUAL "windows")
project(ref-types)

View File

@ -1,7 +1,7 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
cmake_minimum_required (VERSION 2.8)
cmake_minimum_required (VERSION 2.9)
project (simple)

View File

@ -46,14 +46,16 @@ run_as_server(void *arg)
pthread_mutex_lock(&lock);
sock = socket(AF_INET, SOCK_STREAM, 0);
if (sock < 0) {
pthread_mutex_unlock(&lock);
perror("Create a socket failed");
goto RETURN;
return NULL;
}
#ifndef __wasi__
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on))) {
pthread_mutex_unlock(&lock);
perror("Setsockopt failed");
goto RETURN;
goto fail1;
}
#endif
@ -64,13 +66,15 @@ run_as_server(void *arg)
addrlen = sizeof(addr);
if (bind(sock, (struct sockaddr *)&addr, addrlen) < 0) {
pthread_mutex_unlock(&lock);
perror("Bind failed");
goto UNLOCK_SHUTDOWN;
goto fail1;
}
if (listen(sock, 0) < 0) {
pthread_mutex_unlock(&lock);
perror("Listen failed");
goto UNLOCK_SHUTDOWN;
goto fail1;
}
server_is_ready = true;
@ -82,25 +86,22 @@ run_as_server(void *arg)
new_sock = accept(sock, (struct sockaddr *)&addr, (socklen_t *)&addrlen);
if (new_sock < 0) {
perror("Accept failed");
goto SHUTDOWN;
goto fail1;
}
printf("Start sending. \n");
send_len = sendmsg(new_sock, &msg, 0);
if (send_len < 0) {
perror("Sendmsg failed");
goto SHUTDOWN;
goto fail2;
}
printf("Send %ld bytes successfully!\n", send_len);
SHUTDOWN:
fail2:
close(new_sock);
fail1:
shutdown(sock, SHUT_RD);
return NULL;
UNLOCK_SHUTDOWN:
shutdown(sock, SHUT_RD);
RETURN:
pthread_mutex_unlock(&lock);
close(sock);
return NULL;
}
@ -125,7 +126,7 @@ run_as_client(void *arg)
sock = socket(AF_INET, SOCK_STREAM, 0);
if (sock < 0) {
perror("Create a socket failed");
goto RETURN;
return NULL;
}
/* 127.0.0.1:1234 */
@ -135,14 +136,14 @@ run_as_client(void *arg)
if (connect(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
perror("Connect failed");
goto UNLOCK_SHUTDOWN;
goto fail;
}
printf("Start receiving. \n");
recv_len = recvmsg(sock, &msg, 0);
if (recv_len < 0) {
perror("Recvmsg failed");
goto SHUTDOWN;
goto fail;
}
printf("Receive %ld bytes successlly!\n", recv_len);
@ -155,14 +156,9 @@ run_as_client(void *arg)
s += strlen(s) + 1;
}
SHUTDOWN:
fail:
shutdown(sock, SHUT_RD);
return NULL;
UNLOCK_SHUTDOWN:
shutdown(sock, SHUT_RD);
RETURN:
pthread_mutex_unlock(&lock);
close(sock);
return NULL;
}

View File

@ -1,7 +1,7 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
cmake_minimum_required (VERSION 2.8)
cmake_minimum_required (VERSION 2.9)
if (NOT WAMR_BUILD_PLATFORM STREQUAL "windows")
project(c-api)