close socket if exception occurs too
This commit is contained in:
parent
fc9219ed80
commit
492e5ee72f
|
@ -23,6 +23,8 @@ proc getPrimaryIPAddr*(dest = parseIpAddress("8.8.8.8")): IpAddress =
|
||||||
newSocket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)
|
newSocket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)
|
||||||
else:
|
else:
|
||||||
newSocket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP)
|
newSocket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP)
|
||||||
|
try:
|
||||||
socket.connect($dest, 80.Port)
|
socket.connect($dest, 80.Port)
|
||||||
result = socket.getLocalAddr()[0].parseIpAddress()
|
result = socket.getLocalAddr()[0].parseIpAddress()
|
||||||
|
finally:
|
||||||
socket.close()
|
socket.close()
|
||||||
|
|
Loading…
Reference in New Issue