Skip to content

Commit

Permalink
Upgrade quiche to version 0.22.0 (#11995)
Browse files Browse the repository at this point in the history
upgrade quiche to version 0.22.0

Signed-off-by: Ludovic Orban <[email protected]>
  • Loading branch information
lorban authored Jul 8, 2024
1 parent f199dae commit 78e605a
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -853,28 +853,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.ofBuffer(buffer);
written = quiche_h.quiche_conn_stream_send(quicheConn, streamId, bufferSegment, buffer.remaining(), last);
}
else
try (Arena scope = Arena.ofConfined())
{
// If the ByteBuffer is heap-allocated, it must be copied to native memory.
try (Arena scope = Arena.ofConfined())
MemorySegment outErrorCode = scope.allocate(NativeHelper.C_LONG);
if (buffer.isDirect())
{
// If the ByteBuffer is direct, it can be used without any copy.
MemorySegment bufferSegment = MemorySegment.ofBuffer(buffer);
written = quiche_h.quiche_conn_stream_send(quicheConn, streamId, bufferSegment, buffer.remaining(), last, outErrorCode);
}
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, MemorySegment.NULL, 0, last);
written = quiche_h.quiche_conn_stream_send(quicheConn, streamId, MemorySegment.NULL, 0, last, outErrorCode);
}
else
{
MemorySegment bufferSegment = scope.allocate(buffer.remaining());
int prevPosition = buffer.position();
bufferSegment.asByteBuffer().put(buffer);
buffer.position(prevPosition);
written = quiche_h.quiche_conn_stream_send(quicheConn, streamId, bufferSegment, buffer.remaining(), last);
written = quiche_h.quiche_conn_stream_send(quicheConn, streamId, bufferSegment, buffer.remaining(), last, outErrorCode);
}
}
}
Expand Down Expand Up @@ -904,21 +905,19 @@ public int drainClearBytesForStream(long streamId, ByteBuffer buffer) throws IOE
long read;
try (Arena scope = Arena.ofConfined())
{
MemorySegment fin = scope.allocate(NativeHelper.C_CHAR);
MemorySegment outErrorCode = scope.allocate(NativeHelper.C_LONG);
if (buffer.isDirect())
{
// If the ByteBuffer is direct, it can be used without any copy.
MemorySegment bufferSegment = MemorySegment.ofBuffer(buffer);
MemorySegment fin = scope.allocate(NativeHelper.C_CHAR);
read = quiche_h.quiche_conn_stream_recv(quicheConn, streamId, bufferSegment, buffer.remaining(), fin);
read = quiche_h.quiche_conn_stream_recv(quicheConn, streamId, bufferSegment, buffer.remaining(), fin, outErrorCode);
}
else
{
// If the ByteBuffer is heap-allocated, native memory must be copied to it.
MemorySegment bufferSegment = scope.allocate(buffer.remaining());

MemorySegment fin = scope.allocate(NativeHelper.C_CHAR);
read = quiche_h.quiche_conn_stream_recv(quicheConn, streamId, bufferSegment, buffer.remaining(), fin);

read = quiche_h.quiche_conn_stream_recv(quicheConn, streamId, bufferSegment, buffer.remaining(), fin, outErrorCode);
if (read > 0)
{
int prevPosition = buffer.position();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

public class quiche_h
{
private static final String EXPECTED_QUICHE_VERSION = "0.21.0";
private static final String EXPECTED_QUICHE_VERSION = "0.22.0";
private static final Logger LOG = LoggerFactory.getLogger(quiche_h.class);

private static class LoggingCallback
Expand Down Expand Up @@ -485,6 +485,7 @@ private static class DowncallHandles
C_LONG,
C_POINTER,
C_LONG,
C_POINTER,
C_POINTER
));
private static final MethodHandle quiche_conn_stream_send = NativeHelper.downcallHandle(
Expand All @@ -495,7 +496,8 @@ private static class DowncallHandles
C_LONG,
C_POINTER,
C_LONG,
C_BOOL
C_BOOL,
C_POINTER
));
private static final MethodHandle quiche_conn_stream_priority = NativeHelper.downcallHandle(
"quiche_conn_stream_priority",
Expand Down Expand Up @@ -1662,23 +1664,23 @@ public static long quiche_conn_send_quantum_on_path(MemorySegment conn, MemorySe
}
}

public static long quiche_conn_stream_recv(MemorySegment conn, long stream_id, MemorySegment out, long buf_len, MemorySegment fin)
public static long quiche_conn_stream_recv(MemorySegment conn, long stream_id, MemorySegment out, long buf_len, MemorySegment fin, MemorySegment out_error_code)
{
try
{
return (long)DowncallHandles.quiche_conn_stream_recv.invokeExact(conn, stream_id, out, buf_len, fin);
return (long)DowncallHandles.quiche_conn_stream_recv.invokeExact(conn, stream_id, out, buf_len, fin, out_error_code);
}
catch (Throwable x)
{
throw new AssertionError("should not reach here", x);
}
}

public static long quiche_conn_stream_send(MemorySegment conn, long stream_id, MemorySegment buf, long buf_len, boolean fin)
public static long quiche_conn_stream_send(MemorySegment conn, long stream_id, MemorySegment buf, long buf_len, boolean fin, MemorySegment out_error_code)
{
try
{
return (long)DowncallHandles.quiche_conn_stream_send.invokeExact(conn, stream_id, buf, buf_len, fin);
return (long)DowncallHandles.quiche_conn_stream_send.invokeExact(conn, stream_id, buf, buf_len, fin, out_error_code);
}
catch (Throwable x)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,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 @@ -745,7 +746,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 == quiche_error.QUICHE_ERR_STREAM_RESET)
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 @@ -214,7 +214,7 @@
<jboss.logging.processor.version>2.2.1.Final</jboss.logging.processor.version>
<jboss.logging.version>3.5.3.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

0 comments on commit 78e605a

Please sign in to comment.