Skip to content

Commit 5f6fa96

Browse files
authored
Fix localhost resolving on windows (#82)
1 parent 5ce4e16 commit 5f6fa96

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

trantor/net/InetAddress.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
#ifdef _WIN32
1515
struct in6_addr_uint
1616
{
17-
union {
17+
union
18+
{
1819
u_char Byte[16];
1920
u_short Word[8];
2021
uint32_t __s6_addr32[4];

trantor/net/InetAddress.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ class InetAddress
100100
}
101101

102102
private:
103-
union {
103+
union
104+
{
104105
struct sockaddr_in addr_;
105106
struct sockaddr_in6 addr6_;
106107
};

trantor/net/inner/AresResolver.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,14 @@ void AresResolver::resolveInLoop(const std::string& hostname,
106106
const Callback& cb)
107107
{
108108
loop_->assertInLoopThread();
109+
#ifdef _WIN32
110+
if (hostname == "localhost")
111+
{
112+
const static trantor::InetAddress localhost_{"127.0.0.1", 0};
113+
cb(localhost_);
114+
return;
115+
}
116+
#endif
109117
init();
110118
QueryData* queryData = new QueryData(this, cb, hostname);
111119
ares_gethostbyname(ctx_,

0 commit comments

Comments
 (0)