Merge pull request #33 from normanmaurer/master
Only release FileRegion if configured to do so. See NETTY-440
This commit is contained in:
commit
c8271a2e1d
@ -14,13 +14,28 @@ public class DefaultFileRegion implements FileRegion {
|
|||||||
private final FileChannel file;
|
private final FileChannel file;
|
||||||
private final long position;
|
private final long position;
|
||||||
private final long count;
|
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.file = file;
|
||||||
this.position = position;
|
this.position = position;
|
||||||
this.count = count;
|
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
|
@Override
|
||||||
public long getPosition() {
|
public long getPosition() {
|
||||||
return position;
|
return position;
|
||||||
@ -54,4 +69,13 @@ public class DefaultFileRegion implements FileRegion {
|
|||||||
logger.warn("Failed to close a file.", e);
|
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.
|
* byte of the region transferred.
|
||||||
*/
|
*/
|
||||||
long transferTo(WritableByteChannel target, long position) throws IOException;
|
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
|
@Override
|
||||||
public void release() {
|
public void release() {
|
||||||
// Make sure the FileRegion resource are released otherwise it may cause a FD leak or something similar
|
if (file.releaseAfterTransfer()) {
|
||||||
file.releaseExternalResources();
|
// 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 {
|
} finally {
|
||||||
fr.releaseExternalResources();
|
if (fr.releaseAfterTransfer()) {
|
||||||
|
fr.releaseExternalResources();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user