Update FileServerHandler

This commit is contained in:
Gravit 2018-10-02 19:51:07 +07:00
parent e8126f565d
commit 788eb253f4
2 changed files with 23 additions and 1 deletions

View file

@ -0,0 +1,22 @@
package ru.gravit.launchserver.fileserver;
import java.io.Closeable;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import ru.gravit.utils.helper.IOHelper;
public class ClosingChannelFutureListener implements ChannelFutureListener {
public final Closeable[] close;
public ClosingChannelFutureListener(Closeable... close) {
this.close = close;
}
@Override
public void operationComplete(ChannelFuture future) {
for (Closeable cl : close) IOHelper.close(cl);
}
}

View file

@ -169,7 +169,7 @@ public void operationComplete(ChannelProgressiveFuture future) {
// Decide whether to close the connection or not. // Decide whether to close the connection or not.
if (!HttpUtil.isKeepAlive(request)) { if (!HttpUtil.isKeepAlive(request)) {
// Close the connection when the whole content is written out. lastContentFuture.addListener(new ClosingChannelFutureListener(raf));
lastContentFuture.addListener(ChannelFutureListener.CLOSE); lastContentFuture.addListener(ChannelFutureListener.CLOSE);
} }
} }