This commit is contained in:
yhirose 2019-06-04 22:53:37 -04:00
parent 48af26e332
commit 6f207497de

View file

@ -87,6 +87,8 @@ typedef int socket_t;
#define CPPHTTPLIB_KEEPALIVE_TIMEOUT_SECOND 5
#define CPPHTTPLIB_KEEPALIVE_TIMEOUT_USECOND 0
#define CPPHTTPLIB_KEEPALIVE_MAX_COUNT 5
#define CPPHTTPLIB_READ_TIMEOUT_SECOND 5
#define CPPHTTPLIB_READ_TIMEOUT_USECOND 0
#define CPPHTTPLIB_REQUEST_URI_MAX_LENGTH 8192
#define CPPHTTPLIB_PAYLOAD_MAX_LENGTH std::numeric_limits<size_t>::max()
@ -1432,7 +1434,11 @@ inline SocketStream::SocketStream(socket_t sock) : sock_(sock) {}
inline SocketStream::~SocketStream() {}
inline int SocketStream::read(char *ptr, size_t size) {
return recv(sock_, ptr, static_cast<int>(size), 0);
if (detail::select_read(sock_, CPPHTTPLIB_READ_TIMEOUT_SECOND,
CPPHTTPLIB_READ_TIMEOUT_USECOND) > 0) {
return recv(sock_, ptr, static_cast<int>(size), 0);
}
return -1;
}
inline int SocketStream::write(const char *ptr, size_t size) {
@ -2310,7 +2316,12 @@ inline SSLSocketStream::SSLSocketStream(socket_t sock, SSL *ssl)
inline SSLSocketStream::~SSLSocketStream() {}
inline int SSLSocketStream::read(char *ptr, size_t size) {
return SSL_read(ssl_, ptr, size);
if (SSL_pending(ssl_) > 0 ||
detail::select_read(sock_, CPPHTTPLIB_READ_TIMEOUT_SECOND,
CPPHTTPLIB_READ_TIMEOUT_USECOND) > 0) {
return SSL_read(ssl_, ptr, size);
}
return -1;
}
inline int SSLSocketStream::write(const char *ptr, size_t size) {