Move DnsNameResolver creation into try-catch block.

This commit is contained in:
Steveice10 2020-11-21 12:59:51 -08:00
parent bb12069f95
commit ead6afae39

View file

@ -146,11 +146,14 @@ public class TcpClientSession extends TcpSession {
System.out.println("[PacketLib] Attempting SRV lookup for \"" + name + "\".");
}
DnsNameResolver resolver = null;
AddressedEnvelope<DnsResponse, InetSocketAddress> envelope = null;
try(DnsNameResolver resolver = new DnsNameResolverBuilder(this.group.next())
.channelType(NioDatagramChannel.class)
.build()) {
try {
resolver = new DnsNameResolverBuilder(this.group.next())
.channelType(NioDatagramChannel.class)
.build();
envelope = resolver.query(new DefaultDnsQuestion(name, DnsRecordType.SRV)).get();
DnsResponse response = envelope.content();
if(response.count(DnsSection.ANSWER) > 0) {
DefaultDnsRawRecord record = response.recordAt(DnsSection.ANSWER, 0);
@ -185,6 +188,10 @@ public class TcpClientSession extends TcpSession {
if(envelope != null) {
envelope.release();
}
if(resolver != null) {
resolver.close();
}
}
}