Skip to content

Commit c7554cc

Browse files
authored
Fix #1069 (#1070)
1 parent 35ef1c7 commit c7554cc

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

httplib.h

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6997,7 +6997,30 @@ inline ssize_t SSLSocketStream::read(char *ptr, size_t size) {
69976997
}
69986998

69996999
inline ssize_t SSLSocketStream::write(const char *ptr, size_t size) {
7000-
if (is_writable()) { return SSL_write(ssl_, ptr, static_cast<int>(size)); }
7000+
if (is_writable()) {
7001+
auto ret = SSL_write(ssl_, ptr, static_cast<int>(size));
7002+
if (ret < 0) {
7003+
auto err = SSL_get_error(ssl_, ret);
7004+
int n = 1000;
7005+
#ifdef _WIN32
7006+
while (--n >= 0 &&
7007+
(err == SSL_ERROR_WANT_WRITE ||
7008+
err == SSL_ERROR_SYSCALL && WSAGetLastError() == WSAETIMEDOUT)) {
7009+
#else
7010+
while (--n >= 0 && err == SSL_ERROR_WANT_WRITE) {
7011+
#endif
7012+
if (is_writable()) {
7013+
std::this_thread::sleep_for(std::chrono::milliseconds(1));
7014+
ret = SSL_write(ssl_, ptr, static_cast<int>(size));
7015+
if (ret >= 0) { return ret; }
7016+
err = SSL_get_error(ssl_, ret);
7017+
} else {
7018+
return -1;
7019+
}
7020+
}
7021+
}
7022+
return ret;
7023+
}
70017024
return -1;
70027025
}
70037026

0 commit comments

Comments
 (0)