mirror of
https://github.com/GeyserMC/MCProtocolLib.git
synced 2024-12-04 21:01:02 -05:00
Move DnsNameResolver creation into try-catch block.
This commit is contained in:
parent
bb12069f95
commit
ead6afae39
1 changed files with 10 additions and 3 deletions
|
@ -146,11 +146,14 @@ public class TcpClientSession extends TcpSession {
|
||||||
System.out.println("[PacketLib] Attempting SRV lookup for \"" + name + "\".");
|
System.out.println("[PacketLib] Attempting SRV lookup for \"" + name + "\".");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DnsNameResolver resolver = null;
|
||||||
AddressedEnvelope<DnsResponse, InetSocketAddress> envelope = null;
|
AddressedEnvelope<DnsResponse, InetSocketAddress> envelope = null;
|
||||||
try(DnsNameResolver resolver = new DnsNameResolverBuilder(this.group.next())
|
try {
|
||||||
.channelType(NioDatagramChannel.class)
|
resolver = new DnsNameResolverBuilder(this.group.next())
|
||||||
.build()) {
|
.channelType(NioDatagramChannel.class)
|
||||||
|
.build();
|
||||||
envelope = resolver.query(new DefaultDnsQuestion(name, DnsRecordType.SRV)).get();
|
envelope = resolver.query(new DefaultDnsQuestion(name, DnsRecordType.SRV)).get();
|
||||||
|
|
||||||
DnsResponse response = envelope.content();
|
DnsResponse response = envelope.content();
|
||||||
if(response.count(DnsSection.ANSWER) > 0) {
|
if(response.count(DnsSection.ANSWER) > 0) {
|
||||||
DefaultDnsRawRecord record = response.recordAt(DnsSection.ANSWER, 0);
|
DefaultDnsRawRecord record = response.recordAt(DnsSection.ANSWER, 0);
|
||||||
|
@ -185,6 +188,10 @@ public class TcpClientSession extends TcpSession {
|
||||||
if(envelope != null) {
|
if(envelope != null) {
|
||||||
envelope.release();
|
envelope.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(resolver != null) {
|
||||||
|
resolver.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue