This commit is contained in:
yhirose 2020-04-30 19:40:23 -04:00
parent 8333340e2c
commit 08fc7085e5
2 changed files with 13 additions and 11 deletions

View file

@ -1515,8 +1515,8 @@ inline bool bind_ip_address(socket_t sock, const char *host) {
return ret;
}
inline std::string if2ip(const std::string &ifn) {
#ifndef _WIN32
inline std::string if2ip(const std::string &ifn) {
struct ifaddrs *ifap;
getifaddrs(&ifap);
for (auto ifa = ifap; ifa; ifa = ifa->ifa_next) {
@ -1532,9 +1532,9 @@ inline std::string if2ip(const std::string &ifn) {
}
}
freeifaddrs(ifap);
#endif
return std::string();
}
#endif
inline socket_t create_client_socket(const char *host, int port,
time_t timeout_sec,
@ -1542,9 +1542,11 @@ inline socket_t create_client_socket(const char *host, int port,
return create_socket(
host, port, [&](socket_t sock, struct addrinfo &ai) -> bool {
if (!intf.empty()) {
#ifndef _WIN32
auto ip = if2ip(intf);
if (ip.empty()) { ip = intf; }
if (!bind_ip_address(sock, ip.c_str())) { return false; }
#endif
}
set_nonblocking(sock, true);
@ -2849,11 +2851,11 @@ inline void Response::set_header(const char *key, const std::string &val) {
}
}
inline void Response::set_redirect(const char *url, int status) {
inline void Response::set_redirect(const char *url, int stat) {
if (!detail::has_crlf(url)) {
set_header("Location", url);
if (300 <= status && status < 400) {
this->status = status;
if (300 <= stat && stat < 400) {
this->status = stat;
} else {
this->status = 302;
}

View file

@ -91,7 +91,7 @@
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<WarningLevel>Level4</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>./;../</AdditionalIncludeDirectories>
@ -108,7 +108,7 @@
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<WarningLevel>Level4</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>./;../</AdditionalIncludeDirectories>
@ -118,12 +118,12 @@
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>Ws2_32.lib;AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>Ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<WarningLevel>Level4</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
@ -144,7 +144,7 @@
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<WarningLevel>Level4</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
@ -171,4 +171,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>