|
NAMEtls_read , tls_write ,
tls_handshake , tls_error ,
tls_close , tls_reset —
use a TLS connection
SYNOPSIS#include <tls.h>
ssize_t
ssize_t
int
const char *
int
void
DESCRIPTIONtls_read () reads buflen bytes of
data from the socket into buf. It returns the amount of
data read.
The
RETURN VALUEStls_read () and tls_write ()
return a size on success or -1 on error.
The
In the case of blocking file descriptors, the same function call should be repeated immediately. In the case of non-blocking file descriptors, the same function call should be repeated when the required condition has been met. Callers of these functions cannot rely on the value of the global
errno. To prevent mishandling of error conditions,
EXAMPLESThe following example demonstrates how to handle TLS writes on a blocking file descriptor:... while (len > 0) { ssize_t ret; ret = tls_write(ctx, buf, len); if (ret == TLS_WANT_POLLIN || ret == TLS_WANT_POLLOUT) continue; if (ret == -1) errx(1, "tls_write: %s", tls_error(ctx)); buf += ret; len -= ret; } ... The following example demonstrates how to handle TLS writes on a non-blocking file descriptor using poll(2): ... pfd[0].fd = fd; pfd[0].events = POLLIN|POLLOUT; while (len > 0) { nready = poll(pfd, 1, 0); if (nready == -1) err(1, "poll"); if ((pfd[0].revents & (POLLERR|POLLNVAL))) errx(1, "bad fd %d", pfd[0].fd); if ((pfd[0].revents & (pfd[0].events|POLLHUP))) { ssize_t ret; ret = tls_write(ctx, buf, len); if (ret == TLS_WANT_POLLIN) pfd[0].events = POLLIN; else if (ret == TLS_WANT_POLLOUT) pfd[0].events = POLLOUT; else if (ret == -1) errx(1, "tls_write: %s", tls_error(ctx)); else { buf += ret; len -= ret; } } } ... SEE ALSOtls_accept_socket(3), tls_configure(3), tls_conn_version(3), tls_connect(3), tls_init(3), tls_ocsp_process_response(3)HISTORYtls_read (), tls_write (),
tls_error (), tls_close (), and
tls_reset () appeared in OpenBSD
5.6 and got their final names in OpenBSD 5.7.
AUTHORSJoel Sing <jsing@openbsd.org> with contributions fromBob Beck <beck@openbsd.org> CAVEATSThe functiontls_error () returns an internal pointer. It
must not be freed by the application, or a double free error will occur. The
pointer will become invalid when the next error occurs with
ctx. Consequently, if the application may need the
message at a later time, it has to copy the string before calling the next
libtls function involving ctx, or a
segmentation fault or read access to unintended data is the likely result.
Visit the GSP FreeBSD Man Page Interface. |