summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorderaadt <>2015-09-10 16:59:00 +0000
committerderaadt <>2015-09-10 16:59:00 +0000
commit3de7aa268622f5ee3cfe2831d0da81edc27f1d24 (patch)
treeef68776941323adc99c6819819489b4bb0e3d502 /src
parentd574f53ead547139fe344bb35933efc8628c04d4 (diff)
downloadopenbsd-3de7aa268622f5ee3cfe2831d0da81edc27f1d24.tar.gz
openbsd-3de7aa268622f5ee3cfe2831d0da81edc27f1d24.tar.bz2
openbsd-3de7aa268622f5ee3cfe2831d0da81edc27f1d24.zip
improve examples,
1. hoist pollfd fields which don't change upwards 2. show ret as ssize_t, it MUST BE, or there will be lots of crying 3. on first pass, must check for either POLLIN|POLLOUT ok millert beck
Diffstat (limited to 'src')
-rw-r--r--src/lib/libtls/tls_init.319
1 files changed, 11 insertions, 8 deletions
diff --git a/src/lib/libtls/tls_init.3 b/src/lib/libtls/tls_init.3
index 01c931bb41..050bdfb6a6 100644
--- a/src/lib/libtls/tls_init.3
+++ b/src/lib/libtls/tls_init.3
@@ -1,4 +1,4 @@
1.\" $OpenBSD: tls_init.3,v 1.34 2015/09/10 15:47:25 beck Exp $ 1.\" $OpenBSD: tls_init.3,v 1.35 2015/09/10 16:59:00 deraadt Exp $
2.\" 2.\"
3.\" Copyright (c) 2014 Ted Unangst <tedu@openbsd.org> 3.\" Copyright (c) 2014 Ted Unangst <tedu@openbsd.org>
4.\" 4.\"
@@ -487,6 +487,8 @@ file descriptor:
487.Bd -literal -offset indent 487.Bd -literal -offset indent
488\&... 488\&...
489while (len > 0) { 489while (len > 0) {
490 ssize_t ret;
491
490 ret = tls_write(ctx, buf, len); 492 ret = tls_write(ctx, buf, len);
491 if (ret == TLS_WANT_POLLIN || ret == TLS_WANT_POLLOUT) 493 if (ret == TLS_WANT_POLLIN || ret == TLS_WANT_POLLOUT)
492 continue; 494 continue;
@@ -500,24 +502,25 @@ while (len > 0) {
500.Pp 502.Pp
501The following example demonstrates how to handle TLS writes on a 503The following example demonstrates how to handle TLS writes on a
502non-blocking file descriptor using 504non-blocking file descriptor using
503.Xr poll 2 505.Xr poll 2 :
504.Bd -literal -offset indent 506.Bd -literal -offset indent
505\&... 507\&...
506pevent = POLLOUT; 508pfd[0].fd = fd;
509pfd[0].events = POLLIN|POLLOUT;
507while (len > 0) { 510while (len > 0) {
508 pfd[0].fd = fd;
509 pfd[0].events = pevent;
510 nready = poll(pfd, 1, 0); 511 nready = poll(pfd, 1, 0);
511 if (nready == -1) 512 if (nready == -1)
512 err(1, "poll"); 513 err(1, "poll");
513 if ((pfd[0].revents & (POLLERR|POLLNVAL))) 514 if ((pfd[0].revents & (POLLERR|POLLNVAL)))
514 errx(1, "bad fd %d", pfd[0].fd); 515 errx(1, "bad fd %d", pfd[0].fd);
515 if ((pfd[0].revents & (pevent|POLLHUP))) { 516 if ((pfd[0].revents & (pfd[0].events|POLLHUP))) {
517 ssize_t ret;
518
516 ret = tls_write(ctx, buf, len); 519 ret = tls_write(ctx, buf, len);
517 if (ret == TLS_WANT_POLLIN) 520 if (ret == TLS_WANT_POLLIN)
518 pevent = POLLIN; 521 pfd[0].events = POLLIN;
519 else if (ret == TLS_WANT_POLLOUT) 522 else if (ret == TLS_WANT_POLLOUT)
520 pevent = POLLOUT; 523 pfd[0].events = POLLOUT;
521 else if (ret < 0) 524 else if (ret < 0)
522 err(1, "tls_write: %s", tls_error(ctx)); 525 err(1, "tls_write: %s", tls_error(ctx));
523 else { 526 else {