Browse Source

Fixed Visual Studio compiler warnings with x64 platform (Resolve #440 and #446) (#448)

yhirose 5 years ago
parent
commit
a5005789ff
1 changed files with 16 additions and 4 deletions
  1. 16 4
      httplib.h

+ 16 - 4
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<size_t>(std::numeric_limits<int>::max())) { return -1; }
+  return recv(sock_, ptr, static_cast<int>(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<size_t>(std::numeric_limits<int>::max())) { return -1; }
+  return send(sock_, ptr, static_cast<int>(size), 0);
+#else
+  return send(sock_, ptr, size, 0);
+#endif
 }
 
 inline void SocketStream::get_remote_ip_and_port(std::string &ip,