426750 Handle autoclose on async writes
This commit is contained in:
parent
d4368d1018
commit
8cc9d71e20
|
@ -680,11 +680,12 @@ public class HttpOutput extends ServletOutputStream implements Runnable
|
|||
{
|
||||
Throwable th=_onError;
|
||||
_onError=null;
|
||||
_writeListener.onError(th);
|
||||
_writeListener.onError(new IOException(th));
|
||||
close();
|
||||
}
|
||||
if (_state.get()==OutputState.READY)
|
||||
switch(_state.get())
|
||||
{
|
||||
case READY:
|
||||
try
|
||||
{
|
||||
_writeListener.onWritePossible();
|
||||
|
@ -694,6 +695,24 @@ public class HttpOutput extends ServletOutputStream implements Runnable
|
|||
_writeListener.onError(e);
|
||||
close();
|
||||
}
|
||||
break;
|
||||
|
||||
case CLOSED:
|
||||
try
|
||||
{
|
||||
// even though a write is not possible, because a close has
|
||||
// occurred, we need to call onWritePossible to tell async
|
||||
// producer that the last write completed.
|
||||
_writeListener.onWritePossible();
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
_writeListener.onError(e);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -722,7 +741,7 @@ public class HttpOutput extends ServletOutputStream implements Runnable
|
|||
break;
|
||||
|
||||
case CLOSED:
|
||||
_onError=new EofException("Closed");
|
||||
_channel.getState().onWritePossible();
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
|
@ -547,6 +547,22 @@ public class HttpOutputTest
|
|||
assertThat(response,containsString("400\tThis is a big file"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAsyncWriteSimpleKnown() throws Exception
|
||||
{
|
||||
final Resource big = Resource.newClassPathResource("simple/simple.txt");
|
||||
|
||||
_handler._async=true;
|
||||
_handler._writeLengthIfKnown=true;
|
||||
_handler._content=BufferUtil.toBuffer(big,false);
|
||||
_handler._arrayBuffer=new byte[4000];
|
||||
|
||||
String response=_connector.getResponses("GET / HTTP/1.0\nHost: localhost:80\n\n");
|
||||
assertThat(response,containsString("HTTP/1.1 200 OK"));
|
||||
assertThat(response,containsString("Content-Length: 11"));
|
||||
assertThat(response,containsString("simple text"));
|
||||
}
|
||||
|
||||
static class ContentHandler extends AbstractHandler
|
||||
{
|
||||
boolean _writeLengthIfKnown=true;
|
||||
|
@ -664,7 +680,6 @@ public class HttpOutputTest
|
|||
BufferUtil.flipToFlush(_byteBuffer,0);
|
||||
out.write(_byteBuffer);
|
||||
}
|
||||
Assert.assertFalse(out.isReady());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue