Enhance/Fix sample socket-api and workload (#2006)
- Add python script to test socket-api cases - Fix issues in socket-api send_recv wasm app - Fix issues in building samples/workload/meshoptimizer - Enhance build script of sample workload
This commit is contained in:
@ -19,6 +19,7 @@
|
||||
|
||||
static pthread_mutex_t lock = { 0 };
|
||||
static pthread_cond_t cond = { 0 };
|
||||
static bool server_create_failed = false;
|
||||
static bool server_is_ready = false;
|
||||
|
||||
void *
|
||||
@ -46,6 +47,8 @@ run_as_server(void *arg)
|
||||
pthread_mutex_lock(&lock);
|
||||
sock = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if (sock < 0) {
|
||||
server_create_failed = true;
|
||||
pthread_cond_signal(&cond);
|
||||
pthread_mutex_unlock(&lock);
|
||||
perror("Create a socket failed");
|
||||
return NULL;
|
||||
@ -53,6 +56,8 @@ run_as_server(void *arg)
|
||||
|
||||
#ifndef __wasi__
|
||||
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on))) {
|
||||
server_create_failed = true;
|
||||
pthread_cond_signal(&cond);
|
||||
pthread_mutex_unlock(&lock);
|
||||
perror("Setsockopt failed");
|
||||
goto fail1;
|
||||
@ -66,12 +71,16 @@ run_as_server(void *arg)
|
||||
|
||||
addrlen = sizeof(addr);
|
||||
if (bind(sock, (struct sockaddr *)&addr, addrlen) < 0) {
|
||||
server_create_failed = true;
|
||||
pthread_cond_signal(&cond);
|
||||
pthread_mutex_unlock(&lock);
|
||||
perror("Bind failed");
|
||||
goto fail1;
|
||||
}
|
||||
|
||||
if (listen(sock, 0) < 0) {
|
||||
server_create_failed = true;
|
||||
pthread_cond_signal(&cond);
|
||||
pthread_mutex_unlock(&lock);
|
||||
perror("Listen failed");
|
||||
goto fail1;
|
||||
@ -117,11 +126,15 @@ run_as_client(void *arg)
|
||||
ssize_t recv_len = 0;
|
||||
|
||||
pthread_mutex_lock(&lock);
|
||||
while (false == server_is_ready) {
|
||||
while (!server_create_failed && !server_is_ready) {
|
||||
pthread_cond_wait(&cond, &lock);
|
||||
}
|
||||
pthread_mutex_unlock(&lock);
|
||||
|
||||
if (server_create_failed) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
printf("Client is running...\n");
|
||||
sock = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if (sock < 0) {
|
||||
|
||||
Reference in New Issue
Block a user