GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Only release FileRegion after transfer was done if its configured todo · netty/netty@2a4b91b

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • src/main/java/org/jboss/netty/channel
    • DefaultFileRegion.java
    • socket
      • nio
        • SocketSendBufferPool.java
      • oio
        • OioWorker.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/main/java/org/jboss/netty/channel/DefaultFileRegion.java‎

Copy file name to clipboardExpand all lines: src/main/java/org/jboss/netty/channel/DefaultFileRegion.java
+19-1Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,29 @@ public class DefaultFileRegion implements FileRegion {
1414
private final FileChannel file;
1515
private final long position;
1616
private final long count;
17+
private boolean releaseAfterTransfer;
1718

18-
public DefaultFileRegion(FileChannel file, long position, long count) {
19+
public DefaultFileRegion(FileChannel file, long position, long count, boolean releaseAfterTransfer) {
1920
this.file = file;
2021
this.position = position;
2122
this.count = count;
23+
this.releaseAfterTransfer = releaseAfterTransfer;
2224
}
2325

26+
public DefaultFileRegion(FileChannel file, long position, long count) {
27+
this(file, position, count, false);
28+
}
29+
2430
public long getPosition() {
2531
return position;
2632
}
2733

34+
2835
public long getCount() {
2936
return count;
3037
}
3138

39+
3240
public long transferTo(WritableByteChannel target, long position) throws IOException {
3341
long count = this.count - position;
3442
if (count < 0 || position < 0) {
@@ -43,11 +51,21 @@ public long transferTo(WritableByteChannel target, long position) throws IOExcep
4351
return file.transferTo(this.position + position, count, target);
4452
}
4553

54+
4655
public void releaseExternalResources() {
4756
try {
4857
file.close();
4958
} catch (IOException e) {
5059
logger.warn("Failed to close a file.", e);
5160
}
5261
}
62+
63+
64+
public boolean releaseAfterTransfer() {
65+
return releaseAfterTransfer;
66+
}
67+
68+
public void setReleaseAfterTransfer(boolean releaseAfterTransfer) {
69+
this.releaseAfterTransfer = releaseAfterTransfer;
70+
}
5371
}
Collapse file

‎src/main/java/org/jboss/netty/channel/socket/nio/SocketSendBufferPool.java‎

Copy file name to clipboardExpand all lines: src/main/java/org/jboss/netty/channel/socket/nio/SocketSendBufferPool.java
+7-2Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.nio.channels.WritableByteChannel;
2424

2525
import org.jboss.netty.buffer.ChannelBuffer;
26+
import org.jboss.netty.channel.DefaultFileRegion;
2627
import org.jboss.netty.channel.FileRegion;
2728

2829
/**
@@ -288,8 +289,12 @@ public long transferTo(DatagramChannel ch, SocketAddress raddr)
288289
}
289290

290291
public void release() {
291-
// Make sure the FileRegion resource are released otherwise it may cause a FD leak or something similar
292-
file.releaseExternalResources();
292+
if (file instanceof DefaultFileRegion) {
293+
if (((DefaultFileRegion)file).releaseAfterTransfer()) {
294+
// Make sure the FileRegion resource are released otherwise it may cause a FD leak or something similar
295+
file.releaseExternalResources();
296+
}
297+
}
293298
}
294299
}
295300

Collapse file

‎src/main/java/org/jboss/netty/channel/socket/oio/OioWorker.java‎

Copy file name to clipboardExpand all lines: src/main/java/org/jboss/netty/channel/socket/oio/OioWorker.java
+6-1Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.jboss.netty.buffer.ChannelBuffer;
2929
import org.jboss.netty.channel.Channel;
3030
import org.jboss.netty.channel.ChannelFuture;
31+
import org.jboss.netty.channel.DefaultFileRegion;
3132
import org.jboss.netty.channel.FileRegion;
3233

3334
/**
@@ -141,7 +142,11 @@ static void write(
141142
}
142143
}
143144
} finally {
144-
fr.releaseExternalResources();
145+
if (fr instanceof DefaultFileRegion) {
146+
if (((DefaultFileRegion)fr).releaseAfterTransfer()) {
147+
fr.releaseExternalResources();
148+
}
149+
}
145150

146151
}
147152
} else {

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.