UndertowServerHttpRequest: suspend reading when no demand
- When there is no demand for reading, the implementation should suspend reading otherwise useless events will be send by Undertow to the registered read listener. - There is not need to wait for an event for reading/writing after calling resumeReads/resumeWrites
This commit is contained in:
parent
3e8e0c1d6a
commit
0fbfa64385
|
|
@ -113,6 +113,12 @@ public abstract class AbstractListenerReadPublisher<T> implements Publisher<T> {
|
||||||
@Nullable
|
@Nullable
|
||||||
protected abstract T read() throws IOException;
|
protected abstract T read() throws IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Suspend reading. Defaults to no-op.
|
||||||
|
*/
|
||||||
|
protected void suspendReading() {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read and publish data from the input. Continue till there is no more
|
* Read and publish data from the input. Continue till there is no more
|
||||||
|
|
@ -256,6 +262,7 @@ public abstract class AbstractListenerReadPublisher<T> implements Publisher<T> {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
publisher.changeState(READING, NO_DEMAND);
|
publisher.changeState(READING, NO_DEMAND);
|
||||||
|
publisher.suspendReading();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (IOException ex) {
|
catch (IOException ex) {
|
||||||
|
|
|
||||||
|
|
@ -152,8 +152,29 @@ class UndertowServerHttpRequest extends AbstractServerHttpRequest {
|
||||||
protected void checkOnDataAvailable() {
|
protected void checkOnDataAvailable() {
|
||||||
// TODO: The onDataAvailable() call below can cause a StackOverflowError
|
// TODO: The onDataAvailable() call below can cause a StackOverflowError
|
||||||
// since this method is being called from onDataAvailable() itself.
|
// since this method is being called from onDataAvailable() itself.
|
||||||
|
if (isReadPossible()) {
|
||||||
onDataAvailable();
|
onDataAvailable();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isReadPossible() {
|
||||||
|
if (!this.channel.isReadResumed()) {
|
||||||
|
this.channel.resumeReads();
|
||||||
|
}
|
||||||
|
return this.channel.isReadResumed();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void suspendReading() {
|
||||||
|
this.channel.suspendReads();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAllDataRead() {
|
||||||
|
this.channel.getReadSetter().set(null);
|
||||||
|
this.channel.resumeReads();
|
||||||
|
super.onAllDataRead();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
|
|
|
||||||
|
|
@ -152,12 +152,10 @@ class UndertowServerHttpResponse extends AbstractListenerServerHttpResponse impl
|
||||||
if (this.responseChannel == null) {
|
if (this.responseChannel == null) {
|
||||||
this.responseChannel = this.exchange.getResponseChannel();
|
this.responseChannel = this.exchange.getResponseChannel();
|
||||||
}
|
}
|
||||||
if (this.responseChannel.isWriteResumed()) {
|
if (!this.responseChannel.isWriteResumed()) {
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
this.responseChannel.resumeWrites();
|
this.responseChannel.resumeWrites();
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
return this.responseChannel.isWriteResumed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue