#10519 check if the stream is still in a usable state when quiche_conn_stream_send returns QUICHE_ERR_DONE

Signed-off-by: Ludovic Orban <lorban@bitronix.be>
This commit is contained in:
Ludovic Orban 2023-10-18 18:15:31 +02:00
parent caf46b0b0b
commit a8a8c8b9eb
3 changed files with 29 additions and 1 deletions

View File

@ -29,8 +29,8 @@ import jdk.incubator.foreign.MemoryAddress;
import jdk.incubator.foreign.MemorySegment;
import jdk.incubator.foreign.ResourceScope;
import org.eclipse.jetty.quic.quiche.Quiche;
import org.eclipse.jetty.quic.quiche.Quiche.quiche_error;
import org.eclipse.jetty.quic.quiche.Quiche.quic_error;
import org.eclipse.jetty.quic.quiche.Quiche.quiche_error;
import org.eclipse.jetty.quic.quiche.QuicheConfig;
import org.eclipse.jetty.quic.quiche.QuicheConnection;
import org.eclipse.jetty.util.BufferUtil;
@ -865,7 +865,12 @@ public class ForeignIncubatorQuicheConnection extends QuicheConnection
}
if (written == quiche_error.QUICHE_ERR_DONE)
{
int rc = quiche_h.quiche_conn_stream_writable(quicheConn, streamId, buffer.remaining());
if (rc < 0)
throw new IOException("failed to write to stream " + streamId + "; quiche_err=" + quiche_error.errToString(rc));
return 0;
}
if (written < 0L)
throw new IOException("failed to write to stream " + streamId + "; quiche_err=" + quiche_error.errToString(written));
buffer.position((int)(buffer.position() + written));

View File

@ -310,6 +310,12 @@ public class quiche_h
FunctionDescriptor.of(C_LONG, C_POINTER, C_LONG, C_POINTER, C_LONG, C_CHAR)
);
private static final MethodHandle quiche_conn_stream_writable$MH = downcallHandle(
"quiche_conn_stream_writable",
"(Ljdk/incubator/foreign/MemoryAddress;JJ)I",
FunctionDescriptor.of(C_INT, C_POINTER, C_LONG, C_LONG)
);
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",
@ -670,6 +676,18 @@ public class quiche_h
}
}
public static int quiche_conn_stream_writable(MemoryAddress conn, long stream_id, long buf_len)
{
try
{
return (int) quiche_conn_stream_writable$MH.invokeExact(conn, stream_id, buf_len);
}
catch (Throwable ex)
{
throw new AssertionError("should not reach here", ex);
}
}
public static byte quiche_stream_iter_next(MemoryAddress conn, MemoryAddress stream_id)
{
try

View File

@ -692,7 +692,12 @@ public class JnaQuicheConnection extends QuicheConnection
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();
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()));
if (rc < 0)
throw new IOException("failed to write to stream " + streamId + "; quiche_err=" + quiche_error.errToString(rc));
return 0;
}
if (written < 0L)
throw new IOException("failed to write to stream " + streamId + "; quiche_err=" + quiche_error.errToString(written));
buffer.position(buffer.position() + written);