Author: ron.sigal(a)jboss.com
Date: 2013-11-03 00:40:02 -0400 (Sun, 03 Nov 2013)
New Revision: 6508
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/ClientSocketWrapper.java
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/MicroSocketClientInvoker.java
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/SocketServerInvoker.java
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/TimedOutputStream.java
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/sslbisocket/SSLBisocketClientInvoker.java
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/sslsocket/SSLSocketClientInvoker.java
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/timeout/WriteTimeoutTestParent.java
Log:
JBREM-1307: TimedOutputStream calls Socket.setSoLinger(true,0) before calling
Socket.close().
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/ClientSocketWrapper.java
===================================================================
---
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/ClientSocketWrapper.java 2013-11-03
02:31:32 UTC (rev 6507)
+++
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/ClientSocketWrapper.java 2013-11-03
04:40:02 UTC (rev 6508)
@@ -125,6 +125,7 @@
// Public
---------------------------------------------------------------------------------------
+
public String toString()
{
Socket socket = getSocket();
@@ -220,7 +221,7 @@
OutputStream os = socket.getOutputStream();
if (writeTimeout > 0)
{
- os = new TimedOutputStream(os, writeTimeout);
+ os = new TimedOutputStream(os, socket, writeTimeout);
}
if (marshaller instanceof PreferredStreamMarshaller)
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/MicroSocketClientInvoker.java
===================================================================
---
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/MicroSocketClientInvoker.java 2013-11-03
02:31:32 UTC (rev 6507)
+++
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/MicroSocketClientInvoker.java 2013-11-03
04:40:02 UTC (rev 6508)
@@ -1261,8 +1261,9 @@
if (oOBInlineSet) s.setOOBInline(oOBInline);
if (receiveBufferSize > -1) s.setReceiveBufferSize(receiveBufferSize);
if (sendBufferSize > -1) s.setSendBufferSize(sendBufferSize);
- if (soLingerSet &&
- soLingerDuration > 0) s.setSoLinger(soLinger, soLingerDuration);
+// if (soLingerSet &&
+// soLingerDuration > 0) s.setSoLinger(soLinger, soLingerDuration);
+ if (soLingerSet) s.setSoLinger(soLinger, soLingerDuration);
if (trafficClass > -1) s.setTrafficClass(trafficClass);
}
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/SocketServerInvoker.java
===================================================================
---
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/SocketServerInvoker.java 2013-11-03
02:31:32 UTC (rev 6507)
+++
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/SocketServerInvoker.java 2013-11-03
04:40:02 UTC (rev 6508)
@@ -767,8 +767,9 @@
if (oOBInlineSet) s.setOOBInline(oOBInline);
if (receiveBufferSize > -1) s.setReceiveBufferSize(receiveBufferSize);
if (sendBufferSize > -1) s.setSendBufferSize(sendBufferSize);
- if (soLingerSet &&
- soLingerDuration > 0) s.setSoLinger(soLinger, soLingerDuration);
+// if (soLingerSet &&
+// soLingerDuration > 0) s.setSoLinger(soLinger, soLingerDuration);
+ if (soLingerSet) s.setSoLinger(soLinger, soLingerDuration);
if (trafficClass > -1) s.setTrafficClass(trafficClass);
}
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/TimedOutputStream.java
===================================================================
---
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/TimedOutputStream.java 2013-11-03
02:31:32 UTC (rev 6507)
+++
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/TimedOutputStream.java 2013-11-03
04:40:02 UTC (rev 6508)
@@ -24,17 +24,18 @@
import java.io.IOException;
import java.io.OutputStream;
+import java.net.Socket;
import java.util.Timer;
import java.util.TimerTask;
import org.jboss.logging.Logger;
/**
- * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @author <a href="ron.sigal(a)jboss.com"Ron Sigal</a
* @version $Rev$
- * <p>
+ * <p
* Copyright April 22, 2009
- * </p>
+ * </p
*/
public class TimedOutputStream extends OutputStream
{
@@ -43,12 +44,14 @@
private OutputStream os;
private int outputTimeout;
+ private Socket socket;
private OutputTimerTask timerTask;
private Object lock = new Object();
- public TimedOutputStream(OutputStream os, int outputTimeout)
+ public TimedOutputStream(OutputStream os, Socket socket, int outputTimeout)
{
this.os = os;
+ this.socket = socket;
this.outputTimeout = outputTimeout;
}
@@ -128,6 +131,16 @@
}
}
+ public Socket getSocket()
+ {
+ return socket;
+ }
+
+ public void setSocket(Socket socket)
+ {
+ this.socket = socket;
+ }
+
static class OutputTimerTask extends TimerTask
{
private TimedOutputStream tos;
@@ -139,16 +152,56 @@
public void run()
{
+// try
+// {
+// log.debug(this + " closing: " + tos);
+// tos.close();
+// tos = null;
+// }
+// catch (IOException e)
+// {
+// log.debug("unable to close " + tos);
+// }
try
{
- log.debug(this + " closing: " + tos);
- tos.close();
- tos = null;
+ Socket mySocket = tos.getSocket();
+ if (mySocket != null)
+ {
+ // set the linger on with duration 0, results RST being sent
+ // and socket send and receive buffers being discarded (does not
+ // wait of the existing write() to complete]. There is no use in
+ // setting the soLingerDuration longer then 0 (thus waiting for the write
to
+ // complete), since we've already waited "writeTimeout"
seconds on this write.
+ //
+ // Thank you, Todd Sandor!! -ron
+ boolean on = true;
+ int soLingerDuration = 0;
+ log.debug(this + " socketWrite TIMEOUT: set soLinger(ON,0): " +
tos);
+ mySocket.setSoLinger(on, soLingerDuration);
+ }
}
catch (IOException e)
{
- log.debug("unable to close " + tos);
+ log.debug(" socketWrite TIMEOUT: Attempting to set linger on socket
stream [" + tos +
+ "], Exception [" + e.toString() + "]");
}
+ finally
+ {
+ log.debug(this + " socketWrite TIMEOUT: close(): " + tos);
+ try
+ {
+ tos.close();
+ }
+ catch (Exception e)
+ {
+ // ignore - log error
+ log.error("Failed to close() socket stream Exception: ", e);
+ tos = null;
+ return;
+ }
+ log.debug(this + " socketWrite TIMEOUT: close() completed.");
+ tos = null;
+ }
}
public boolean cancel()
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/sslbisocket/SSLBisocketClientInvoker.java
===================================================================
---
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/sslbisocket/SSLBisocketClientInvoker.java 2013-11-03
02:31:32 UTC (rev 6507)
+++
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/sslbisocket/SSLBisocketClientInvoker.java 2013-11-03
04:40:02 UTC (rev 6508)
@@ -209,8 +209,9 @@
if (keepAliveSet) s.setKeepAlive(keepAlive);
if (receiveBufferSize > -1) s.setReceiveBufferSize(receiveBufferSize);
if (sendBufferSize > -1) s.setSendBufferSize(sendBufferSize);
- if (soLingerSet &&
- soLingerDuration > 0) s.setSoLinger(soLinger, soLingerDuration);
+// if (soLingerSet &&
+// soLingerDuration > 0) s.setSoLinger(soLinger, soLingerDuration);
+ if (soLingerSet) s.setSoLinger(soLinger, soLingerDuration);
if (trafficClass > -1) s.setTrafficClass(trafficClass);
if (s instanceof SSLSocket)
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/sslsocket/SSLSocketClientInvoker.java
===================================================================
---
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/sslsocket/SSLSocketClientInvoker.java 2013-11-03
02:31:32 UTC (rev 6507)
+++
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/sslsocket/SSLSocketClientInvoker.java 2013-11-03
04:40:02 UTC (rev 6508)
@@ -207,8 +207,9 @@
if (keepAliveSet) s.setKeepAlive(keepAlive);
if (receiveBufferSize > -1) s.setReceiveBufferSize(receiveBufferSize);
if (sendBufferSize > -1) s.setSendBufferSize(sendBufferSize);
- if (soLingerSet &&
- soLingerDuration > 0) s.setSoLinger(soLinger, soLingerDuration);
+// if (soLingerSet &&
+// soLingerDuration > 0) s.setSoLinger(soLinger, soLingerDuration);
+ if (soLingerSet) s.setSoLinger(soLinger, soLingerDuration);
if (trafficClass > -1) s.setTrafficClass(trafficClass);
if (s instanceof SSLSocket)
Modified:
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/timeout/WriteTimeoutTestParent.java
===================================================================
---
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/timeout/WriteTimeoutTestParent.java 2013-11-03
02:31:32 UTC (rev 6507)
+++
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/timeout/WriteTimeoutTestParent.java 2013-11-03
04:40:02 UTC (rev 6508)
@@ -93,7 +93,7 @@
if (firstTime)
{
firstTime = false;
- Logger.getLogger("org.jboss.remoting").setLevel(Level.INFO);
+ Logger.getLogger("org.jboss.remoting").setLevel(Level.DEBUG);
Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
PatternLayout layout = new PatternLayout(pattern);