Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/usnistgov/jsip
Browse files Browse the repository at this point in the history
  • Loading branch information
fre42 committed Feb 16, 2018
2 parents 419b526 + 3c93a33 commit 0ec1683
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 17 deletions.
27 changes: 17 additions & 10 deletions src/gov/nist/javax/sip/stack/TCPMessageChannel.java
Expand Up @@ -235,6 +235,9 @@ protected synchronized void sendMessage(byte[] msg, boolean isClient) throws IO

Socket sock = null;
IOException problem = null;
// try to prevent at least the worst thread safety issues by using a local variable ...
Socket mySockLocal = mySock;

try {
sock = this.sipStack.ioHandler.sendBytes(this.messageProcessor.getIpAddress(),
this.peerAddress, this.peerPort, this.peerProtocol, msg, isClient, this);
Expand Down Expand Up @@ -270,8 +273,8 @@ protected synchronized void sendMessage(byte[] msg, boolean isClient) throws IO
// if (mySock == null && s != null) {
// this.uncache();
// } else
if (sock != mySock && sock != null) {
if (mySock != null) {
if (sock != mySockLocal && sock != null) {
if (mySockLocal != null) {
if(logger.isLoggingEnabled(LogWriter.TRACE_WARN)) {
logger.logWarning(
"Old socket different than new socket on channel " + key);
Expand All @@ -288,19 +291,23 @@ protected synchronized void sendMessage(byte[] msg, boolean isClient) throws IO
close(false, false);
}
if(problem == null) {
if(mySock != null) {
if (mySockLocal != null) {
if(logger.isLoggingEnabled(LogWriter.TRACE_WARN)) {
logger.logWarning(
"There was no exception for the retry mechanism so creating a new thread based on the new socket for incoming " + key);
}
}
mySock = sock;
this.myClientInputStream = mySock.getInputStream();
this.myClientOutputStream = mySock.getOutputStream();
Thread thread = new Thread(this);
thread.setDaemon(true);
thread.setName("TCPMessageChannelThread");
thread.start();
// NOTE: need to consider refactoring the whole socket handling with respect to thread safety
if (mySockLocal == mySock) {
// still not thread safe :-( but what else to do?
mySock = sock;
this.myClientInputStream = mySock.getInputStream();
this.myClientOutputStream = mySock.getOutputStream();
Thread thread = new Thread(this);
thread.setDaemon(true);
thread.setName("TCPMessageChannelThread");
thread.start();
}
} else {
if(logger.isLoggingEnabled(LogWriter.TRACE_WARN)) {
logger.logWarning(
Expand Down
20 changes: 13 additions & 7 deletions src/gov/nist/javax/sip/stack/TLSMessageChannel.java
Expand Up @@ -234,6 +234,8 @@ protected synchronized void sendMessage(byte[] msg, boolean retry) throws IOExce
}
Socket sock = null;
IOException problem = null;
// try to prevent at least the worst thread safety issues by using a local variable ...
Socket mySockLocal = mySock;
try {
sock = this.sipStack.ioHandler.sendBytes(
this.getMessageProcessor().getIpAddress(), this.peerAddress, this.peerPort,
Expand Down Expand Up @@ -278,18 +280,22 @@ protected synchronized void sendMessage(byte[] msg, boolean retry) throws IOExce
close(false, false);
}
if(problem == null) {
if(mySock != null) {
if (mySockLocal != null) {
if(logger.isLoggingEnabled(LogWriter.TRACE_WARN)) {
logger.logWarning(
"There was no exception for the retry mechanism so creating a new thread based on the new socket for incoming " + key);
}
}
mySock = sock;
this.myClientInputStream = mySock.getInputStream();
Thread thread = new Thread(this);
thread.setDaemon(true);
thread.setName("TCPMessageChannelThread");
thread.start();
// NOTE: need to consider refactoring the whole socket handling with respect to thread safety
if (mySockLocal == mySock) {
// still not thread safe :-( but what else to do?
mySock = sock;
this.myClientInputStream = mySock.getInputStream();
Thread thread = new Thread(this);
thread.setDaemon(true);
thread.setName("TCPMessageChannelThread");
thread.start();
}
} else {
if(logger.isLoggingEnabled(LogWriter.TRACE_WARN)) {
logger.logWarning(
Expand Down

0 comments on commit 0ec1683

Please sign in to comment.