Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,18 @@ public void write(ByteBuf data, boolean last) throws IOException {
try {
//do all this in the same lock
synchronized (request.connection()) {
awaitWriteable();
if (last) {
request.response().end(createBuffer(data));
} else {
request.response().write(createBuffer(data));
try {
awaitWriteable();
if (last) {
request.response().end(createBuffer(data));
} else {
request.response().write(createBuffer(data));
}
} catch (Exception e) {
if (data != null && data.refCnt() > 0) {
data.release();
}
throw new IOException("Failed to write", e);
}
}
} finally {
Expand All @@ -95,16 +102,21 @@ private void awaitWriteable() throws IOException {
if (Context.isOnEventLoopThread()) {
throw new IOException("Attempting a blocking write on io thread");
}
if (request.response().closed()) {
throw new IOException("Connection has been closed");
}
if (!drainHandlerRegistered) {
drainHandlerRegistered = true;
request.response().drainHandler(new Handler<Void>() {
Handler<Void> handler = new Handler<Void>() {
@Override
public void handle(Void event) {
if (waitingForDrain) {
request.connection().notifyAll();
}
}
});
};
request.response().drainHandler(handler);
request.response().closeHandler(handler);
}
try {
waitingForDrain = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,13 @@ public void write(final byte[] b, final int off, final int len) throws IOExcepti
rem -= toWrite;
idx += toWrite;
if (!buffer.isWritable()) {
response.writeBlocking(buffer, false);
ByteBuf tmpBuf = buffer;
this.pooledBuffer = buffer = allocator.allocateBuffer();
response.writeBlocking(tmpBuf, false);
}
}
} catch (Exception e) {
if (buffer != null) {
if (buffer != null && buffer.refCnt() > 0) {
buffer.release();
}
throw new IOException(e);
Expand Down