This commit is contained in:
yhirose 2021-10-09 20:35:58 -04:00 committed by GitHub
parent 35ef1c7bae
commit c7554ccac2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -6997,7 +6997,30 @@ inline ssize_t SSLSocketStream::read(char *ptr, size_t size) {
}
inline ssize_t SSLSocketStream::write(const char *ptr, size_t size) {
if (is_writable()) { return SSL_write(ssl_, ptr, static_cast<int>(size)); }
if (is_writable()) {
auto ret = SSL_write(ssl_, ptr, static_cast<int>(size));
if (ret < 0) {
auto err = SSL_get_error(ssl_, ret);
int n = 1000;
#ifdef _WIN32
while (--n >= 0 &&
(err == SSL_ERROR_WANT_WRITE ||
err == SSL_ERROR_SYSCALL && WSAGetLastError() == WSAETIMEDOUT)) {
#else
while (--n >= 0 && err == SSL_ERROR_WANT_WRITE) {
#endif
if (is_writable()) {
std::this_thread::sleep_for(std::chrono::milliseconds(1));
ret = SSL_write(ssl_, ptr, static_cast<int>(size));
if (ret >= 0) { return ret; }
err = SSL_get_error(ssl_, ret);
} else {
return -1;
}
}
}
return ret;
}
return -1;
}