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

WoodyAtHome 2022-05-16 07:44:34 +02:00 committed by Jef Roosens
parent ec2346d45c
commit 8ce7860e8a
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
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
}