Author: ron.sigal(a)jboss.com
Date: 2013-11-04 10:57:44 -0500 (Mon, 04 Nov 2013)
New Revision: 6511
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/TimedOutputStream.java
Log:
JBREM-1307: Restoring TimedOutputStream changes.
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-04
15:38:42 UTC (rev 6510)
+++
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/ClientSocketWrapper.java 2013-11-04
15:57:44 UTC (rev 6511)
@@ -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)
@@ -236,4 +237,4 @@
// Inner classes
--------------------------------------------------------------------------------
-}
+}
\ No newline at end of file
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-04
15:38:42 UTC (rev 6510)
+++
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/TimedOutputStream.java 2013-11-04
15:57:44 UTC (rev 6511)
@@ -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()
@@ -157,4 +210,4 @@
return super.cancel();
}
}
-}
+}
\ No newline at end of file
Show replies by date