Only release FileRegion after transfer was done if its configured to do
so. The default is true in the master branch. See NETTY-440
This commit is contained in:
parent
0d78c0508d
commit
c641f24e8f
@ -14,13 +14,28 @@ public class DefaultFileRegion implements FileRegion {
|
||||
private final FileChannel file;
|
||||
private final long position;
|
||||
private final long count;
|
||||
private boolean releaseAfterTransfer;
|
||||
|
||||
public DefaultFileRegion(FileChannel file, long position, long count) {
|
||||
public DefaultFileRegion(FileChannel file, long position, long count, boolean releaseAfterTransfer) {
|
||||
this.file = file;
|
||||
this.position = position;
|
||||
this.count = count;
|
||||
this.releaseAfterTransfer = releaseAfterTransfer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls {@link #DefaultFileRegion(FileChannel, long, long, boolean)} with <code>true</code>
|
||||
* as the last argument.
|
||||
*
|
||||
* @param file
|
||||
* @param position
|
||||
* @param count
|
||||
*/
|
||||
public DefaultFileRegion(FileChannel file, long position, long count) {
|
||||
this(file, position, count, true);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public long getPosition() {
|
||||
return position;
|
||||
@ -54,4 +69,13 @@ public class DefaultFileRegion implements FileRegion {
|
||||
logger.warn("Failed to close a file.", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean releaseAfterTransfer() {
|
||||
return releaseAfterTransfer;
|
||||
}
|
||||
|
||||
public void setReleaseAfterTransfer(boolean releaseAfterTransfer) {
|
||||
this.releaseAfterTransfer = releaseAfterTransfer;
|
||||
}
|
||||
}
|
||||
|
@ -84,4 +84,12 @@ public interface FileRegion extends ExternalResourceReleasable {
|
||||
* byte of the region transferred.
|
||||
*/
|
||||
long transferTo(WritableByteChannel target, long position) throws IOException;
|
||||
|
||||
/**
|
||||
* Returns <code>true</code> if {@link #releaseExternalResources()} should be called after the
|
||||
* transfer of the {@link FileRegion} was complete.
|
||||
*
|
||||
* @return release
|
||||
*/
|
||||
public boolean releaseAfterTransfer();
|
||||
}
|
@ -306,8 +306,10 @@ final class SocketSendBufferPool {
|
||||
|
||||
@Override
|
||||
public void release() {
|
||||
// Make sure the FileRegion resource are released otherwise it may cause a FD leak or something similar
|
||||
file.releaseExternalResources();
|
||||
if (file.releaseAfterTransfer()) {
|
||||
// Make sure the FileRegion resource are released otherwise it may cause a FD leak or something similar
|
||||
file.releaseExternalResources();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -141,7 +141,9 @@ class OioWorker implements Runnable {
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
fr.releaseExternalResources();
|
||||
if (fr.releaseAfterTransfer()) {
|
||||
fr.releaseExternalResources();
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user