Skip to content

Commit 5d87cc0

Browse files
authored
resolve compiler warnings (yhirose#1246)
* resolve compiler warnings - check `WSAStartup` return. - `const` is not suitable for `std::move`. * resolve compiler warnings - bool startup => bool is_valid_. - remove `const` not removed.
1 parent cb41947 commit 5d87cc0

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

httplib.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -974,7 +974,7 @@ class ClientImpl {
974974

975975
void stop();
976976

977-
void set_hostname_addr_map(const std::map<std::string, std::string> addr_map);
977+
void set_hostname_addr_map(std::map<std::string, std::string> addr_map);
978978

979979
void set_default_headers(Headers headers);
980980

@@ -1309,7 +1309,7 @@ class Client {
13091309

13101310
void stop();
13111311

1312-
void set_hostname_addr_map(const std::map<std::string, std::string> addr_map);
1312+
void set_hostname_addr_map(std::map<std::string, std::string> addr_map);
13131313

13141314
void set_default_headers(Headers headers);
13151315

@@ -4231,10 +4231,12 @@ class WSInit {
42314231
public:
42324232
WSInit() {
42334233
WSADATA wsaData;
4234-
WSAStartup(0x0002, &wsaData);
4234+
if (WSAStartup(0x0002, &wsaData) == 0) is_valid_ = true;
42354235
}
42364236

4237-
~WSInit() { WSACleanup(); }
4237+
~WSInit() { if (is_valid_) WSACleanup(); }
4238+
4239+
bool is_valid_ = false;
42384240
};
42394241

42404242
static WSInit wsinit_;
@@ -6969,7 +6971,7 @@ inline void ClientImpl::set_follow_location(bool on) { follow_location_ = on; }
69696971
inline void ClientImpl::set_url_encode(bool on) { url_encode_ = on; }
69706972

69716973
inline void ClientImpl::set_hostname_addr_map(
6972-
const std::map<std::string, std::string> addr_map) {
6974+
std::map<std::string, std::string> addr_map) {
69736975
addr_map_ = std::move(addr_map);
69746976
}
69756977

@@ -8095,7 +8097,7 @@ inline size_t Client::is_socket_open() const { return cli_->is_socket_open(); }
80958097
inline void Client::stop() { cli_->stop(); }
80968098

80978099
inline void Client::set_hostname_addr_map(
8098-
const std::map<std::string, std::string> addr_map) {
8100+
std::map<std::string, std::string> addr_map) {
80998101
cli_->set_hostname_addr_map(std::move(addr_map));
81008102
}
81018103

0 commit comments

Comments
 (0)