From d51b21c6f41a021f21078921a0de50106264d55e Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Wed, 26 Feb 2014 11:00:18 +0100 Subject: [PATCH] Update comstack example a bit In particular use cs_rcvconnect. --- doc/comstack.xml | 15 ++++++++++----- test/test_comstack.c | 14 +++++++++----- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/doc/comstack.xml b/doc/comstack.xml index 436d84a..846b507 100644 --- a/doc/comstack.xml +++ b/doc/comstack.xml @@ -20,25 +20,30 @@ } server_address_ip = cs_straddr(stack, server_address_str); - if (!server_address_ip) - { + if (!server_address_ip) { fprintf(stderr, "cs_straddr: address could not be resolved\n"); return -1; } status = cs_connect(stack, server_address_ip); - if (status != 0) { + if (status) { fprintf(stderr, "cs_connect: %s\n", cs_strerror(stack)); return -1; } + status = cs_rcvconnect(stack); + if (status) { + fprintf(stderr, "cs_rcvconnect: %s\n", cs_strerror(stack)); + return -1; + } + status = cs_put(stack, protocol_package, protocol_package_length); if (status) { fprintf(stderr, "cs_put: %s\n", cs_strerror(stack)); return -1; } - /* Now get a response */ + /* Now get a response */ length_incoming = cs_get(stack, &buf, &size); if (!length_incoming) { fprintf(stderr, "Connection closed\n"); @@ -54,7 +59,7 @@ /* clean up */ cs_close(stack); if (buf) - free(buf); + xfree(buf); return 0; ]]> diff --git a/test/test_comstack.c b/test/test_comstack.c index ecbceb3..fedf567 100644 --- a/test/test_comstack.c +++ b/test/test_comstack.c @@ -223,18 +223,23 @@ static int comstack_example(const char *server_address_str) } server_address_ip = cs_straddr(stack, server_address_str); - if (!server_address_ip) - { + if (!server_address_ip) { fprintf(stderr, "cs_straddr: address could not be resolved\n"); return -1; } status = cs_connect(stack, server_address_ip); - if (status != 0) { + if (status) { fprintf(stderr, "cs_connect: %s\n", cs_strerror(stack)); return -1; } + status = cs_rcvconnect(stack); + if (status) { + fprintf(stderr, "cs_rcvconnect: %s\n", cs_strerror(stack)); + return -1; + } + status = cs_put(stack, protocol_package, protocol_package_length); if (status) { fprintf(stderr, "cs_put: %s\n", cs_strerror(stack)); @@ -242,7 +247,6 @@ static int comstack_example(const char *server_address_str) } /* Now get a response */ - length_incoming = cs_get(stack, &buf, &size); if (!length_incoming) { fprintf(stderr, "Connection closed\n"); @@ -258,7 +262,7 @@ static int comstack_example(const char *server_address_str) /* clean up */ cs_close(stack); if (buf) - free(buf); + xfree(buf); return 0; } -- 1.7.10.4