From 788eb253f4f172cd69a7daaf7c401d81b5c02667 Mon Sep 17 00:00:00 2001 From: Gravit Date: Tue, 2 Oct 2018 19:51:07 +0700 Subject: [PATCH] Update FileServerHandler --- .../ClosingChannelFutureListener.java | 22 +++++++++++++++++++ .../fileserver/FileServerHandler.java | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 LaunchServer/src/main/java/ru/gravit/launchserver/fileserver/ClosingChannelFutureListener.java diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/fileserver/ClosingChannelFutureListener.java b/LaunchServer/src/main/java/ru/gravit/launchserver/fileserver/ClosingChannelFutureListener.java new file mode 100644 index 00000000..9cd22a0c --- /dev/null +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/fileserver/ClosingChannelFutureListener.java @@ -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); + } + +} diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/fileserver/FileServerHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/fileserver/FileServerHandler.java index 94dc6e62..5127fdfb 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/fileserver/FileServerHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/fileserver/FileServerHandler.java @@ -169,7 +169,7 @@ public void operationComplete(ChannelProgressiveFuture future) { // Decide whether to close the connection or not. if (!HttpUtil.isKeepAlive(request)) { - // Close the connection when the whole content is written out. + lastContentFuture.addListener(new ClosingChannelFutureListener(raf)); lastContentFuture.addListener(ChannelFutureListener.CLOSE); } }