mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
return actual port if bind to any (0)
This commit is contained in:
@@ -57,8 +57,8 @@ public class WebServer {
|
||||
bootstrap.setOption("child.tcpNoDelay", true);
|
||||
bootstrap.setPipelineFactory(new ChannelPipelineFactoryImpl(pipelineConsumers, new DefaultHandler(openChannels)));
|
||||
|
||||
for (int i = 0, n = tryAnyPort ? portsCount : portsCount + 1; i < n; i++) {
|
||||
int port = i == portsCount ? 0 : firstPort + i;
|
||||
for (int i = 0; i < portsCount; i++) {
|
||||
int port = firstPort + i;
|
||||
try {
|
||||
openChannels.add(bootstrap.bind(new InetSocketAddress(port)));
|
||||
return port;
|
||||
@@ -67,12 +67,23 @@ public class WebServer {
|
||||
if (portsCount == 1) {
|
||||
throw e;
|
||||
}
|
||||
else if (i == (n - 1)) {
|
||||
else if (!tryAnyPort && i == (portsCount - 1)) {
|
||||
LOG.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (tryAnyPort) {
|
||||
try {
|
||||
Channel channel = bootstrap.bind(new InetSocketAddress(0));
|
||||
openChannels.add(channel);
|
||||
return ((InetSocketAddress)channel.getLocalAddress()).getPort();
|
||||
}
|
||||
catch (ChannelException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user