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,