diff --git a/src/common/tortls.c b/src/common/tortls.c index 7f601258c4..51c4abe247 100644 --- a/src/common/tortls.c +++ b/src/common/tortls.c @@ -850,7 +850,14 @@ tor_tls_get_pending_bytes(tor_tls_t *tls) return 0; #endif return SSL_pending(tls->ssl); +} +/** If tls requires that the next write be of a particular size, + * return that size. Otherwise, return 0. */ +size_t +tor_tls_get_forced_write_size(tor_tls_t *tls) +{ + return tls->wantwrite_n; } /** Return the number of bytes read across the underlying socket. */ diff --git a/src/common/tortls.h b/src/common/tortls.h index 2569abf79c..dea072a338 100644 --- a/src/common/tortls.h +++ b/src/common/tortls.h @@ -41,6 +41,7 @@ int tor_tls_write(tor_tls_t *tls, char *cp, size_t n); int tor_tls_handshake(tor_tls_t *tls); int tor_tls_shutdown(tor_tls_t *tls); int tor_tls_get_pending_bytes(tor_tls_t *tls); +size_t tor_tls_get_forced_write_size(tor_tls_t *tls); unsigned long tor_tls_get_n_bytes_read(tor_tls_t *tls); unsigned long tor_tls_get_n_bytes_written(tor_tls_t *tls); diff --git a/src/or/buffers.c b/src/or/buffers.c index 55120c60a7..aeca8b0ec3 100644 --- a/src/or/buffers.c +++ b/src/or/buffers.c @@ -648,16 +648,21 @@ flush_buf(int s, buf_t *buf, size_t sz, size_t *buf_flushlen) return flushed; } -/** Helper for flush_buf_tls(): try to write sz bytes from buffer - * buf onto TLS object tls. On success, deduct the bytes - * written from *buf_flushlen. - * Return the number of bytes written on success, -1 on failure. +/** Helper for flush_buf_tls(): try to write sz bytes (or more if + * required by a previous write) from buffer buf onto TLS object + * tls. On success, deduct the bytes written from + * *buf_flushlen. Return the number of bytes written on success, -1 on + * failure. */ static INLINE int flush_buf_tls_impl(tor_tls_t *tls, buf_t *buf, size_t sz, size_t *buf_flushlen) { int r; + size_t forced; + forced = tor_tls_get_forced_write_size(tls); + if (forced < sz) + sz = forced; r = tor_tls_write(tls, buf->cur, sz); if (r < 0) { return r;