net.openssl: read doesn't block infinitely (#14406)

master
WoodyAtHome 2022-05-16 07:44:34 +02:00 committed by GitHub
parent c01a8a1737
commit eeff02a8ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 15 deletions

View File

@ -151,30 +151,31 @@ pub fn (mut s SSLConn) socket_read_into_ptr(buf_ptr &u8, len int) ?int {
mut res := 0
for {
res = C.SSL_read(voidptr(s.ssl), buf_ptr, len)
if res < 0 {
if res >= 0 {
return res
} else {
err_res := ssl_error(res, s.ssl)?
if err_res == .ssl_error_want_read {
for {
match err_res {
.ssl_error_want_read {
ready := @select(s.handle, .read, s.duration)?
if ready {
break
if !ready {
return net.err_timed_out
}
}
continue
} else if err_res == .ssl_error_want_write {
for {
.ssl_error_want_write {
ready := @select(s.handle, .write, s.duration)?
if ready {
break
if !ready {
return net.err_timed_out
}
}
continue
} else if err_res == .ssl_error_zero_return {
return 0
.ssl_error_zero_return {
return 0
}
else {
return error('Could not read using SSL. ($err_res)')
}
}
return error('Could not read using SSL. ($err_res)')
}
break
}
return res
}