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 mut res := 0
for { for {
res = C.SSL_read(voidptr(s.ssl), buf_ptr, len) 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)? err_res := ssl_error(res, s.ssl)?
if err_res == .ssl_error_want_read { match err_res {
for { .ssl_error_want_read {
ready := @select(s.handle, .read, s.duration)? ready := @select(s.handle, .read, s.duration)?
if ready { if !ready {
break return net.err_timed_out
} }
} }
continue .ssl_error_want_write {
} else if err_res == .ssl_error_want_write {
for {
ready := @select(s.handle, .write, s.duration)? ready := @select(s.handle, .write, s.duration)?
if ready { if !ready {
break return net.err_timed_out
} }
} }
continue .ssl_error_zero_return {
} else if err_res == .ssl_error_zero_return { return 0
return 0 }
else {
return error('Could not read using SSL. ($err_res)')
}
} }
return error('Could not read using SSL. ($err_res)')
} }
break
} }
return res return res
} }