upgrade quiche to version 0.22.0

Signed-off-by: Ludovic Orban <lorban@bitronix.be>
This commit is contained in:
Ludovic Orban 2024-07-08 12:17:14 +02:00
parent aa5d3d018c
commit 03173f4e64
5 changed files with 47 additions and 35 deletions

View File

@ -838,20 +838,21 @@ public class ForeignIncubatorQuicheConnection extends QuicheConnection
throw new IOException("connection was released"); throw new IOException("connection was released");
long written; long written;
try (ResourceScope scope = ResourceScope.newConfinedScope())
{
MemorySegment outErrorCode = MemorySegment.allocateNative(CLinker.C_LONG, scope);
if (buffer.isDirect()) if (buffer.isDirect())
{ {
// If the ByteBuffer is direct, it can be used without any copy. // If the ByteBuffer is direct, it can be used without any copy.
MemorySegment bufferSegment = MemorySegment.ofByteBuffer(buffer); MemorySegment bufferSegment = MemorySegment.ofByteBuffer(buffer);
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());
} }
else else
{ {
// If the ByteBuffer is heap-allocated, it must be copied to native memory. // If the ByteBuffer is heap-allocated, it must be copied to native memory.
try (ResourceScope scope = ResourceScope.newConfinedScope())
{
if (buffer.remaining() == 0) 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 else
{ {
@ -859,7 +860,7 @@ public class ForeignIncubatorQuicheConnection extends QuicheConnection
int prevPosition = buffer.position(); int prevPosition = buffer.position();
bufferSegment.asByteBuffer().put(buffer); bufferSegment.asByteBuffer().put(buffer);
buffer.position(prevPosition); 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());
} }
} }
} }
@ -889,26 +890,27 @@ public class ForeignIncubatorQuicheConnection extends QuicheConnection
long read; long read;
try (ResourceScope scope = ResourceScope.newConfinedScope()) 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 (buffer.isDirect())
{ {
// If the ByteBuffer is direct, it can be used without any copy. // If the ByteBuffer is direct, it can be used without any copy.
MemorySegment bufferSegment = MemorySegment.ofByteBuffer(buffer); 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(), outErrorCode.address());
read = quiche_h.quiche_conn_stream_recv(quicheConn, streamId, bufferSegment.address(), buffer.remaining(), fin.address());
} }
else else
{ {
// If the ByteBuffer is heap-allocated, native memory must be copied to it. // If the ByteBuffer is heap-allocated, native memory must be copied to it.
MemorySegment bufferSegment = MemorySegment.allocateNative(buffer.remaining(), scope); MemorySegment bufferSegment = MemorySegment.allocateNative(buffer.remaining(), scope);
read = quiche_h.quiche_conn_stream_recv(quicheConn, streamId, bufferSegment.address(), buffer.remaining(), fin.address(), outErrorCode.address());
MemorySegment fin = MemorySegment.allocateNative(CLinker.C_CHAR, scope); if (read > 0)
read = quiche_h.quiche_conn_stream_recv(quicheConn, streamId, bufferSegment.address(), buffer.remaining(), fin.address()); {
int prevPosition = buffer.position(); int prevPosition = buffer.position();
buffer.put(bufferSegment.asByteBuffer().limit((int)read)); buffer.put(bufferSegment.asByteBuffer().limit((int)read));
buffer.position(prevPosition); buffer.position(prevPosition);
} }
} }
}
if (read == quiche_error.QUICHE_ERR_DONE) if (read == quiche_error.QUICHE_ERR_DONE)
return isStreamFinished(streamId) ? -1 : 0; return isStreamFinished(streamId) ? -1 : 0;

View File

@ -33,7 +33,7 @@ public class quiche_h
{ {
// This interface is a translation of the quiche.h header of a specific version. // 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. // 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_FALSE = 0;
public static final byte C_TRUE = 1; public static final byte C_TRUE = 1;
@ -312,8 +312,8 @@ public class quiche_h
private static final MethodHandle quiche_conn_stream_send$MH = downcallHandle( private static final MethodHandle quiche_conn_stream_send$MH = downcallHandle(
"quiche_conn_stream_send", "quiche_conn_stream_send",
"(Ljdk/incubator/foreign/MemoryAddress;JLjdk/incubator/foreign/MemoryAddress;JB)J", "(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) 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( private static final MethodHandle quiche_conn_stream_writable$MH = downcallHandle(
@ -324,8 +324,8 @@ public class quiche_h
private static final MethodHandle quiche_conn_stream_recv$MH = downcallHandle( private static final MethodHandle quiche_conn_stream_recv$MH = downcallHandle(
"quiche_conn_stream_recv", "quiche_conn_stream_recv",
"(Ljdk/incubator/foreign/MemoryAddress;JLjdk/incubator/foreign/MemoryAddress;JLjdk/incubator/foreign/MemoryAddress;)J", "(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) 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( private static final MethodHandle quiche_stream_iter_next$MH = downcallHandle(
@ -658,11 +658,11 @@ public class quiche_h
} }
} }
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 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) catch (Throwable ex)
{ {
@ -670,11 +670,11 @@ public class quiche_h
} }
} }
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 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) catch (Throwable ex)
{ {

View File

@ -690,7 +690,8 @@ public class JnaQuicheConnection extends QuicheConnection
{ {
if (quicheConn == null) if (quicheConn == null)
throw new IOException("connection was released"); 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) 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())); int rc = LibQuiche.INSTANCE.quiche_conn_stream_writable(quicheConn, new uint64_t(streamId), new size_t(buffer.remaining()));
@ -742,7 +743,8 @@ public class JnaQuicheConnection extends QuicheConnection
if (quicheConn == null) if (quicheConn == null)
throw new IOException("connection was released"); throw new IOException("connection was released");
bool_pointer fin = new bool_pointer(); 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) if (read == quiche_error.QUICHE_ERR_DONE)
return isStreamFinished(streamId) ? -1 : 0; return isStreamFinished(streamId) ? -1 : 0;
if (read < 0L) if (read < 0L)

View File

@ -31,7 +31,7 @@ public interface LibQuiche extends Library
{ {
// This interface is a translation of the quiche.h header of a specific version. // 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. // 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. // The charset used to convert java.lang.String to char * and vice versa.
Charset CHARSET = StandardCharsets.UTF_8; Charset CHARSET = StandardCharsets.UTF_8;
@ -540,10 +540,18 @@ public interface LibQuiche extends Library
void quiche_stream_iter_free(quiche_stream_iter iter); void quiche_stream_iter_free(quiche_stream_iter iter);
// Reads contiguous data from a stream. // 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. // 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. // Frees the connection object.
void quiche_conn_free(quiche_conn conn); void quiche_conn_free(quiche_conn conn);

View File

@ -265,7 +265,7 @@
<jboss.logging.processor.version>2.2.1.Final</jboss.logging.processor.version> <jboss.logging.processor.version>2.2.1.Final</jboss.logging.processor.version>
<jboss.logging.version>3.6.0.Final</jboss.logging.version> <jboss.logging.version>3.6.0.Final</jboss.logging.version>
<jetty-assembly-descriptors.version>1.1</jetty-assembly-descriptors.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-test-policy.version>1.2</jetty-test-policy.version>
<jetty-version.maven.plugin.version>2.7</jetty-version.maven.plugin.version> <jetty-version.maven.plugin.version>2.7</jetty-version.maven.plugin.version>
<jetty.perf-helper.version>1.0.7</jetty.perf-helper.version> <jetty.perf-helper.version>1.0.7</jetty.perf-helper.version>