From cf2e29f27e4a5ef2303a3a41aa88616c0525a534 Mon Sep 17 00:00:00 2001 From: Nathan Miles Date: Fri, 2 Nov 2018 16:49:11 -0400 Subject: [PATCH] Add support for TCP_NODELAY --- src/gov/nist/javax/sip/SipStackImpl.java | 13 +++++++++++-- .../javax/sip/stack/NioTcpMessageProcessor.java | 6 ++++++ .../nist/javax/sip/stack/SIPTransactionStack.java | 2 ++ .../nist/javax/sip/stack/TCPMessageProcessor.java | 5 +++++ .../nist/javax/sip/stack/TLSMessageProcessor.java | 3 +++ 5 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/gov/nist/javax/sip/SipStackImpl.java b/src/gov/nist/javax/sip/SipStackImpl.java index 093f98350..aef627ae3 100755 --- a/src/gov/nist/javax/sip/SipStackImpl.java +++ b/src/gov/nist/javax/sip/SipStackImpl.java @@ -564,8 +564,11 @@ * A Disabled value will not require a certificate chain for the Server Connection. A DisabledAll will not require a certificate chain for both Server and Client Connections. * * - *
  • gov.nist.javax.sip.RELIABLE_CONNECTION_KEEP_ALIVE_TIMEOUT Value in seconds which is used as default keepalive timeout - * (See also http://tools.ietf.org/html/rfc5626#section-4.4.1). Defaults to "infiinity" seconds (i.e. timeout event not delivered).
  • + *
  • gov.nist.javax.sip.RELIABLE_CONNECTION_KEEP_ALIVE_TIMEOUT Value in seconds which is used as default keepalive timeout + * (See also http://tools.ietf.org/html/rfc5626#section-4.4.1). Defaults to "infinity" seconds (i.e. timeout event not delivered).
  • + * + *
  • gov.nist.javax.sip.TCP_NODELAY = [true|false] + * Whether or not to disable Nagle's algorithm for TCP sockets. Defaults to {@code false}.
  • * *
  • gov.nist.javax.sip.SSL_HANDSHAKE_TIMEOUT Value in seconds which is used as default timeout for performing the SSL Handshake * This prevents bad clients of connecting without sending any data to block the server
  • @@ -1103,6 +1106,12 @@ public SipStackImpl(Properties configurationProperties) } } + String isTcpNoDelayEnabled = configurationProperties + .getProperty("gov.nist.javax.sip.TCP_NODELAY"); + if (isTcpNoDelayEnabled != null) { + this.isTcpNoDelayEnabled = Boolean.parseBoolean(isTcpNoDelayEnabled); + } + String serverTransactionTableSize = configurationProperties .getProperty("gov.nist.javax.sip.MAX_SERVER_TRANSACTIONS"); if (serverTransactionTableSize != null) { diff --git a/src/gov/nist/javax/sip/stack/NioTcpMessageProcessor.java b/src/gov/nist/javax/sip/stack/NioTcpMessageProcessor.java index 13a267747..62b856e23 100644 --- a/src/gov/nist/javax/sip/stack/NioTcpMessageProcessor.java +++ b/src/gov/nist/javax/sip/stack/NioTcpMessageProcessor.java @@ -33,6 +33,7 @@ import java.io.IOException; import java.net.InetAddress; import java.net.InetSocketAddress; +import java.net.StandardSocketOptions; import java.nio.ByteBuffer; import java.nio.channels.*; import java.util.*; @@ -237,6 +238,11 @@ public void accept(SelectionKey selectionKey) throws IOException{ ServerSocketChannel serverSocketChannel = (ServerSocketChannel) selectionKey.channel(); SocketChannel client; client = serverSocketChannel.accept(); + + if (sipStack.isTcpNoDelayEnabled) { + client.setOption(StandardSocketOptions.TCP_NODELAY, true); + } + client.configureBlocking(false); if(logger.isLoggingEnabled(LogWriter.TRACE_DEBUG)) logger.logDebug("got a new connection! " + client); diff --git a/src/gov/nist/javax/sip/stack/SIPTransactionStack.java b/src/gov/nist/javax/sip/stack/SIPTransactionStack.java index adb4d3195..81c44e6f3 100755 --- a/src/gov/nist/javax/sip/stack/SIPTransactionStack.java +++ b/src/gov/nist/javax/sip/stack/SIPTransactionStack.java @@ -351,6 +351,8 @@ public abstract class SIPTransactionStack implements protected boolean isDialogTerminatedEventDeliveredForNullDialog = false; + protected boolean isTcpNoDelayEnabled = false; + // Max time for a forked response to arrive. After this time, the original // dialog // is not tracked. If you want to track the original transaction you need to diff --git a/src/gov/nist/javax/sip/stack/TCPMessageProcessor.java b/src/gov/nist/javax/sip/stack/TCPMessageProcessor.java index c2ddbe122..30ec28864 100755 --- a/src/gov/nist/javax/sip/stack/TCPMessageProcessor.java +++ b/src/gov/nist/javax/sip/stack/TCPMessageProcessor.java @@ -122,6 +122,11 @@ public void run() { } Socket newsock = sock.accept(); + + if (sipStack.isTcpNoDelayEnabled) { + newsock.setTcpNoDelay(true); + } + if (logger.isLoggingEnabled(LogWriter.TRACE_DEBUG)) { logger.logDebug("Accepting new connection!"); } diff --git a/src/gov/nist/javax/sip/stack/TLSMessageProcessor.java b/src/gov/nist/javax/sip/stack/TLSMessageProcessor.java index 5591305a0..c98a1e5b4 100755 --- a/src/gov/nist/javax/sip/stack/TLSMessageProcessor.java +++ b/src/gov/nist/javax/sip/stack/TLSMessageProcessor.java @@ -159,6 +159,9 @@ public void run() { } newsock = sock.accept(); + if (sipStack.isTcpNoDelayEnabled) { + newsock.setTcpNoDelay(true); + } if (logger.isLoggingEnabled(LogWriter.TRACE_DEBUG)) { logger.logDebug("Accepting new connection!");