mirror of
https://github.com/libevent/libevent.git
synced 2025-01-31 09:12:55 +08:00
Deal with partial writes on SSL write
SSL write may do partial writes in some cases. For example, document of mbedtls_ssl_write says: If the return value is non-negative but less than length, the function must be called again with updated arguments: buf + ret, len - ret (if ret is the return value) until it returns a value equal to the last 'len' argument. In case of partial writes, we should continue writing the same chain of buffer, not the next chain.
This commit is contained in:
parent
9203d98ff8
commit
fc568ff045
@ -339,15 +339,17 @@ do_write(struct bufferevent_ssl *bev_ssl, int atmost)
|
||||
|
||||
if (n > 8)
|
||||
n = 8;
|
||||
for (i=0; i < n; ++i) {
|
||||
for (i=0; i < n;) {
|
||||
if (bev_ssl->bev.write_suspended)
|
||||
break;
|
||||
|
||||
/* SSL_write will (reasonably) return 0 if we tell it to
|
||||
send 0 data. Skip this case so we don't interpret the
|
||||
result as an error */
|
||||
if (space[i].iov_len == 0)
|
||||
if (space[i].iov_len == 0) {
|
||||
++i;
|
||||
continue;
|
||||
}
|
||||
|
||||
bev_ssl->ssl_ops->clear_error();
|
||||
r = bev_ssl->ssl_ops->write(bev_ssl->ssl, space[i].iov_base,
|
||||
@ -360,6 +362,10 @@ do_write(struct bufferevent_ssl *bev_ssl, int atmost)
|
||||
n_written += r;
|
||||
bev_ssl->last_write = -1;
|
||||
bev_ssl->ssl_ops->decrement_buckets(bev_ssl);
|
||||
space[i].iov_base = (unsigned char *)space[i].iov_base + r;
|
||||
space[i].iov_len -= r;
|
||||
if (space[i].iov_len == 0)
|
||||
++i;
|
||||
} else {
|
||||
int err = bev_ssl->ssl_ops->get_error(bev_ssl->ssl, r);
|
||||
bev_ssl->ssl_ops->print_err(err);
|
||||
|
Loading…
x
Reference in New Issue
Block a user