diff options
author | Bob Beck <beck@cvs.openbsd.org> | 2015-09-10 10:22:29 +0000 |
---|---|---|
committer | Bob Beck <beck@cvs.openbsd.org> | 2015-09-10 10:22:29 +0000 |
commit | 88a0937d27b2170a227eb731fc6e2c03e1e6f221 (patch) | |
tree | 30f73b08ad1a7ed69f276553b2c29f492371ff55 /lib/libtls/tls.c | |
parent | cf62476995aa2d557f8c44d6cfdbcae71adc3378 (diff) |
Change tls_read and tls_write semantics to return an ssize_t to better
match read() and write() semantics to make porting existing code using
read/write easier.. requested by bluhm@ who convinced jsing and I to break
the api
ok jsing@ bluhm@
Diffstat (limited to 'lib/libtls/tls.c')
-rw-r--r-- | lib/libtls/tls.c | 28 |
1 files changed, 11 insertions, 17 deletions
diff --git a/lib/libtls/tls.c b/lib/libtls/tls.c index fe5bc964e29..c89b805af90 100644 --- a/lib/libtls/tls.c +++ b/lib/libtls/tls.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tls.c,v 1.20 2015/09/10 10:14:20 jsing Exp $ */ +/* $OpenBSD: tls.c,v 1.21 2015/09/10 10:22:28 beck Exp $ */ /* * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> * @@ -383,13 +383,11 @@ tls_handshake(struct tls *ctx) return (rv); } -int -tls_read(struct tls *ctx, void *buf, size_t buflen, size_t *outlen) +ssize_t +tls_read(struct tls *ctx, void *buf, size_t buflen) { + ssize_t rv = -1; int ssl_ret; - int rv = -1; - - *outlen = 0; if ((ctx->state & TLS_HANDSHAKE_COMPLETE) == 0) { if ((rv = tls_handshake(ctx)) != 0) @@ -402,24 +400,21 @@ tls_read(struct tls *ctx, void *buf, size_t buflen, size_t *outlen) } if ((ssl_ret = SSL_read(ctx->ssl_conn, buf, buflen)) > 0) { - *outlen = (size_t)ssl_ret; - rv = 0; + rv = (ssize_t)ssl_ret; goto out; } - rv = tls_ssl_error(ctx, ctx->ssl_conn, ssl_ret, "read"); + rv = (ssize_t)tls_ssl_error(ctx, ctx->ssl_conn, ssl_ret, "read"); out: errno = 0; return (rv); } -int -tls_write(struct tls *ctx, const void *buf, size_t buflen, size_t *outlen) +ssize_t +tls_write(struct tls *ctx, const void *buf, size_t buflen) { + ssize_t rv = -1; int ssl_ret; - int rv = -1; - - *outlen = 0; if ((ctx->state & TLS_HANDSHAKE_COMPLETE) == 0) { if ((rv = tls_handshake(ctx)) != 0) @@ -432,12 +427,11 @@ tls_write(struct tls *ctx, const void *buf, size_t buflen, size_t *outlen) } if ((ssl_ret = SSL_write(ctx->ssl_conn, buf, buflen)) > 0) { - *outlen = (size_t)ssl_ret; - rv = 0; + rv = (ssize_t)ssl_ret; goto out; } - rv = tls_ssl_error(ctx, ctx->ssl_conn, ssl_ret, "write"); + rv = (ssize_t)tls_ssl_error(ctx, ctx->ssl_conn, ssl_ret, "write"); out: errno = 0; return (rv); |