Normalized behavior of shutdown[In|Out]put() methods and is[In|Out]putShutdown(), relying on a volatile flag.

This commit is contained in:
Simone Bordet 2011-11-21 21:39:47 +01:00
parent 111000befa
commit e27c5a9306
1 changed files with 20 additions and 23 deletions

View File

@ -43,8 +43,9 @@ public class ChannelEndPoint implements EndPoint
protected final Socket _socket; protected final Socket _socket;
protected final InetSocketAddress _local; protected final InetSocketAddress _local;
protected final InetSocketAddress _remote; protected final InetSocketAddress _remote;
protected int _maxIdleTime; protected volatile int _maxIdleTime;
private boolean _ishut; private volatile boolean _ishut;
private volatile boolean _oshut;
public ChannelEndPoint(ByteChannel channel) throws IOException public ChannelEndPoint(ByteChannel channel) throws IOException
{ {
@ -109,34 +110,32 @@ public class ChannelEndPoint implements EndPoint
*/ */
protected final void shutdownChannelInput() throws IOException protected final void shutdownChannelInput() throws IOException
{ {
LOG.debug("ishut {}",this); LOG.debug("ishut {}", this);
_ishut = true;
if (_channel.isOpen()) if (_channel.isOpen())
{ {
if (_socket!=null) if (_socket != null)
{ {
try try
{ {
if (!_socket.isInputShutdown()) if (!_socket.isInputShutdown())
{ {
// System.err.println("ISHUT "+_socket);
_socket.shutdownInput(); _socket.shutdownInput();
} }
} }
catch(SocketException e) catch (SocketException e)
{ {
// System.err.println(e);
LOG.debug(e.toString()); LOG.debug(e.toString());
LOG.ignore(e); LOG.ignore(e);
} }
finally finally
{ {
_ishut=true; if (_oshut)
if(_socket.isOutputShutdown() && !_socket.isClosed()) {
close(); close();
}
} }
} }
else
_ishut=true;
} }
} }
@ -151,33 +150,31 @@ public class ChannelEndPoint implements EndPoint
protected final void shutdownChannelOutput() throws IOException protected final void shutdownChannelOutput() throws IOException
{ {
LOG.debug("oshut {}",this); LOG.debug("oshut {}",this);
_oshut = true;
if (_channel.isOpen()) if (_channel.isOpen())
{ {
if (_socket!=null) if (_socket != null)
{ {
try try
{ {
if (!_socket.isOutputShutdown()) if (!_socket.isOutputShutdown())
{ {
// System.err.println("OSHUT "+_socket);
_socket.shutdownOutput(); _socket.shutdownOutput();
} }
} }
catch(SocketException e) catch (SocketException e)
{ {
LOG.debug(e.toString()); LOG.debug(e.toString());
LOG.ignore(e); LOG.ignore(e);
if (!_socket.isClosed())
close();
} }
finally finally
{ {
if ((_ishut||_socket.isInputShutdown()) && !_socket.isClosed()) if (_ishut)
{
close(); close();
}
} }
} }
else
close();
} }
} }
@ -191,12 +188,12 @@ public class ChannelEndPoint implements EndPoint
public boolean isOutputShutdown() public boolean isOutputShutdown()
{ {
return !_channel.isOpen() || _socket!=null && _socket.isOutputShutdown(); return _oshut;
} }
public boolean isInputShutdown() public boolean isInputShutdown()
{ {
return !_channel.isOpen() || _ishut || _socket!=null && _socket.isInputShutdown(); return _ishut;
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -359,7 +356,7 @@ public class ChannelEndPoint implements EndPoint
trailer!=null && trailer.length()>0) trailer!=null && trailer.length()>0)
length+=flush(trailer); length+=flush(trailer);
} }
return length; return length;
} }