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

This commit is contained in:
yhirose 2020-04-25 17:13:14 -04:00 committed by GitHub
parent fae30af47d
commit a5005789ff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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,