Handle partial data re-sending on ktls/sendfile on FreeBSD

Add a handler for EBUSY sendfile error in addition to
EAGAIN. With EBUSY returned the data still can be partially
sent and user code has to be notified about it, otherwise it
may try to send data multiple times.

PR:		251969
Reviewed by:	jkim
Obtained from:	OpenSSL (dfcfd17f2818cf520ce6381aed9ec3d2fc12170d)
MFC after:	1 week
Sponsored by:	Netflix (merging to FreeBSD)
Differential Revision:	https://reviews.freebsd.org/D28714
This commit is contained in:
Oleksandr Tymoshenko 2021-02-17 14:49:30 -08:00 committed by John Baldwin
parent d616ae46b4
commit 9b2f020c14
2 changed files with 5 additions and 7 deletions

View File

@ -120,7 +120,8 @@ For SSL_sendfile(), the following return values can occur:
=item Z<>>= 0
The write operation was successful, the return value is the number
of bytes of the file written to the TLS/SSL connection.
of bytes of the file written to the TLS/SSL connection. The return
value can be less than B<size> for a partial write.
=item E<lt> 0

View File

@ -192,15 +192,12 @@ static ossl_inline int ktls_read_record(int fd, void *data, size_t length)
static ossl_inline ossl_ssize_t ktls_sendfile(int s, int fd, off_t off,
size_t size, int flags)
{
off_t sbytes;
off_t sbytes = 0;
int ret;
ret = sendfile(fd, s, off, size, NULL, &sbytes, flags);
if (ret == -1) {
if (errno == EAGAIN && sbytes != 0)
return sbytes;
if (ret == -1 && sbytes == 0)
return -1;
}
return sbytes;
}