summaryrefslogtreecommitdiff
path: root/doc/examples/ex-client-anon.c
diff options
context:
space:
mode:
Diffstat (limited to 'doc/examples/ex-client-anon.c')
-rw-r--r--doc/examples/ex-client-anon.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/doc/examples/ex-client-anon.c b/doc/examples/ex-client-anon.c
index e86e9302f5..39d5a7e3cd 100644
--- a/doc/examples/ex-client-anon.c
+++ b/doc/examples/ex-client-anon.c
@@ -11,11 +11,18 @@
#include <sys/socket.h>
#include <arpa/inet.h>
#include <unistd.h>
+#include <assert.h>
#include <gnutls/gnutls.h>
/* A very basic TLS client, with anonymous authentication.
*/
+#define LOOP_CHECK(rval, cmd) \
+ do { \
+ rval = cmd; \
+ } while(rval == GNUTLS_E_AGAIN || rval == GNUTLS_E_INTERRUPTED); \
+ assert(rval >= 0)
+
#define MAX_BUF 1024
#define MSG "GET / HTTP/1.0\r\n\r\n"
@@ -74,9 +81,9 @@ int main(void)
gnutls_free(desc);
}
- gnutls_record_send(session, MSG, strlen(MSG));
+ LOOP_CHECK(ret, gnutls_record_send(session, MSG, strlen(MSG)));
- ret = gnutls_record_recv(session, buffer, MAX_BUF);
+ LOOP_CHECK(ret, gnutls_record_recv(session, buffer, MAX_BUF));
if (ret == 0) {
printf("- Peer has closed the TLS connection\n");
goto end;
@@ -95,7 +102,7 @@ int main(void)
fputs("\n", stdout);
}
- gnutls_bye(session, GNUTLS_SHUT_RDWR);
+ LOOP_CHECK(ret, gnutls_bye(session, GNUTLS_SHUT_RDWR));
end: