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 — Always correctly calculate the memory address of the ByteBuf even if … · netty/netty@79faea3

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • handler/src/main/java/io/netty/handler/ssl
    • OpenSsl.java
  • transport-native-unix-common/src/main/java/io/netty/channel/unix
    • IovArray.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎handler/src/main/java/io/netty/handler/ssl/OpenSsl.java‎

Copy file name to clipboardExpand all lines: handler/src/main/java/io/netty/handler/ssl/OpenSsl.java
+9-3Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import io.netty.util.internal.logging.InternalLoggerFactory;
3636

3737
import java.io.ByteArrayInputStream;
38+
import java.nio.ByteBuffer;
3839
import java.security.cert.CertificateException;
3940
import java.security.cert.X509Certificate;
4041
import java.util.ArrayList;
@@ -667,9 +668,14 @@ static boolean useKeyManagerFactory() {
667668

668669
static long memoryAddress(ByteBuf buf) {
669670
assert buf.isDirect();
670-
return buf.hasMemoryAddress() ? buf.memoryAddress() :
671-
// Use internalNioBuffer to reduce object creation.
672-
Buffer.address(buf.internalNioBuffer(0, buf.readableBytes()));
671+
if (buf.hasMemoryAddress()) {
672+
return buf.memoryAddress();
673+
}
674+
// Use internalNioBuffer to reduce object creation.
675+
// It is important to add the position as the returned ByteBuffer might be shared by multiple ByteBuf
676+
// instances and so has an address that starts before the start of the ByteBuf itself.
677+
ByteBuffer byteBuffer = buf.internalNioBuffer(0, buf.readableBytes());
678+
return Buffer.address(byteBuffer) + byteBuffer.position();
673679
}
674680

675681
private OpenSsl() { }
Collapse file

‎transport-native-unix-common/src/main/java/io/netty/channel/unix/IovArray.java‎

Copy file name to clipboardExpand all lines: transport-native-unix-common/src/main/java/io/netty/channel/unix/IovArray.java
+6-1Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,12 @@ public IovArray(ByteBuf memory) {
8282
memoryAddress = memory.memoryAddress();
8383
} else {
8484
// Fallback to using JNI as we were not be able to access the address otherwise.
85-
memoryAddress = Buffer.memoryAddress(memory.internalNioBuffer(0, memory.capacity()));
85+
86+
// Use internalNioBuffer to reduce object creation.
87+
// It is important to add the position as the returned ByteBuffer might be shared by multiple ByteBuf
88+
// instances and so has an address that starts before the start of the ByteBuf itself.
89+
ByteBuffer byteBuffer = memory.internalNioBuffer(0, memory.capacity());
90+
memoryAddress = Buffer.memoryAddress(byteBuffer) + byteBuffer.position();
8691
}
8792
}
8893

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.