Skip to content

Commit be33a40

Browse files
Fix socket shutdown (#12) (#4449)
1 parent 8a55a1e commit be33a40

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

samples/socket-api/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ Client is running...
7979
Start receiving.
8080
Start sending.
8181
Send 106 bytes successfully!
82-
Receive 106 bytes successlly!
82+
Receive 106 bytes successfully!
8383
Data:
8484
The stars shine down
8585
It brings us light

samples/socket-api/wasm-src/send_recv.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ static bool server_is_ready = false;
2525
void *
2626
run_as_server(void *arg)
2727
{
28+
(void)arg;
2829
int sock = -1, on = 1;
2930
struct sockaddr_in addr = { 0 };
3031
int addrlen = 0;
@@ -109,14 +110,15 @@ run_as_server(void *arg)
109110
fail2:
110111
close(new_sock);
111112
fail1:
112-
shutdown(sock, SHUT_RD);
113+
shutdown(sock, SHUT_RDWR);
113114
close(sock);
114115
return NULL;
115116
}
116117

117118
void *
118119
run_as_client(void *arg)
119120
{
121+
(void)arg;
120122
int sock = -1;
121123
struct sockaddr_in addr = { 0 };
122124
/* buf of server is 106 bytes */
@@ -159,7 +161,7 @@ run_as_client(void *arg)
159161
goto fail;
160162
}
161163

162-
printf("Receive %ld bytes successlly!\n", recv_len);
164+
printf("Receive %ld bytes successfully!\n", recv_len);
163165
assert(recv_len == 106);
164166

165167
printf("Data:\n");
@@ -170,14 +172,16 @@ run_as_client(void *arg)
170172
}
171173

172174
fail:
173-
shutdown(sock, SHUT_RD);
175+
shutdown(sock, SHUT_RDWR);
174176
close(sock);
175177
return NULL;
176178
}
177179

178180
int
179181
main(int argc, char *argv[])
180182
{
183+
(void)argc;
184+
(void)argv;
181185
pthread_t cs[2] = { 0 };
182186
uint8_t i = 0;
183187
int ret = EXIT_SUCCESS;

samples/wasm-c-api-imports/wasm/send_recv.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ local_printf(const char *formatter, ...)
5050
void *
5151
run_as_server(void *arg)
5252
{
53+
(void)arg;
5354
int sock = -1, on = 1;
5455
struct sockaddr_in addr = { 0 };
5556
int addrlen = 0;
@@ -134,14 +135,15 @@ run_as_server(void *arg)
134135
fail2:
135136
close(new_sock);
136137
fail1:
137-
shutdown(sock, SHUT_RD);
138+
shutdown(sock, SHUT_RDWR);
138139
close(sock);
139140
return NULL;
140141
}
141142

142143
void *
143144
run_as_client(void *arg)
144145
{
146+
(void)arg;
145147
int sock = -1;
146148
struct sockaddr_in addr = { 0 };
147149
/* buf of server is 106 bytes */
@@ -184,7 +186,7 @@ run_as_client(void *arg)
184186
goto fail;
185187
}
186188

187-
local_printf("Receive %ld bytes successlly!\n", recv_len);
189+
local_printf("Receive %ld bytes successfully!\n", recv_len);
188190
assert(recv_len == 106);
189191

190192
local_printf("Data:\n");
@@ -195,14 +197,16 @@ run_as_client(void *arg)
195197
}
196198

197199
fail:
198-
shutdown(sock, SHUT_RD);
200+
shutdown(sock, SHUT_RDWR);
199201
close(sock);
200202
return NULL;
201203
}
202204

203205
int
204206
main(int argc, char *argv[])
205207
{
208+
(void)argc;
209+
(void)argv;
206210
pthread_t cs[2] = { 0 };
207211
uint8_t i = 0;
208212
int ret = EXIT_SUCCESS;

0 commit comments

Comments
 (0)