Revision: 70a68f2d3507
Author:   vralev <vralev@8e71dc83-d81e-6649-80f2-80b843a9b2be>
Date:     Fri Apr 27 05:16:21 2012
Log: Fix NIO UAC rapid outbound sockets race condition(3rd try) http://java.net/jira/browse/JSIP-416

git-svn-id: https://svn.java.net/svn/jsip~svn/branches/JAIN-SIP-NIO-year-2012@2104 8e71dc83-d81e-6649-80f2-80b843a9b2be

http://code.google.com/p/jain-sip/source/detail?r=70a68f2d3507

Modified:
 /src/gov/nist/javax/sip/stack/NIOHandler.java
 /src/gov/nist/javax/sip/stack/NioTcpMessageChannel.java

=======================================
--- /src/gov/nist/javax/sip/stack/NIOHandler.java       Wed Apr 25 14:50:23 2012
+++ /src/gov/nist/javax/sip/stack/NIOHandler.java       Fri Apr 27 05:16:21 2012
@@ -424,6 +424,12 @@
// UAC case with rapid outbound socket creation might end up overwriting the assigned socket public synchronized SocketChannel createOrReuseSocket(InetAddress inetAddress, int port) throws IOException { SocketChannel channel = getSocket(NIOHandler.makeKey(inetAddress, port));
+       if(channel != null && !channel.isConnected()) {
+               if(logger.isLoggingEnabled(LogWriter.TRACE_DEBUG))
+                               logger.logDebug("Channel disconnected " + 
channel);
+
+               channel = null;
+       }
                if(channel == null) { // this is where the threads will race
                        SocketAddress sockAddr = new 
InetSocketAddress(inetAddress, port);
channel = messageProcessor.blockingConnect((InetSocketAddress) sockAddr, 10000);
=======================================
--- /src/gov/nist/javax/sip/stack/NioTcpMessageChannel.java Thu Apr 26 22:29:01 2012 +++ /src/gov/nist/javax/sip/stack/NioTcpMessageChannel.java Fri Apr 27 05:16:21 2012
@@ -146,8 +146,9 @@
                        // messages that we write out to him.
                        nioParser = new NioPipelineParser(sipStack, this,
                                        this.sipStack.getMaxMessageSize());
-                       this.peerProtocol = "TCP";
+                       this.peerProtocol = getTransport();
                        lastActivityTimeStamp = System.currentTimeMillis();
+ super.key = MessageChannel.getKey(peerAddress, peerPort, getTransport());
                } finally {
                        if (logger.isLoggingEnabled(LogWriter.TRACE_DEBUG)) {
                                logger.logDebug("Done creating NioTcpMessageChannel 
" + this);
@@ -175,7 +176,7 @@
                                        this.sipStack.getMaxMessageSize());
                        putMessageChannel(socketChannel, this);
                        lastActivityTimeStamp = System.currentTimeMillis();
- //super.key = MessageChannel.getKey(peerAddress, peerPort, getTransport()); + super.key = MessageChannel.getKey(peerAddress, peerPort, getTransport());

                } finally {
                        if (logger.isLoggingEnabled(LogWriter.TRACE_DEBUG)) {

Reply via email to