JETTY-1237 Save local/remote address to be available after close

git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@2004 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
Greg Wilkins 2010-06-15 07:40:26 +00:00
parent 871f73d409
commit 6a9bbd673b
3 changed files with 30 additions and 48 deletions

View File

@ -3,6 +3,7 @@ jetty-7.1.5-SNAPSHOT
+ 316449 Websocket disconnect fix
+ 316584 Exception on startup if temp path has spaces and extractWAR=false
+ 316597 Removed null check and fixed name in Resource#hrefEncodeURI
+ JETTY-1237 Save local/remote address to be available after close
jetty-7.1.4.v20100610
+ 298551 SslSocketConnector does not need keystore stream

View File

@ -1,5 +1,5 @@
// ========================================================================
// Copyright (c) 2004-2009 Mort Bay Consulting Pty. Ltd.
// Copyright (c) 2004-2010 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
@ -29,9 +29,9 @@ import org.eclipse.jetty.util.log.Log;
*/
public class SocketEndPoint extends StreamEndPoint
{
Socket _socket;
InetSocketAddress _local;
InetSocketAddress _remote;
final Socket _socket;
final InetSocketAddress _local;
final InetSocketAddress _remote;
/**
*
@ -41,6 +41,8 @@ public class SocketEndPoint extends StreamEndPoint
{
super(socket.getInputStream(),socket.getOutputStream());
_socket=socket;
_local=(InetSocketAddress)_socket.getLocalSocketAddress();
_remote=(InetSocketAddress)_socket.getRemoteSocketAddress();
super.setMaxIdleTime(_socket.getSoTimeout());
}
@ -52,6 +54,8 @@ public class SocketEndPoint extends StreamEndPoint
{
super(socket.getInputStream(),socket.getOutputStream());
_socket=socket;
_local=(InetSocketAddress)_socket.getLocalSocketAddress();
_remote=(InetSocketAddress)_socket.getRemoteSocketAddress();
_socket.setSoTimeout(maxIdleTime>0?maxIdleTime:0);
super.setMaxIdleTime(maxIdleTime);
}
@ -97,9 +101,6 @@ public class SocketEndPoint extends StreamEndPoint
@Override
public String getLocalAddr()
{
if (_local==null)
_local=(InetSocketAddress)_socket.getLocalSocketAddress();
if (_local==null || _local.getAddress()==null || _local.getAddress().isAnyLocalAddress())
return StringUtil.ALL_INTERFACES;
@ -113,9 +114,6 @@ public class SocketEndPoint extends StreamEndPoint
@Override
public String getLocalHost()
{
if (_local==null)
_local=(InetSocketAddress)_socket.getLocalSocketAddress();
if (_local==null || _local.getAddress()==null || _local.getAddress().isAnyLocalAddress())
return StringUtil.ALL_INTERFACES;
@ -129,8 +127,6 @@ public class SocketEndPoint extends StreamEndPoint
@Override
public int getLocalPort()
{
if (_local==null)
_local=(InetSocketAddress)_socket.getLocalSocketAddress();
if (_local==null)
return -1;
return _local.getPort();
@ -143,8 +139,6 @@ public class SocketEndPoint extends StreamEndPoint
@Override
public String getRemoteAddr()
{
if (_remote==null)
_remote=(InetSocketAddress)_socket.getRemoteSocketAddress();
if (_remote==null)
return null;
InetAddress addr = _remote.getAddress();
@ -158,8 +152,6 @@ public class SocketEndPoint extends StreamEndPoint
@Override
public String getRemoteHost()
{
if (_remote==null)
_remote=(InetSocketAddress)_socket.getRemoteSocketAddress();
if (_remote==null)
return null;
return _remote.getAddress().getCanonicalHostName();
@ -172,8 +164,6 @@ public class SocketEndPoint extends StreamEndPoint
@Override
public int getRemotePort()
{
if (_remote==null)
_remote=(InetSocketAddress)_socket.getRemoteSocketAddress();
if (_remote==null)
return -1;
return _remote.getPort();

View File

@ -29,18 +29,17 @@ 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;
/**
@ -52,7 +51,15 @@ public class ChannelEndPoint implements EndPoint
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;
}
}
/**
@ -64,7 +71,16 @@ public class ChannelEndPoint implements EndPoint
_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()
@ -321,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();
}
@ -339,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();
}
@ -357,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();
@ -373,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();
@ -390,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();
@ -407,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();
}