336691 handle Views passed into flush

git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@2771 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
Greg Wilkins 2011-02-10 10:05:56 +00:00
parent 5b7e63510a
commit 5d2c3eee1b
2 changed files with 67 additions and 60 deletions

View File

@ -230,61 +230,7 @@ public class ChannelEndPoint implements EndPoint
header!=null && header.length()!=0 && buf0 instanceof NIOBuffer &&
buffer!=null && buffer.length()!=0 && buf1 instanceof NIOBuffer)
{
final NIOBuffer nbuf0 = (NIOBuffer)buf0;
final ByteBuffer bbuf0=nbuf0.getByteBuffer();
final NIOBuffer nbuf1 = (NIOBuffer)buf1;
final ByteBuffer bbuf1=nbuf1.getByteBuffer();
synchronized(this)
{
// We must sync because buffers may be shared (eg nbuf1 is likely to be cached content).
//noinspection SynchronizationOnLocalVariableOrMethodParameter
synchronized(bbuf0)
{
//noinspection SynchronizationOnLocalVariableOrMethodParameter
synchronized(bbuf1)
{
try
{
// Adjust position indexs of buf0 and buf1
bbuf0.position(header.getIndex());
bbuf0.limit(header.putIndex());
bbuf1.position(buffer.getIndex());
bbuf1.limit(buffer.putIndex());
_gather2[0]=bbuf0;
_gather2[1]=bbuf1;
// do the gathering write.
length=(int)((GatheringByteChannel)_channel).write(_gather2);
int hl=header.length();
if (length>hl)
{
header.clear();
buffer.skip(length-hl);
}
else if (length>0)
{
header.skip(length);
}
}
finally
{
// adjust buffer 0 and 1
if (!header.isImmutable())
header.setGetIndex(bbuf0.position());
if (!buffer.isImmutable())
buffer.setGetIndex(bbuf1.position());
bbuf0.position(0);
bbuf1.position(0);
bbuf0.limit(bbuf0.capacity());
bbuf1.limit(bbuf1.capacity());
}
}
}
}
length = gatheringFlush(header,((NIOBuffer)buf0).getByteBuffer(),buffer,((NIOBuffer)buf1).getByteBuffer());
}
else
{
@ -321,6 +267,63 @@ public class ChannelEndPoint implements EndPoint
return length;
}
protected int gatheringFlush(Buffer header, ByteBuffer bbuf0, Buffer buffer, ByteBuffer bbuf1) throws IOException
{
int length;
synchronized(this)
{
// We must sync because buffers may be shared (eg nbuf1 is likely to be cached content).
//noinspection SynchronizationOnLocalVariableOrMethodParameter
synchronized(bbuf0)
{
//noinspection SynchronizationOnLocalVariableOrMethodParameter
synchronized(bbuf1)
{
try
{
// Adjust position indexs of buf0 and buf1
bbuf0.position(header.getIndex());
bbuf0.limit(header.putIndex());
bbuf1.position(buffer.getIndex());
bbuf1.limit(buffer.putIndex());
_gather2[0]=bbuf0;
_gather2[1]=bbuf1;
// do the gathering write.
length=(int)((GatheringByteChannel)_channel).write(_gather2);
int hl=header.length();
if (length>hl)
{
header.clear();
buffer.skip(length-hl);
}
else if (length>0)
{
header.skip(length);
}
}
finally
{
// adjust buffer 0 and 1
if (!header.isImmutable())
header.setGetIndex(bbuf0.position());
if (!buffer.isImmutable())
buffer.setGetIndex(bbuf1.position());
bbuf0.position(0);
bbuf1.position(0);
bbuf0.limit(bbuf0.capacity());
bbuf1.limit(bbuf1.capacity());
}
}
}
}
return length;
}
/**
* @return Returns the channel.
*/

View File

@ -20,7 +20,6 @@ import java.nio.channels.SelectionKey;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import java.util.Arrays;
import java.util.Collections;
import org.eclipse.jetty.continuation.Continuation;
import org.eclipse.jetty.io.ConnectedEndPoint;
@ -236,9 +235,9 @@ public class SelectChannelConnector extends AbstractNIOConnector
_manager.setLowResourcesConnections(getLowResourcesConnections());
_manager.setLowResourcesMaxIdleTime(getLowResourcesMaxIdleTime());
_manager.start();
super.doStart();
// start a thread to accept new connections
_manager.dispatch(new Runnable()
{
@ -262,7 +261,7 @@ public class SelectChannelConnector extends AbstractNIOConnector
}
}
});
}
/* ------------------------------------------------------------ */
@ -281,6 +280,11 @@ public class SelectChannelConnector extends AbstractNIOConnector
return new SelectChannelEndPoint(channel,selectSet,key, SelectChannelConnector.this._maxIdleTime);
}
protected void endPointClosed(SelectChannelEndPoint endpoint)
{
connectionClosed(endpoint.getConnection());
}
/* ------------------------------------------------------------------------------- */
protected Connection newConnection(SocketChannel channel,final SelectChannelEndPoint endpoint)
{
@ -327,7 +331,7 @@ public class SelectChannelConnector extends AbstractNIOConnector
@Override
protected void endPointClosed(final SelectChannelEndPoint endpoint)
{
connectionClosed(endpoint.getConnection());
SelectChannelConnector.this.endPointClosed(endpoint);
}
@Override