diff options
Diffstat (limited to 'jetty-io/src/main/java/org/eclipse/jetty/io/nio/ChannelEndPoint.java')
-rw-r--r-- | jetty-io/src/main/java/org/eclipse/jetty/io/nio/ChannelEndPoint.java | 122 |
1 files changed, 67 insertions, 55 deletions
diff --git a/jetty-io/src/main/java/org/eclipse/jetty/io/nio/ChannelEndPoint.java b/jetty-io/src/main/java/org/eclipse/jetty/io/nio/ChannelEndPoint.java index 762e9380df..c9628b86ab 100644 --- a/jetty-io/src/main/java/org/eclipse/jetty/io/nio/ChannelEndPoint.java +++ b/jetty-io/src/main/java/org/eclipse/jetty/io/nio/ChannelEndPoint.java @@ -29,27 +29,58 @@ import org.eclipse.jetty.util.log.Log; /** + * Channel End Point. + * <p>Holds the channel and socket for an NIO endpoint. * - * - * To change the template for this generated type comment go to - * Window - Preferences - Java - Code Generation - Code and Comments */ public class ChannelEndPoint implements EndPoint { protected final ByteChannel _channel; protected final ByteBuffer[] _gather2=new ByteBuffer[2]; protected final Socket _socket; - protected InetSocketAddress _local; - protected InetSocketAddress _remote; + protected final InetSocketAddress _local; + protected final InetSocketAddress _remote; + protected int _maxIdleTime; /** * */ - public ChannelEndPoint(ByteChannel channel) + public ChannelEndPoint(ByteChannel channel) throws IOException { super(); this._channel = channel; _socket=(channel instanceof SocketChannel)?((SocketChannel)channel).socket():null; + if (_socket!=null) + { + _local=(InetSocketAddress)_socket.getLocalSocketAddress(); + _remote=(InetSocketAddress)_socket.getRemoteSocketAddress(); + _maxIdleTime=_socket.getSoTimeout(); + } + else + { + _local=_remote=null; + } + } + + /** + * + */ + protected ChannelEndPoint(ByteChannel channel, int maxIdleTime) throws IOException + { + this._channel = channel; + _maxIdleTime=maxIdleTime; + _socket=(channel instanceof SocketChannel)?((SocketChannel)channel).socket():null; + if (_socket!=null) + { + _local=(InetSocketAddress)_socket.getLocalSocketAddress(); + _remote=(InetSocketAddress)_socket.getRemoteSocketAddress(); + _socket.setSoTimeout(_maxIdleTime); + } + else + { + _local=_remote=null; + } + } public boolean isBlocking() @@ -78,34 +109,23 @@ public class ChannelEndPoint implements EndPoint /* (non-Javadoc) * @see org.eclipse.io.EndPoint#close() */ - public void close() throws IOException + public void shutdownOutput() throws IOException { - if (_channel.isOpen()) + if (_channel.isOpen() && _channel instanceof SocketChannel) { - try - { - if (_channel instanceof SocketChannel) - { - // TODO - is this really required? - Socket socket= ((SocketChannel)_channel).socket(); - if (!socket.isClosed()&&!socket.isOutputShutdown()) - socket.shutdownOutput(); - } - } - catch(IOException e) - { - Log.ignore(e); - } - catch(UnsupportedOperationException e) - { - Log.ignore(e); - } - finally - { - _channel.close(); - } + Socket socket= ((SocketChannel)_channel).socket(); + if (!socket.isClosed()&&!socket.isOutputShutdown()) + socket.shutdownOutput(); } } + + /* (non-Javadoc) + * @see org.eclipse.io.EndPoint#close() + */ + public void close() throws IOException + { + _channel.close(); + } /* (non-Javadoc) * @see org.eclipse.io.EndPoint#fill(org.eclipse.io.Buffer) @@ -317,13 +337,8 @@ public class ChannelEndPoint implements EndPoint { if (_socket==null) return null; - - if (_local==null) - _local=(InetSocketAddress)_socket.getLocalSocketAddress(); - if (_local==null || _local.getAddress()==null || _local.getAddress().isAnyLocalAddress()) return StringUtil.ALL_INTERFACES; - return _local.getAddress().getHostAddress(); } @@ -335,13 +350,8 @@ public class ChannelEndPoint implements EndPoint { if (_socket==null) return null; - - if (_local==null) - _local=(InetSocketAddress)_socket.getLocalSocketAddress(); - if (_local==null || _local.getAddress()==null || _local.getAddress().isAnyLocalAddress()) return StringUtil.ALL_INTERFACES; - return _local.getAddress().getCanonicalHostName(); } @@ -353,9 +363,6 @@ public class ChannelEndPoint implements EndPoint { if (_socket==null) return 0; - - if (_local==null) - _local=(InetSocketAddress)_socket.getLocalSocketAddress(); if (_local==null) return -1; return _local.getPort(); @@ -369,10 +376,6 @@ public class ChannelEndPoint implements EndPoint { if (_socket==null) return null; - - if (_remote==null) - _remote=(InetSocketAddress)_socket.getRemoteSocketAddress(); - if (_remote==null) return null; return _remote.getAddress().getHostAddress(); @@ -386,10 +389,6 @@ public class ChannelEndPoint implements EndPoint { if (_socket==null) return null; - - if (_remote==null) - _remote=(InetSocketAddress)_socket.getRemoteSocketAddress(); - if (_remote==null) return null; return _remote.getAddress().getCanonicalHostName(); @@ -403,10 +402,6 @@ public class ChannelEndPoint implements EndPoint { if (_socket==null) return 0; - - if (_remote==null) - _remote=(InetSocketAddress)_socket.getRemoteSocketAddress(); - return _remote==null?-1:_remote.getPort(); } @@ -442,4 +437,21 @@ public class ChannelEndPoint implements EndPoint { return false; } + + /* ------------------------------------------------------------ */ + public int getMaxIdleTime() + { + return _maxIdleTime; + } + + /* ------------------------------------------------------------ */ + /** + * @see org.eclipse.jetty.io.bio.StreamEndPoint#setMaxIdleTime(int) + */ + public void setMaxIdleTime(int timeMs) throws IOException + { + if (_socket!=null && timeMs!=_maxIdleTime) + _socket.setSoTimeout(timeMs>0?timeMs:0); + _maxIdleTime=timeMs; + } } |