Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jetty 10 Upgrade quiche to version 0.22.0 #12042

Merged
merged 1 commit into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -838,28 +838,29 @@ public int feedClearBytesForStream(long streamId, ByteBuffer buffer, boolean las
throw new IOException("connection was released");

long written;
if (buffer.isDirect())
{
// If the ByteBuffer is direct, it can be used without any copy.
MemorySegment bufferSegment = MemorySegment.ofByteBuffer(buffer);
written = quiche_h.quiche_conn_stream_send(quicheConn, streamId, bufferSegment.address(), buffer.remaining(), last ? C_TRUE : C_FALSE);
}
else
try (ResourceScope scope = ResourceScope.newConfinedScope())
{
// If the ByteBuffer is heap-allocated, it must be copied to native memory.
try (ResourceScope scope = ResourceScope.newConfinedScope())
MemorySegment outErrorCode = MemorySegment.allocateNative(CLinker.C_LONG, scope);
if (buffer.isDirect())
{
// If the ByteBuffer is direct, it can be used without any copy.
MemorySegment bufferSegment = MemorySegment.ofByteBuffer(buffer);
written = quiche_h.quiche_conn_stream_send(quicheConn, streamId, bufferSegment.address(), buffer.remaining(), last ? C_TRUE : C_FALSE, outErrorCode.address());
}
else
{
// If the ByteBuffer is heap-allocated, it must be copied to native memory.
if (buffer.remaining() == 0)
{
written = quiche_h.quiche_conn_stream_send(quicheConn, streamId, MemoryAddress.NULL, 0, last ? C_TRUE : C_FALSE);
written = quiche_h.quiche_conn_stream_send(quicheConn, streamId, MemoryAddress.NULL, 0, last ? C_TRUE : C_FALSE, outErrorCode.address());
}
else
{
MemorySegment bufferSegment = MemorySegment.allocateNative(buffer.remaining(), scope);
int prevPosition = buffer.position();
bufferSegment.asByteBuffer().put(buffer);
buffer.position(prevPosition);
written = quiche_h.quiche_conn_stream_send(quicheConn, streamId, bufferSegment.address(), buffer.remaining(), last ? C_TRUE : C_FALSE);
written = quiche_h.quiche_conn_stream_send(quicheConn, streamId, bufferSegment.address(), buffer.remaining(), last ? C_TRUE : C_FALSE, outErrorCode.address());
}
}
}
Expand Down Expand Up @@ -889,24 +890,25 @@ public int drainClearBytesForStream(long streamId, ByteBuffer buffer) throws IOE
long read;
try (ResourceScope scope = ResourceScope.newConfinedScope())
{
MemorySegment fin = MemorySegment.allocateNative(CLinker.C_CHAR, scope);
MemorySegment outErrorCode = MemorySegment.allocateNative(CLinker.C_LONG, scope);
if (buffer.isDirect())
{
// If the ByteBuffer is direct, it can be used without any copy.
MemorySegment bufferSegment = MemorySegment.ofByteBuffer(buffer);
MemorySegment fin = MemorySegment.allocateNative(CLinker.C_CHAR, scope);
read = quiche_h.quiche_conn_stream_recv(quicheConn, streamId, bufferSegment.address(), buffer.remaining(), fin.address());
read = quiche_h.quiche_conn_stream_recv(quicheConn, streamId, bufferSegment.address(), buffer.remaining(), fin.address(), outErrorCode.address());
}
else
{
// If the ByteBuffer is heap-allocated, native memory must be copied to it.
MemorySegment bufferSegment = MemorySegment.allocateNative(buffer.remaining(), scope);

MemorySegment fin = MemorySegment.allocateNative(CLinker.C_CHAR, scope);
read = quiche_h.quiche_conn_stream_recv(quicheConn, streamId, bufferSegment.address(), buffer.remaining(), fin.address());

int prevPosition = buffer.position();
buffer.put(bufferSegment.asByteBuffer().limit((int)read));
buffer.position(prevPosition);
read = quiche_h.quiche_conn_stream_recv(quicheConn, streamId, bufferSegment.address(), buffer.remaining(), fin.address(), outErrorCode.address());
if (read > 0)
{
int prevPosition = buffer.position();
buffer.put(bufferSegment.asByteBuffer().limit((int)read));
buffer.position(prevPosition);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class quiche_h
{
// This interface is a translation of the quiche.h header of a specific version.
// It needs to be reviewed each time the native lib version changes.
private static final String EXPECTED_QUICHE_VERSION = "0.21.0";
private static final String EXPECTED_QUICHE_VERSION = "0.22.0";

public static final byte C_FALSE = 0;
public static final byte C_TRUE = 1;
Expand Down Expand Up @@ -312,8 +312,8 @@ public class quiche_h

private static final MethodHandle quiche_conn_stream_send$MH = downcallHandle(
"quiche_conn_stream_send",
"(Ljdk/incubator/foreign/MemoryAddress;JLjdk/incubator/foreign/MemoryAddress;JB)J",
FunctionDescriptor.of(C_LONG, C_POINTER, C_LONG, C_POINTER, C_LONG, C_CHAR)
"(Ljdk/incubator/foreign/MemoryAddress;JLjdk/incubator/foreign/MemoryAddress;JBLjdk/incubator/foreign/MemoryAddress;)J",
FunctionDescriptor.of(C_LONG, C_POINTER, C_LONG, C_POINTER, C_LONG, C_CHAR, C_POINTER)
);

private static final MethodHandle quiche_conn_stream_writable$MH = downcallHandle(
Expand All @@ -324,8 +324,8 @@ public class quiche_h

private static final MethodHandle quiche_conn_stream_recv$MH = downcallHandle(
"quiche_conn_stream_recv",
"(Ljdk/incubator/foreign/MemoryAddress;JLjdk/incubator/foreign/MemoryAddress;JLjdk/incubator/foreign/MemoryAddress;)J",
FunctionDescriptor.of(C_LONG, C_POINTER, C_LONG, C_POINTER, C_LONG, C_POINTER)
"(Ljdk/incubator/foreign/MemoryAddress;JLjdk/incubator/foreign/MemoryAddress;JLjdk/incubator/foreign/MemoryAddress;Ljdk/incubator/foreign/MemoryAddress;)J",
FunctionDescriptor.of(C_LONG, C_POINTER, C_LONG, C_POINTER, C_LONG, C_POINTER, C_POINTER)
);

private static final MethodHandle quiche_stream_iter_next$MH = downcallHandle(
Expand Down Expand Up @@ -658,23 +658,23 @@ public static MemoryAddress quiche_connect(Addressable server_name, Addressable
}
}

public static long quiche_conn_stream_recv(MemoryAddress conn, long stream_id, MemoryAddress buf, long buf_len, MemoryAddress fin)
public static long quiche_conn_stream_recv(MemoryAddress conn, long stream_id, MemoryAddress buf, long buf_len, MemoryAddress fin, MemoryAddress outErrorCode)
{
try
{
return (long) quiche_conn_stream_recv$MH.invokeExact(conn, stream_id, buf, buf_len, fin);
return (long) quiche_conn_stream_recv$MH.invokeExact(conn, stream_id, buf, buf_len, fin, outErrorCode);
}
catch (Throwable ex)
{
throw new AssertionError("should not reach here", ex);
}
}

public static long quiche_conn_stream_send(MemoryAddress conn, long stream_id, MemoryAddress buf, long buf_len, byte fin)
public static long quiche_conn_stream_send(MemoryAddress conn, long stream_id, MemoryAddress buf, long buf_len, byte fin, MemoryAddress outErrorCode)
{
try
{
return (long) quiche_conn_stream_send$MH.invokeExact(conn, stream_id, buf, buf_len, fin);
return (long) quiche_conn_stream_send$MH.invokeExact(conn, stream_id, buf, buf_len, fin, outErrorCode);
}
catch (Throwable ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,8 @@ public int feedClearBytesForStream(long streamId, ByteBuffer buffer, boolean las
{
if (quicheConn == null)
throw new IOException("connection was released");
int written = LibQuiche.INSTANCE.quiche_conn_stream_send(quicheConn, new uint64_t(streamId), jnaBuffer(buffer), new size_t(buffer.remaining()), last).intValue();
uint64_t_pointer outErrorCode = new uint64_t_pointer();
int written = LibQuiche.INSTANCE.quiche_conn_stream_send(quicheConn, new uint64_t(streamId), jnaBuffer(buffer), new size_t(buffer.remaining()), last, outErrorCode).intValue();
if (written == quiche_error.QUICHE_ERR_DONE)
{
int rc = LibQuiche.INSTANCE.quiche_conn_stream_writable(quicheConn, new uint64_t(streamId), new size_t(buffer.remaining()));
Expand Down Expand Up @@ -742,7 +743,8 @@ public int drainClearBytesForStream(long streamId, ByteBuffer buffer) throws IOE
if (quicheConn == null)
throw new IOException("connection was released");
bool_pointer fin = new bool_pointer();
int read = LibQuiche.INSTANCE.quiche_conn_stream_recv(quicheConn, new uint64_t(streamId), buffer, new size_t(buffer.remaining()), fin).intValue();
uint64_t_pointer outErrorCode = new uint64_t_pointer();
int read = LibQuiche.INSTANCE.quiche_conn_stream_recv(quicheConn, new uint64_t(streamId), buffer, new size_t(buffer.remaining()), fin, outErrorCode).intValue();
if (read == quiche_error.QUICHE_ERR_DONE)
return isStreamFinished(streamId) ? -1 : 0;
if (read < 0L)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public interface LibQuiche extends Library
{
// This interface is a translation of the quiche.h header of a specific version.
// It needs to be reviewed each time the native lib version changes.
String EXPECTED_QUICHE_VERSION = "0.21.0";
String EXPECTED_QUICHE_VERSION = "0.22.0";

// The charset used to convert java.lang.String to char * and vice versa.
Charset CHARSET = StandardCharsets.UTF_8;
Expand Down Expand Up @@ -540,10 +540,18 @@ int quiche_conn_stream_shutdown(quiche_conn conn, uint64_t stream_id,
void quiche_stream_iter_free(quiche_stream_iter iter);

// Reads contiguous data from a stream.
ssize_t quiche_conn_stream_recv(quiche_conn conn, uint64_t stream_id, ByteBuffer out, size_t buf_len, bool_pointer fin);
// out_error_code is only set when STREAM_STOPPED or STREAM_RESET are returned.
// Set to the reported error code associated with STOP_SENDING or STREAM_RESET.
ssize_t quiche_conn_stream_recv(quiche_conn conn, uint64_t stream_id,
ByteBuffer out, size_t buf_len, bool_pointer fin,
uint64_t_pointer out_error_code);

// Writes data to a stream.
ssize_t quiche_conn_stream_send(quiche_conn conn, uint64_t stream_id, ByteBuffer buf, size_t buf_len, boolean fin);
// out_error_code is only set when STREAM_STOPPED or STREAM_RESET are returned.
// Set to the reported error code associated with STOP_SENDING or STREAM_RESET.
ssize_t quiche_conn_stream_send(quiche_conn conn, uint64_t stream_id,
ByteBuffer buf, size_t buf_len, boolean fin,
uint64_t_pointer out_error_code);

// Frees the connection object.
void quiche_conn_free(quiche_conn conn);
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@
<jboss.logging.processor.version>2.2.1.Final</jboss.logging.processor.version>
<jboss.logging.version>3.6.0.Final</jboss.logging.version>
<jetty-assembly-descriptors.version>1.1</jetty-assembly-descriptors.version>
<jetty-quiche-native.version>0.21.0</jetty-quiche-native.version>
<jetty-quiche-native.version>0.22.0</jetty-quiche-native.version>
<jetty-test-policy.version>1.2</jetty-test-policy.version>
<jetty-version.maven.plugin.version>2.7</jetty-version.maven.plugin.version>
<jetty.perf-helper.version>1.0.7</jetty.perf-helper.version>
Expand Down
Loading