Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WFCORE-3296 Ephemeral port number (port="0") should not be affected b… #3726

Merged
merged 1 commit into from
Apr 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 7 additions & 5 deletions network/src/main/java/org/jboss/as/network/SocketBinding.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ public SocketBindingManager getSocketBindings() {

private int calculatePort() {
int port = this.port;
if (!isFixedPort) {
// 0 is a reserved port number indicating usage of system-allocated dynamic ports
// and thus port offset must not be applied
if (!isFixedPort && port != 0) {
port += socketBindings.getPortOffset();
}
return port;
Expand Down Expand Up @@ -265,11 +267,11 @@ public List<ClientMapping> getClientMappings() {
}

/**
* Unlike the {@link #getPort()} method, this method takes into account the port offset, if the port
* is <i>not</i> a fixed port and returns the absolute port number which is the sum of the port offset
* and the (relative) port.
* Unlike the {@link #getPort()} method, this method takes into account the port offset, if the port is <i>not</i> a fixed
* port nor dynamically allocated ephemeral port (port number 0) and returns the absolute port number which is the sum of
* the port offset and the (relative) port.
*
* @return port number configured for this socket binding taking port-offset into account
* @return port number configured for this socket binding taking port-offset into account when appropriate
*/
public int getAbsolutePort() {
return calculatePort();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ public void testPortOffsetZero() throws Exception {
Assert.assertEquals(8000, socketBinding.getSocketBindings().getPortOffset());
Assert.assertFalse("fixed port", socketBinding.isFixedPort());
Assert.assertEquals(0, socketBinding.getPort());
Assert.assertEquals(8000, socketBinding.getSocketAddress().getPort());
// Port 0 must not be affected by port-offset
Assert.assertEquals(0, socketBinding.getSocketAddress().getPort());
}

/**
Expand Down