diff --git a/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpTransport.java b/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpTransport.java index 0c6befd68f..0ac4bc721d 100755 --- a/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpTransport.java +++ b/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpTransport.java @@ -129,7 +129,7 @@ public class TcpTransport extends TransportThreadSupport implements Transport, S protected final AtomicReference stoppedLatch = new AtomicReference(); private Map socketOptions; - private int soLinger = -1; + private int soLinger = Integer.MIN_VALUE; private Boolean keepAlive; private Boolean tcpNoDelay; private Thread runnerThread; @@ -360,8 +360,8 @@ public class TcpTransport extends TransportThreadSupport implements Transport, S } /** - * Enable soLinger with the specified soLinger - * @param soLinger enabled if > -1 + * Enable/disable soLinger + * @param soLinger enabled if > -1, disabled if == -1, system default otherwise */ public void setSoLinger(int soLinger) { this.soLinger = soLinger; @@ -448,8 +448,10 @@ public class TcpTransport extends TransportThreadSupport implements Transport, S sock.setKeepAlive(keepAlive.booleanValue()); } - if (soLinger != -1) { + if (soLinger > -1) { sock.setSoLinger(true, soLinger); + } else if (soLinger == -1) { + sock.setSoLinger(false, 0); } if (tcpNoDelay != null) { sock.setTcpNoDelay(tcpNoDelay.booleanValue()); diff --git a/activemq-core/src/test/java/org/apache/activemq/transport/tcp/TransportUriTest.java b/activemq-core/src/test/java/org/apache/activemq/transport/tcp/TransportUriTest.java index 4ab1c3f21e..d1cbfaa5b6 100644 --- a/activemq-core/src/test/java/org/apache/activemq/transport/tcp/TransportUriTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/transport/tcp/TransportUriTest.java @@ -139,6 +139,8 @@ public class TransportUriTest extends EmbeddedBrokerTestSupport { // TODO: Add more combinations. addCombinationValues("postfix", new Object[] {"?tcpNoDelay=true&keepAlive=true&soLinger=0"}); + addCombinationValues("postfix", new Object[] + {"?tcpNoDelay=true&keepAlive=true&soLinger=-1"}); } private void testValidOptionsWork(String options, String msg) {