summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbeck <>2015-09-10 14:57:29 +0000
committerbeck <>2015-09-10 14:57:29 +0000
commit18cdf03962910233188c8a93fa79a99b36a52cb6 (patch)
treef5ffaaee55a6627c8c20af752776d1744bdad364
parent0a913351fcafdac683d490f6de2b65ac6460ec11 (diff)
downloadopenbsd-18cdf03962910233188c8a93fa79a99b36a52cb6.tar.gz
openbsd-18cdf03962910233188c8a93fa79a99b36a52cb6.tar.bz2
openbsd-18cdf03962910233188c8a93fa79a99b36a52cb6.zip
document changed tls_read and tls_write semantics.
document functions that clear errno. change examples to provide demonstration of both the blocking and non-blocking cases. ok jsing@, bluhm@
-rw-r--r--src/lib/libtls/tls_init.373
1 files changed, 58 insertions, 15 deletions
diff --git a/src/lib/libtls/tls_init.3 b/src/lib/libtls/tls_init.3
index d2ba9d0978..62f52e4331 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.32 2015/09/10 14:17:22 jmc Exp $ 1.\" $OpenBSD: tls_init.3,v 1.33 2015/09/10 14:57:29 beck Exp $
2.\" 2.\"
3.\" Copyright (c) 2014 Ted Unangst <tedu@openbsd.org> 3.\" Copyright (c) 2014 Ted Unangst <tedu@openbsd.org>
4.\" 4.\"
@@ -131,10 +131,10 @@
131.Fn tls_accept_socket "struct tls *tls" "struct tls **cctx" "int socket" 131.Fn tls_accept_socket "struct tls *tls" "struct tls **cctx" "int socket"
132.Ft "int" 132.Ft "int"
133.Fn tls_handshake "struct tls *ctx" 133.Fn tls_handshake "struct tls *ctx"
134.Ft "int" 134.Ft "ssize_t"
135.Fn tls_read "struct tls *ctx" "void *buf" "size_t buflen" "size_t *outlen" 135.Fn tls_read "struct tls *ctx" "void *buf" "size_t buflen"
136.Ft "int" 136.Ft "ssize_t"
137.Fn tls_write "struct tls *ctx" "const void *buf" "size_t buflen" "size_t *outlen" 137.Fn tls_write "struct tls *ctx" "const void *buf" "size_t buflen"
138.Ft "int" 138.Ft "int"
139.Fn tls_close "struct tls *ctx" 139.Fn tls_close "struct tls *ctx"
140.Sh DESCRIPTION 140.Sh DESCRIPTION
@@ -431,6 +431,8 @@ or
431.Sh RETURN VALUES 431.Sh RETURN VALUES
432Functions that return 432Functions that return
433.Vt int 433.Vt int
434or
435.Vt ssize_t
434will return 0 on success and -1 on error. 436will return 0 on success and -1 on error.
435Functions that return a pointer will return NULL on error, which indicates an 437Functions that return a pointer will return NULL on error, which indicates an
436out of memory condition. 438out of memory condition.
@@ -454,20 +456,61 @@ In the case of blocking file descriptors, the same function call should be
454repeated immediately. 456repeated immediately.
455In the case of non-blocking file descriptors, the same function call should be 457In the case of non-blocking file descriptors, the same function call should be
456repeated when the required condition has been met. 458repeated when the required condition has been met.
459.Pp
460Callers of these functions can not rely on the value of the global
461.Ar errno .
462To prevent mishandling of error conditions,
463.Fn tls_handshake ,
464.Fn tls_read ,
465.Fn tls_write ,
466and
467.Fn tls_close
468all explicitly clear
469.Ar errno .
457.Sh EXAMPLES 470.Sh EXAMPLES
458Example showing how to handle TLS writes. 471The following example demonstrates how to handle TLS writes on a blocking
472file descriptor:
473.Bd -literal -offset indent
474\&...
475while (len > 0) {
476 ret = tls_write(ctx, buf, len);
477 if (ret == TLS_WANT_POLLIN || ret == TLS_WANT_POLLOUT)
478 continue;
479 if (ret < 0)
480 err(1, "tls_write: %s", tls_error(ctx));
481 buf += ret;
482 len -= ret;
483}
484\&...
485.Ed
486.Pp
487The following example demonstrates how to handle TLS writes on a
488non-blocking file descriptor using
489.Xr poll 2
459.Bd -literal -offset indent 490.Bd -literal -offset indent
460\&... 491\&...
492pevent = POLLOUT;
461while (len > 0) { 493while (len > 0) {
462 ret = tls_write(ctx, buf, len, &num_written); 494 pfd[0].fd = fd;
463 if (ret == TLS_WANT_POLLIN || ret == TLS_WANT_POLLOUT) { 495 pfd[0].events = pevent;
464 /* Retry - use select to wait for non-blocking. */ 496 nready = poll(pfd, 1, 0);
465 } else if (ret < 0) { 497 if (nready == -1)
466 return -1; 498 err(1, "poll");
467 } else { 499 if ((pfd[0].revents & (POLLERR|POLLNVAL)))
468 buf += num_written; 500 errx(1, "bad fd %d", pfd[0].fd);
469 len -= num_written; 501 if ((pfd[0].revents & (pevent|POLLHUP))) {
470 } 502 ret = tls_write(ctx, buf, len);
503 if (ret == TLS_WANT_POLLIN)
504 pevent = POLLIN;
505 else if (ret == TLS_WANT_POLLOUT)
506 pevent = POLLOUT;
507 else if (ret < 0)
508 err(1, "tls_write: %s", tls_error(ctx));
509 else {
510 buf += ret;
511 len -= ret;
512 }
513 }
471} 514}
472\&... 515\&...
473.Ed 516.Ed