aboutsummaryrefslogtreecommitdiff
path: root/tests/sockets/test_sockets_echo_client.c
diff options
context:
space:
mode:
authorAnthony Pesch <inolen@gmail.com>2013-08-30 16:52:52 -0700
committerAnthony Pesch <inolen@gmail.com>2013-08-30 16:53:05 -0700
commit5cf189f76e6e0ebb5d0e4866e066ac26da7ccbb6 (patch)
treebbc72b05c0854b083329e71f93c43685104f1a37 /tests/sockets/test_sockets_echo_client.c
parent19d175c00a94e66f96b2535fae7b4d4fad3c2248 (diff)
don't close client sockets by default in echo server enabling TCP teardown to succeed
Diffstat (limited to 'tests/sockets/test_sockets_echo_client.c')
-rw-r--r--tests/sockets/test_sockets_echo_client.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/tests/sockets/test_sockets_echo_client.c b/tests/sockets/test_sockets_echo_client.c
index 6b3ccef3..f6ea85cf 100644
--- a/tests/sockets/test_sockets_echo_client.c
+++ b/tests/sockets/test_sockets_echo_client.c
@@ -38,7 +38,10 @@ int echo_read;
int echo_wrote;
void finish(int result) {
- close(server.fd);
+ if (server.fd) {
+ close(server.fd);
+ server.fd = 0;
+ }
#if EMSCRIPTEN
REPORT_RESULT();
#endif
@@ -76,7 +79,12 @@ void main_loop(void *arg) {
assert(available);
res = do_msg_read(server.fd, &server.msg, echo_read, 0, NULL, NULL);
- if (res != -1) echo_read += res;
+ if (res == 0) {
+ perror("server closed");
+ finish(EXIT_FAILURE);
+ } else if (res != -1) {
+ echo_read += res;
+ }
// once we've read the entire message, validate it
if (echo_read >= server.msg.length) {
@@ -89,7 +97,12 @@ void main_loop(void *arg) {
}
res = do_msg_write(server.fd, &echo_msg, echo_wrote, 0, NULL, 0);
- if (res != -1) echo_wrote += res;
+ if (res == 0) {
+ perror("server closed");
+ finish(EXIT_FAILURE);
+ } else if (res != -1) {
+ echo_wrote += res;
+ }
// once we're done writing the message, read it back
if (echo_wrote >= echo_msg.length) {