Skip to content

Commit

Permalink
Merge pull request usnistgov#41 from namiles/tcp-no-delay
Browse files Browse the repository at this point in the history
Add support for TCP_NODELAY
  • Loading branch information
ranganathanm authored Nov 3, 2018
2 parents 908ae60 + cf2e29f commit eba9caf
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/gov/nist/javax/sip/SipStackImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
* </li>
*
*<li><b>gov.nist.javax.sip.RELIABLE_CONNECTION_KEEP_ALIVE_TIMEOUT</b> 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).</li>
* <li><b>gov.nist.javax.sip.RELIABLE_CONNECTION_KEEP_ALIVE_TIMEOUT</b> 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).</li>
*
* <li><b>gov.nist.javax.sip.TCP_NODELAY = [true|false]</b>
* Whether or not to disable Nagle's algorithm for TCP sockets. Defaults to {@code false}.</li>
*
* <li><b>gov.nist.javax.sip.SSL_HANDSHAKE_TIMEOUT</b> 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</li>
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 6 additions & 0 deletions src/gov/nist/javax/sip/stack/NioTcpMessageProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/gov/nist/javax/sip/stack/SIPTransactionStack.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/gov/nist/javax/sip/stack/TCPMessageProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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!");
}
Expand Down
3 changes: 3 additions & 0 deletions src/gov/nist/javax/sip/stack/TLSMessageProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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!");
Expand Down

0 comments on commit eba9caf

Please sign in to comment.