mirror of
https://github.com/yhirose/cpp-httplib
synced 2024-11-21 06:26:02 -07:00
parent
35ef1c7bae
commit
c7554ccac2
1 changed files with 24 additions and 1 deletions
25
httplib.h
25
httplib.h
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue