diff options
| author | deraadt <> | 2015-09-10 16:59:00 +0000 |
|---|---|---|
| committer | deraadt <> | 2015-09-10 16:59:00 +0000 |
| commit | d65ad2c1f2794d3d6f1cd74e64b738ee9904a95b (patch) | |
| tree | ef68776941323adc99c6819819489b4bb0e3d502 | |
| parent | 026c99675eb9b8902610f6f059b8b29e491875b4 (diff) | |
| download | openbsd-d65ad2c1f2794d3d6f1cd74e64b738ee9904a95b.tar.gz openbsd-d65ad2c1f2794d3d6f1cd74e64b738ee9904a95b.tar.bz2 openbsd-d65ad2c1f2794d3d6f1cd74e64b738ee9904a95b.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
| -rw-r--r-- | src/lib/libtls/tls_init.3 | 19 |
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 | \&... |
| 489 | while (len > 0) { | 489 | while (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 |
| 501 | The following example demonstrates how to handle TLS writes on a | 503 | The following example demonstrates how to handle TLS writes on a |
| 502 | non-blocking file descriptor using | 504 | non-blocking file descriptor using |
| 503 | .Xr poll 2 | 505 | .Xr poll 2 : |
| 504 | .Bd -literal -offset indent | 506 | .Bd -literal -offset indent |
| 505 | \&... | 507 | \&... |
| 506 | pevent = POLLOUT; | 508 | pfd[0].fd = fd; |
| 509 | pfd[0].events = POLLIN|POLLOUT; | ||
| 507 | while (len > 0) { | 510 | while (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 { |
