Merge remote-tracking branch 'origin/master' into jetty-8
This commit is contained in:
commit
b8b5df27d6
|
@ -72,7 +72,7 @@ import org.eclipse.jetty.util.thread.Timeout;
|
||||||
*/
|
*/
|
||||||
public class HttpExchange
|
public class HttpExchange
|
||||||
{
|
{
|
||||||
private static final Logger LOG = Log.getLogger(HttpExchange.class);
|
static final Logger LOG = Log.getLogger(HttpExchange.class);
|
||||||
|
|
||||||
public static final int STATUS_START = 0;
|
public static final int STATUS_START = 0;
|
||||||
public static final int STATUS_WAITING_FOR_CONNECTION = 1;
|
public static final int STATUS_WAITING_FOR_CONNECTION = 1;
|
||||||
|
|
|
@ -54,7 +54,7 @@ import org.junit.Test;
|
||||||
*/
|
*/
|
||||||
public class HttpExchangeTest
|
public class HttpExchangeTest
|
||||||
{
|
{
|
||||||
final static boolean verbose=true;
|
final static boolean verbose=HttpExchange.LOG.isDebugEnabled();
|
||||||
protected static int _maxConnectionsPerAddress = 2;
|
protected static int _maxConnectionsPerAddress = 2;
|
||||||
protected static String _scheme = "http";
|
protected static String _scheme = "http";
|
||||||
protected static Server _server;
|
protected static Server _server;
|
||||||
|
|
|
@ -44,6 +44,7 @@ public class ChannelEndPoint implements EndPoint
|
||||||
protected final InetSocketAddress _local;
|
protected final InetSocketAddress _local;
|
||||||
protected final InetSocketAddress _remote;
|
protected final InetSocketAddress _remote;
|
||||||
protected int _maxIdleTime;
|
protected int _maxIdleTime;
|
||||||
|
private boolean _ishut;
|
||||||
|
|
||||||
public ChannelEndPoint(ByteChannel channel) throws IOException
|
public ChannelEndPoint(ByteChannel channel) throws IOException
|
||||||
{
|
{
|
||||||
|
@ -111,29 +112,31 @@ public class ChannelEndPoint implements EndPoint
|
||||||
LOG.debug("ishut {}",this);
|
LOG.debug("ishut {}",this);
|
||||||
if (_channel.isOpen())
|
if (_channel.isOpen())
|
||||||
{
|
{
|
||||||
if (_channel instanceof SocketChannel)
|
if (_socket!=null)
|
||||||
{
|
{
|
||||||
Socket socket= ((SocketChannel)_channel).socket();
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (!socket.isInputShutdown())
|
if (!_socket.isInputShutdown())
|
||||||
socket.shutdownInput();
|
{
|
||||||
|
// System.err.println("ISHUT "+_socket);
|
||||||
|
_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);
|
||||||
if (!socket.isClosed())
|
|
||||||
close();
|
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
if(socket.isOutputShutdown() && !socket.isClosed())
|
_ishut=true;
|
||||||
|
if(_socket.isOutputShutdown() && !_socket.isClosed())
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
close();
|
_ishut=true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,24 +153,26 @@ public class ChannelEndPoint implements EndPoint
|
||||||
LOG.debug("oshut {}",this);
|
LOG.debug("oshut {}",this);
|
||||||
if (_channel.isOpen())
|
if (_channel.isOpen())
|
||||||
{
|
{
|
||||||
if (_channel instanceof SocketChannel)
|
if (_socket!=null)
|
||||||
{
|
{
|
||||||
Socket socket= ((SocketChannel)_channel).socket();
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (!socket.isOutputShutdown())
|
if (!_socket.isOutputShutdown())
|
||||||
socket.shutdownOutput();
|
{
|
||||||
|
// System.err.println("OSHUT "+_socket);
|
||||||
|
_socket.shutdownOutput();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch(SocketException e)
|
catch(SocketException e)
|
||||||
{
|
{
|
||||||
LOG.warn(e.toString());
|
LOG.debug(e.toString());
|
||||||
LOG.debug(e);
|
LOG.ignore(e);
|
||||||
if (!socket.isClosed())
|
if (!_socket.isClosed())
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
if (socket.isInputShutdown() && !socket.isClosed())
|
if ((_ishut||_socket.isInputShutdown()) && !_socket.isClosed())
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -191,7 +196,7 @@ public class ChannelEndPoint implements EndPoint
|
||||||
|
|
||||||
public boolean isInputShutdown()
|
public boolean isInputShutdown()
|
||||||
{
|
{
|
||||||
return !_channel.isOpen() || _socket!=null && _socket.isInputShutdown();
|
return !_channel.isOpen() || _ishut || _socket!=null && _socket.isInputShutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
@ -200,6 +205,8 @@ public class ChannelEndPoint implements EndPoint
|
||||||
public void close() throws IOException
|
public void close() throws IOException
|
||||||
{
|
{
|
||||||
LOG.debug("close {}",this);
|
LOG.debug("close {}",this);
|
||||||
|
|
||||||
|
// System.err.println("CLOSE "+_socket);
|
||||||
_channel.close();
|
_channel.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -208,6 +215,8 @@ public class ChannelEndPoint implements EndPoint
|
||||||
*/
|
*/
|
||||||
public int fill(Buffer buffer) throws IOException
|
public int fill(Buffer buffer) throws IOException
|
||||||
{
|
{
|
||||||
|
if (_ishut)
|
||||||
|
return -1;
|
||||||
Buffer buf = buffer.buffer();
|
Buffer buf = buffer.buffer();
|
||||||
int len=0;
|
int len=0;
|
||||||
if (buf instanceof NIOBuffer)
|
if (buf instanceof NIOBuffer)
|
||||||
|
|
|
@ -657,14 +657,8 @@ public class SslConnection extends AbstractConnection implements AsyncConnection
|
||||||
|
|
||||||
while (now<end)
|
while (now<end)
|
||||||
{
|
{
|
||||||
process(null,null);
|
if (process(null,null))
|
||||||
synchronized (SslConnection.this)
|
|
||||||
{
|
|
||||||
if (_unwrapBuf!=null && _unwrapBuf.hasContent())
|
|
||||||
break;
|
break;
|
||||||
if (_inbound!=null && _inbound.hasContent())
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
_endp.blockReadable(end-now);
|
_endp.blockReadable(end-now);
|
||||||
now = System.currentTimeMillis();
|
now = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,11 +24,15 @@ public abstract class EndPointTest<T extends EndPoint>
|
||||||
EndPointPair<T> c = newConnection();
|
EndPointPair<T> c = newConnection();
|
||||||
Buffer buffer = new IndirectNIOBuffer(4096);
|
Buffer buffer = new IndirectNIOBuffer(4096);
|
||||||
|
|
||||||
|
// Client sends a request
|
||||||
c.client.flush(new ByteArrayBuffer("request"));
|
c.client.flush(new ByteArrayBuffer("request"));
|
||||||
|
|
||||||
|
// Server receives the request
|
||||||
int len = c.server.fill(buffer);
|
int len = c.server.fill(buffer);
|
||||||
assertEquals(7,len);
|
assertEquals(7,len);
|
||||||
assertEquals("request",buffer.toString());
|
assertEquals("request",buffer.toString());
|
||||||
|
|
||||||
|
// Client and server are open
|
||||||
assertTrue(c.client.isOpen());
|
assertTrue(c.client.isOpen());
|
||||||
assertFalse(c.client.isInputShutdown());
|
assertFalse(c.client.isInputShutdown());
|
||||||
assertFalse(c.client.isOutputShutdown());
|
assertFalse(c.client.isOutputShutdown());
|
||||||
|
@ -36,9 +40,11 @@ public abstract class EndPointTest<T extends EndPoint>
|
||||||
assertFalse(c.server.isInputShutdown());
|
assertFalse(c.server.isInputShutdown());
|
||||||
assertFalse(c.server.isOutputShutdown());
|
assertFalse(c.server.isOutputShutdown());
|
||||||
|
|
||||||
|
// Server sends response and closes output
|
||||||
c.server.flush(new ByteArrayBuffer("response"));
|
c.server.flush(new ByteArrayBuffer("response"));
|
||||||
c.server.shutdownOutput();
|
c.server.shutdownOutput();
|
||||||
|
|
||||||
|
// client server are open, server is oshut
|
||||||
assertTrue(c.client.isOpen());
|
assertTrue(c.client.isOpen());
|
||||||
assertFalse(c.client.isInputShutdown());
|
assertFalse(c.client.isInputShutdown());
|
||||||
assertFalse(c.client.isOutputShutdown());
|
assertFalse(c.client.isOutputShutdown());
|
||||||
|
@ -46,11 +52,13 @@ public abstract class EndPointTest<T extends EndPoint>
|
||||||
assertFalse(c.server.isInputShutdown());
|
assertFalse(c.server.isInputShutdown());
|
||||||
assertTrue(c.server.isOutputShutdown());
|
assertTrue(c.server.isOutputShutdown());
|
||||||
|
|
||||||
|
// Client reads response
|
||||||
buffer.clear();
|
buffer.clear();
|
||||||
len = c.client.fill(buffer);
|
len = c.client.fill(buffer);
|
||||||
assertEquals(8,len);
|
assertEquals(8,len);
|
||||||
assertEquals("response",buffer.toString());
|
assertEquals("response",buffer.toString());
|
||||||
|
|
||||||
|
// Client and server are open, server is oshut
|
||||||
assertTrue(c.client.isOpen());
|
assertTrue(c.client.isOpen());
|
||||||
assertFalse(c.client.isInputShutdown());
|
assertFalse(c.client.isInputShutdown());
|
||||||
assertFalse(c.client.isOutputShutdown());
|
assertFalse(c.client.isOutputShutdown());
|
||||||
|
@ -58,10 +66,12 @@ public abstract class EndPointTest<T extends EndPoint>
|
||||||
assertFalse(c.server.isInputShutdown());
|
assertFalse(c.server.isInputShutdown());
|
||||||
assertTrue(c.server.isOutputShutdown());
|
assertTrue(c.server.isOutputShutdown());
|
||||||
|
|
||||||
|
// Client reads -1
|
||||||
buffer.clear();
|
buffer.clear();
|
||||||
len = c.client.fill(buffer);
|
len = c.client.fill(buffer);
|
||||||
assertEquals(-1,len);
|
assertEquals(-1,len);
|
||||||
|
|
||||||
|
// Client and server are open, server is oshut, client is ishut
|
||||||
assertTrue(c.client.isOpen());
|
assertTrue(c.client.isOpen());
|
||||||
assertTrue(c.client.isInputShutdown());
|
assertTrue(c.client.isInputShutdown());
|
||||||
assertFalse(c.client.isOutputShutdown());
|
assertFalse(c.client.isOutputShutdown());
|
||||||
|
@ -69,8 +79,10 @@ public abstract class EndPointTest<T extends EndPoint>
|
||||||
assertFalse(c.server.isInputShutdown());
|
assertFalse(c.server.isInputShutdown());
|
||||||
assertTrue(c.server.isOutputShutdown());
|
assertTrue(c.server.isOutputShutdown());
|
||||||
|
|
||||||
|
// Client shutsdown output, which is a close because already ishut
|
||||||
c.client.shutdownOutput();
|
c.client.shutdownOutput();
|
||||||
|
|
||||||
|
// Client is closed. Server is open and oshut
|
||||||
assertFalse(c.client.isOpen());
|
assertFalse(c.client.isOpen());
|
||||||
assertTrue(c.client.isInputShutdown());
|
assertTrue(c.client.isInputShutdown());
|
||||||
assertTrue(c.client.isOutputShutdown());
|
assertTrue(c.client.isOutputShutdown());
|
||||||
|
@ -78,10 +90,12 @@ public abstract class EndPointTest<T extends EndPoint>
|
||||||
assertFalse(c.server.isInputShutdown());
|
assertFalse(c.server.isInputShutdown());
|
||||||
assertTrue(c.server.isOutputShutdown());
|
assertTrue(c.server.isOutputShutdown());
|
||||||
|
|
||||||
|
// Server reads close
|
||||||
buffer.clear();
|
buffer.clear();
|
||||||
len = c.server.fill(buffer);
|
len = c.server.fill(buffer);
|
||||||
assertEquals(-1,len);
|
assertEquals(-1,len);
|
||||||
|
|
||||||
|
// Client and Server are closed
|
||||||
assertFalse(c.client.isOpen());
|
assertFalse(c.client.isOpen());
|
||||||
assertTrue(c.client.isInputShutdown());
|
assertTrue(c.client.isInputShutdown());
|
||||||
assertTrue(c.client.isOutputShutdown());
|
assertTrue(c.client.isOutputShutdown());
|
||||||
|
|
|
@ -23,6 +23,8 @@ import java.io.ByteArrayOutputStream;
|
||||||
import java.net.ServerSocket;
|
import java.net.ServerSocket;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.net.SocketException;
|
import java.net.SocketException;
|
||||||
|
import java.nio.channels.ServerSocketChannel;
|
||||||
|
import java.nio.channels.SocketChannel;
|
||||||
|
|
||||||
import org.eclipse.jetty.util.IO;
|
import org.eclipse.jetty.util.IO;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
|
@ -51,14 +53,12 @@ public class IOTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHalfCloses() throws Exception
|
public void testHalfClose() throws Exception
|
||||||
{
|
{
|
||||||
ServerSocket connector = new ServerSocket(0);
|
ServerSocket connector = new ServerSocket(0);
|
||||||
|
|
||||||
Socket client = new Socket("localhost",connector.getLocalPort());
|
Socket client = new Socket("localhost",connector.getLocalPort());
|
||||||
System.err.println(client);
|
|
||||||
Socket server = connector.accept();
|
Socket server = connector.accept();
|
||||||
System.err.println(server);
|
|
||||||
|
|
||||||
// we can write both ways
|
// we can write both ways
|
||||||
client.getOutputStream().write(1);
|
client.getOutputStream().write(1);
|
||||||
|
@ -130,8 +130,72 @@ public class IOTest
|
||||||
server.close();
|
server.close();
|
||||||
assertTrue(server.isClosed());
|
assertTrue(server.isClosed());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHalfCloseClientServer() throws Exception
|
||||||
|
{
|
||||||
|
ServerSocketChannel connector = ServerSocketChannel.open();
|
||||||
|
connector.socket().bind(null);
|
||||||
|
|
||||||
|
Socket client = SocketChannel.open(connector.socket().getLocalSocketAddress()).socket();
|
||||||
|
client.setSoTimeout(1000);
|
||||||
|
client.setSoLinger(false,-1);
|
||||||
|
Socket server = connector.accept().socket();
|
||||||
|
server.setSoTimeout(1000);
|
||||||
|
server.setSoLinger(false,-1);
|
||||||
|
|
||||||
|
// Write from client to server
|
||||||
|
client.getOutputStream().write(1);
|
||||||
|
|
||||||
|
// Server reads
|
||||||
|
assertEquals(1,server.getInputStream().read());
|
||||||
|
|
||||||
|
// Write from server to client with oshut
|
||||||
|
server.getOutputStream().write(1);
|
||||||
|
System.err.println("OSHUT "+server);
|
||||||
|
server.shutdownOutput();
|
||||||
|
|
||||||
|
// Client reads response
|
||||||
|
assertEquals(1,client.getInputStream().read());
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Client reads -1 and does ishut
|
||||||
|
assertEquals(-1,client.getInputStream().read());
|
||||||
|
assertFalse(client.isInputShutdown());
|
||||||
|
System.err.println("ISHUT "+client);
|
||||||
|
client.shutdownInput();
|
||||||
|
|
||||||
|
// Client ???
|
||||||
|
System.err.println("OSHUT "+client);
|
||||||
|
client.shutdownOutput();
|
||||||
|
System.err.println("CLOSE "+client);
|
||||||
|
client.close();
|
||||||
|
|
||||||
|
// Server reads -1, does ishut and then close
|
||||||
|
assertEquals(-1,server.getInputStream().read());
|
||||||
|
assertFalse(server.isInputShutdown());
|
||||||
|
System.err.println("ISHUT "+server);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
server.shutdownInput();
|
||||||
|
}
|
||||||
|
catch(SocketException e)
|
||||||
|
{
|
||||||
|
System.err.println(e);
|
||||||
|
}
|
||||||
|
System.err.println("CLOSE "+server);
|
||||||
|
server.close();
|
||||||
|
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
// Dang OSX!
|
||||||
|
System.err.println(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -36,11 +36,9 @@ public class ChannelEndPointTest extends EndPointTest<ChannelEndPoint>
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Override
|
||||||
public void stress() throws Exception
|
public void testClientServerExchange() throws Exception
|
||||||
{
|
{
|
||||||
|
super.testClientServerExchange();
|
||||||
testClientServerExchange();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -154,12 +154,12 @@ public class SelectChannelEndPointTest
|
||||||
|
|
||||||
public void onClose()
|
public void onClose()
|
||||||
{
|
{
|
||||||
System.err.println("onClose");
|
// System.err.println("onClose");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onInputShutdown() throws IOException
|
public void onInputShutdown() throws IOException
|
||||||
{
|
{
|
||||||
System.err.println("onInputShutdown");
|
// System.err.println("onInputShutdown");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -209,9 +209,15 @@ public class SelectChannelEndPointTest
|
||||||
assertTrue(b>0);
|
assertTrue(b>0);
|
||||||
assertEquals(c,(char)b);
|
assertEquals(c,(char)b);
|
||||||
}
|
}
|
||||||
|
|
||||||
client.close();
|
client.close();
|
||||||
|
|
||||||
|
int i=0;
|
||||||
|
while (server.isOpen())
|
||||||
|
{
|
||||||
|
assert(i++<10);
|
||||||
|
Thread.sleep(10);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -283,7 +289,7 @@ public class SelectChannelEndPointTest
|
||||||
OutputStream clientOutputStream = client.getOutputStream();
|
OutputStream clientOutputStream = client.getOutputStream();
|
||||||
InputStream clientInputStream = client.getInputStream();
|
InputStream clientInputStream = client.getInputStream();
|
||||||
|
|
||||||
int specifiedTimeout = 200;
|
int specifiedTimeout = 400;
|
||||||
client.setSoTimeout(specifiedTimeout);
|
client.setSoTimeout(specifiedTimeout);
|
||||||
|
|
||||||
// Write 8 and cause block for 10
|
// Write 8 and cause block for 10
|
||||||
|
@ -303,8 +309,8 @@ public class SelectChannelEndPointTest
|
||||||
catch(SocketTimeoutException e)
|
catch(SocketTimeoutException e)
|
||||||
{
|
{
|
||||||
int elapsed = Long.valueOf(System.currentTimeMillis() - start).intValue();
|
int elapsed = Long.valueOf(System.currentTimeMillis() - start).intValue();
|
||||||
System.err.println("blocked " + elapsed);
|
System.err.println("blocked for " + elapsed+ "ms");
|
||||||
Assert.assertThat("Expected timeout", elapsed, greaterThanOrEqualTo(specifiedTimeout));
|
Assert.assertThat("Expected timeout", elapsed, greaterThanOrEqualTo(3*specifiedTimeout/4));
|
||||||
}
|
}
|
||||||
|
|
||||||
// write remaining characters
|
// write remaining characters
|
||||||
|
@ -324,13 +330,13 @@ public class SelectChannelEndPointTest
|
||||||
public void testStress() throws Exception
|
public void testStress() throws Exception
|
||||||
{
|
{
|
||||||
Socket client = newClient();
|
Socket client = newClient();
|
||||||
client.setSoTimeout(10000);
|
client.setSoTimeout(30000);
|
||||||
|
|
||||||
SocketChannel server = _connector.accept();
|
SocketChannel server = _connector.accept();
|
||||||
server.configureBlocking(false);
|
server.configureBlocking(false);
|
||||||
|
|
||||||
_manager.register(server);
|
_manager.register(server);
|
||||||
int writes = 1000000;
|
int writes = 100000;
|
||||||
|
|
||||||
final CountDownLatch latch = new CountDownLatch(writes);
|
final CountDownLatch latch = new CountDownLatch(writes);
|
||||||
final InputStream in = new BufferedInputStream(client.getInputStream());
|
final InputStream in = new BufferedInputStream(client.getInputStream());
|
||||||
|
|
|
@ -464,9 +464,22 @@ public class ResourceTest
|
||||||
// This test is intended to run only on Windows platform
|
// This test is intended to run only on Windows platform
|
||||||
assumeTrue(OS.IS_WINDOWS);
|
assumeTrue(OS.IS_WINDOWS);
|
||||||
|
|
||||||
|
String path = __userURL.toURI().getPath().replace('/','\\')+"ResourceTest.java";
|
||||||
|
System.err.println(path);
|
||||||
|
|
||||||
|
Resource resource = Resource.newResource(path, false);
|
||||||
|
System.err.println(resource);
|
||||||
|
assertTrue(resource.exists());
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
String uncPath = "\\\\127.0.0.1"+__userURL.toURI().getPath().replace('/','\\').replace(':','$')+"ResourceTest.java";
|
String uncPath = "\\\\127.0.0.1"+__userURL.toURI().getPath().replace('/','\\').replace(':','$')+"ResourceTest.java";
|
||||||
|
System.err.println(uncPath);
|
||||||
|
|
||||||
Resource uncResource = Resource.newResource(uncPath, false);
|
Resource uncResource = Resource.newResource(uncPath, false);
|
||||||
|
System.err.println(uncResource);
|
||||||
assertTrue(uncResource.exists());
|
assertTrue(uncResource.exists());
|
||||||
|
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue