From a5005789ff4cfc989e2eccc4213beda88ce3157c Mon Sep 17 00:00:00 2001 From: yhirose Date: Sat, 25 Apr 2020 17:13:14 -0400 Subject: [PATCH] Fixed Visual Studio compiler warnings with x64 platform (Resolve #440 and #446) (#448) --- httplib.h | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/httplib.h b/httplib.h index 1985123..56a70c1 100644 --- a/httplib.h +++ b/httplib.h @@ -2936,13 +2936,25 @@ inline bool SocketStream::is_writable() const { } inline ssize_t SocketStream::read(char *ptr, size_t size) { - if (is_readable()) { return recv(sock_, ptr, size, 0); } - return -1; + if (!is_readable()) { return -1; } + +#ifdef _WIN32 + if (size > static_cast(std::numeric_limits::max())) { return -1; } + return recv(sock_, ptr, static_cast(size), 0); +#else + return recv(sock_, ptr, size, 0); +#endif } inline ssize_t SocketStream::write(const char *ptr, size_t size) { - if (is_writable()) { return send(sock_, ptr, size, 0); } - return -1; + if (!is_writable()) { return -1; } + +#ifdef _WIN32 + if (size > static_cast(std::numeric_limits::max())) { return -1; } + return send(sock_, ptr, static_cast(size), 0); +#else + return send(sock_, ptr, size, 0); +#endif } inline void SocketStream::get_remote_ip_and_port(std::string &ip,