mirror of
https://github.com/yhirose/cpp-httplib
synced 2024-11-21 06:26:02 -07:00
This commit is contained in:
parent
fae30af47d
commit
a5005789ff
1 changed files with 16 additions and 4 deletions
20
httplib.h
20
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,
|
||||
|
|
Loading…
Reference in a new issue