392237 Improved handling of SPDY async send

This commit is contained in:
Greg Wilkins 2012-11-16 10:45:08 +11:00
parent 7317dde852
commit b5c6555a4a
3 changed files with 27 additions and 7 deletions

View File

@ -69,8 +69,17 @@ public class HttpTransportOverSPDY implements HttpTransport
@Override @Override
public <C> void send(HttpGenerator.ResponseInfo info, ByteBuffer content, boolean lastContent, C context, Callback<C> callback) public <C> void send(HttpGenerator.ResponseInfo info, ByteBuffer content, boolean lastContent, C context, Callback<C> callback)
{ {
boolean hasContent = !BufferUtil.isEmpty(content); // info==null content==null lastContent==false should not happen
// info==null content==null lastContent==true signals no more content - complete
// info==null content!=null lastContent==false send data on committed response
// info==null content!=null lastContent==true send last data on committed response - complete
// info!=null content==null lastContent==false commit
// info!=null content==null lastContent==true commit and complete
// info!=null content!=null lastContent==false commit with content
// info!=null content!=null lastContent==true commit with content and complete
boolean hasContent = BufferUtil.hasContent(content);
if (info!=null) if (info!=null)
{ {
@ -107,12 +116,21 @@ public class HttpTransportOverSPDY implements HttpTransport
boolean close = !hasContent && lastContent; boolean close = !hasContent && lastContent;
reply(stream, new ReplyInfo(headers, close)); reply(stream, new ReplyInfo(headers, close));
} }
if ((hasContent || lastContent ) && !stream.isClosed() ) if (stream.isClosed())
{
callback.failed(context,new EofException());
}
else if (hasContent)
{
stream.data(new ByteBufferDataInfo(content, lastContent),endPoint.getIdleTimeout(),TimeUnit.MILLISECONDS,context,callback); stream.data(new ByteBufferDataInfo(content, lastContent),endPoint.getIdleTimeout(),TimeUnit.MILLISECONDS,context,callback);
}
else if (lastContent)
{
stream.data(new ByteBufferDataInfo(BufferUtil.EMPTY_BUFFER, lastContent),endPoint.getIdleTimeout(),TimeUnit.MILLISECONDS,context,callback);
}
else else
callback.completed(context); callback.completed(context);
} }
@Override @Override

View File

@ -74,7 +74,7 @@ public class NextProtoNegoServerConnection extends AbstractConnection implements
if (nextProtocol == null && engine.getHandshakeStatus() == SSLEngineResult.HandshakeStatus.NOT_HANDSHAKING) if (nextProtocol == null && engine.getHandshakeStatus() == SSLEngineResult.HandshakeStatus.NOT_HANDSHAKING)
{ {
// The client sent the NPN extension, but did not send the NextProtocol // The client sent the NPN extension, but did not send the NextProtocol
// message with the chosen protocol so we need to force the default protocol // message with the chosen protocol so we need to close
LOG.debug("{} missing next protocol", this); LOG.debug("{} missing next protocol", this);
close(); close();
} }

View File

@ -34,6 +34,8 @@
package org.eclipse.jetty.util; package org.eclipse.jetty.util;
import org.eclipse.jetty.util.log.Log;
/** /**
* <p>A callback abstraction that handles completed/failed events of asynchronous operations.</p> * <p>A callback abstraction that handles completed/failed events of asynchronous operations.</p>
* *
@ -72,7 +74,7 @@ public interface Callback<C>
@Override @Override
public void failed(C context, Throwable x) public void failed(C context, Throwable x)
{ {
throw new RuntimeException(x); Log.getLogger(this.getClass()).warn(String.valueOf(context),x);
} }
} }
} }