|
83 | 83 | local function connect(host, timeout) |
84 | 84 | local protocol, host, port = check_protocol(host) |
85 | 85 | local hostaddr = host |
86 | | - if async_dns and host:find "^[^:]-%D$" then |
87 | | - -- if ipv6, contains colons |
88 | | - -- if ipv4, end with a digit |
89 | | - local msg |
90 | | - hostaddr, msg = dns.resolve(host) |
91 | | - if not hostaddr then |
92 | | - error(string.format("%s dns resolve failed msg:%s", host, msg)) |
| 86 | + local hostname |
| 87 | + if host:find "^[^:]-%D$" then |
| 88 | + -- it's a hostname (not ip address), because |
| 89 | + -- ipv6 contains colons |
| 90 | + -- ipv4 end with a digit |
| 91 | + hostname = host |
| 92 | + if async_dns then |
| 93 | + local msg |
| 94 | + hostaddr, msg = dns.resolve(host) |
| 95 | + if not hostaddr then |
| 96 | + error(string.format("%s dns resolve failed msg:%s", host, msg)) |
| 97 | + end |
93 | 98 | end |
94 | 99 | end |
95 | 100 |
|
96 | 101 | local fd = socket.connect(hostaddr, port, timeout) |
97 | 102 | if not fd then |
98 | 103 | error(string.format("%s connect error host:%s, port:%s, timeout:%s", protocol, host, port, timeout)) |
99 | 104 | end |
100 | | - local interface = gen_interface(protocol, fd, host) |
| 105 | + local interface = gen_interface(protocol, fd, hostname) |
101 | 106 | if timeout then |
102 | 107 | skynet.timeout(timeout, function() |
103 | 108 | if not interface.finish then |
|
0 commit comments