AbstractResponseBodySubscriber improvements
When the thread is writing to the response in RECEIVED.onWritePossible(), the execution may stop because isReady() returned false. In this case the buffer is partially written. When there is partially written case: 1. The state will be changed from WRITING to RECEIVED 2. A check for "write possible" will be performed: - If onWritePossible event has been already called by the web container while in WRITING state then this check will trigger RECEIVED.onWritePossible() because isReady() will be true and the writing will continue. - Otherwise the writing will be resumed when the web container sends onWritePossible event.
This commit is contained in:
@@ -101,6 +101,16 @@ abstract class AbstractResponseBodySubscriber implements Subscriber<DataBuffer>
|
||||
protected void receiveBuffer(DataBuffer dataBuffer) {
|
||||
Assert.state(this.currentBuffer == null);
|
||||
this.currentBuffer = dataBuffer;
|
||||
|
||||
checkOnWritePossible();
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a {@link DataBuffer} is received via {@link Subscriber#onNext(Object)}
|
||||
* or when only partial data from the {@link DataBuffer} was written.
|
||||
*/
|
||||
protected void checkOnWritePossible() {
|
||||
// no-op
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -238,6 +248,7 @@ abstract class AbstractResponseBodySubscriber implements Subscriber<DataBuffer>
|
||||
}
|
||||
else {
|
||||
subscriber.changeState(WRITING, RECEIVED);
|
||||
subscriber.checkOnWritePossible();
|
||||
}
|
||||
}
|
||||
catch (IOException ex) {
|
||||
|
||||
@@ -233,9 +233,7 @@ public class ServletHttpHandlerAdapter extends HttpServlet {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void receiveBuffer(DataBuffer dataBuffer) {
|
||||
super.receiveBuffer(dataBuffer);
|
||||
|
||||
protected void checkOnWritePossible() {
|
||||
try {
|
||||
if (outputStream().isReady()) {
|
||||
onWritePossible();
|
||||
|
||||
Reference in New Issue
Block a user