From 61459a6c410f378c623aff731321109d24ef02b2 Mon Sep 17 00:00:00 2001 From: Oleg Yukhnevich Date: Sat, 2 Mar 2024 10:19:47 +0200 Subject: [PATCH] Remove usages of deprecated in ktor APIs (#250) * introduce BufferPool as a placeholder for something that will (or will not) available after migration to ktor 3.0 and kotlinx-io * will be replaced with something after ktor 3.0 / kotlinx-io migration --- rsocket-core/api/rsocket-core.api | 91 +++++++++---------- .../kotlin/io/rsocket/kotlin/Connection.kt | 11 +-- .../rsocket/kotlin/core/RSocketConnector.kt | 11 ++- .../kotlin/core/RSocketConnectorBuilder.kt | 9 +- .../io/rsocket/kotlin/core/RSocketServer.kt | 13 ++- .../kotlin/core/RSocketServerBuilder.kt | 13 ++- .../io/rsocket/kotlin/frame/ExtensionFrame.kt | 7 +- .../kotlin/io/rsocket/kotlin/frame/Frame.kt | 13 +-- .../io/rsocket/kotlin/frame/KeepAliveFrame.kt | 7 +- .../io/rsocket/kotlin/frame/LeaseFrame.kt | 7 +- .../rsocket/kotlin/frame/MetadataPushFrame.kt | 7 +- .../io/rsocket/kotlin/frame/RequestFrame.kt | 9 +- .../io/rsocket/kotlin/frame/ResumeFrame.kt | 7 +- .../io/rsocket/kotlin/frame/SetupFrame.kt | 7 +- .../io/rsocket/kotlin/frame/io/payload.kt | 8 +- .../kotlin/io/rsocket/kotlin/frame/io/util.kt | 15 ++- .../io/rsocket/kotlin/internal/Connect.kt | 15 +-- .../io/rsocket/kotlin/internal/FrameSender.kt | 9 +- .../kotlin/internal/LoggingConnection.kt | 10 +- .../kotlin/internal/RSocketRequester.kt | 11 +-- .../rsocket/kotlin/internal/StreamsStorage.kt | 11 +-- .../kotlin/internal/handler/FrameHandler.kt | 29 ++++-- .../RequesterRequestChannelFrameHandler.kt | 7 +- .../RequesterRequestResponseFrameHandler.kt | 7 +- .../RequesterRequestStreamFrameHandler.kt | 7 +- .../ResponderFireAndForgetFrameHandler.kt | 7 +- .../ResponderRequestChannelFrameHandler.kt | 7 +- .../ResponderRequestResponseFrameHandler.kt | 7 +- .../ResponderRequestStreamFrameHandler.kt | 7 +- .../kotlin/metadata/CompositeMetadata.kt | 6 +- .../metadata/CompositeMetadataExtensions.kt | 9 +- .../io/rsocket/kotlin/metadata/Metadata.kt | 14 ++- ...erStreamAcceptableDataMimeTypesMetadata.kt | 7 +- .../metadata/PerStreamDataMimeTypeMetadata.kt | 7 +- .../io/rsocket/kotlin/metadata/RawMetadata.kt | 7 +- .../kotlin/metadata/RoutingMetadata.kt | 7 +- .../kotlin/metadata/ZipkinTracingMetadata.kt | 7 +- .../kotlin/metadata/security/AuthMetadata.kt | 9 +- .../metadata/security/BearerAuthMetadata.kt | 7 +- .../metadata/security/RawAuthMetadata.kt | 11 +-- .../metadata/security/SimpleAuthMetadata.kt | 7 +- .../io/rsocket/kotlin/TestConnection.kt | 5 +- .../io/rsocket/kotlin/core/RSocketTest.kt | 4 +- .../kotlin/io/rsocket/kotlin/frame/Util.kt | 5 +- ...equesterRequestResponseFrameHandlerTest.kt | 6 +- .../api/rsocket-internal-io.api | 19 ++++ .../rsocket/kotlin/internal/io/BufferPool.kt | 31 +++++-- .../api/rsocket-ktor-client.api | 4 +- .../io/rsocket/kotlin/ktor/client/Builders.kt | 9 +- .../kotlin/ktor/client/RSocketSupport.kt | 8 +- .../api/rsocket-ktor-server.api | 4 +- .../kotlin/ktor/server/RSocketSupport.kt | 8 +- .../io/rsocket/kotlin/ktor/server/Routing.kt | 9 +- rsocket-test/build.gradle.kts | 3 +- .../rsocket/kotlin/test/InUseTrackingPool.kt | 15 +-- .../kotlin/io/rsocket/kotlin/test/Packets.kt | 21 +---- .../io/rsocket/kotlin/test/TestConfig.kt | 6 +- .../api/rsocket-transport-ktor-tcp.api | 16 ++-- .../transport/ktor/tcp/TcpClientTransport.kt | 12 +-- .../transport/ktor/tcp/TcpConnection.kt | 5 +- .../transport/ktor/tcp/TcpServerTransport.kt | 10 +- .../transport/ktor/tcp/TcpServerTest.kt | 6 +- .../transport/ktor/tcp/TcpTransportTest.kt | 7 +- ...socket-transport-ktor-websocket-client.api | 12 +-- .../client/WebSocketClientTransport.kt | 17 ++-- ...socket-transport-ktor-websocket-server.api | 8 +- .../server/WebSocketServerTransport.kt | 9 +- .../server/WebSocketTransportTest.kt | 7 +- .../api/rsocket-transport-ktor-websocket.api | 3 +- .../ktor/websocket/WebSocketConnection.kt | 5 +- .../api/rsocket-transport-local.api | 3 +- .../kotlin/transport/local/LocalConnection.kt | 5 +- .../kotlin/transport/local/LocalServer.kt | 13 +-- .../transport/local/LocalTransportTest.kt | 5 +- .../nodejs/tcp/TcpClientTransport.kt | 7 +- .../transport/nodejs/tcp/TcpConnection.kt | 5 +- .../nodejs/tcp/TcpServerTransport.kt | 8 +- .../transport/nodejs/tcp/TcpTransportTest.kt | 7 +- 78 files changed, 366 insertions(+), 428 deletions(-) rename rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/frame/io/packet.kt => rsocket-internal-io/src/commonMain/kotlin/io/rsocket/kotlin/internal/io/BufferPool.kt (51%) diff --git a/rsocket-core/api/rsocket-core.api b/rsocket-core/api/rsocket-core.api index 93fc888f..5ca8819d 100644 --- a/rsocket-core/api/rsocket-core.api +++ b/rsocket-core/api/rsocket-core.api @@ -11,15 +11,10 @@ public final class io/rsocket/kotlin/ChannelStrategy : io/rsocket/kotlin/Request } public abstract interface class io/rsocket/kotlin/Connection : kotlinx/coroutines/CoroutineScope { - public abstract fun getPool ()Lio/ktor/utils/io/pool/ObjectPool; public abstract fun receive (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public abstract fun send (Lio/ktor/utils/io/core/ByteReadPacket;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; } -public final class io/rsocket/kotlin/Connection$DefaultImpls { - public static fun getPool (Lio/rsocket/kotlin/Connection;)Lio/ktor/utils/io/pool/ObjectPool; -} - public abstract interface class io/rsocket/kotlin/ConnectionAcceptor { public abstract fun accept (Lio/rsocket/kotlin/ConnectionAcceptorContext;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; } @@ -212,12 +207,14 @@ public final class io/rsocket/kotlin/core/RSocketConnector { public final class io/rsocket/kotlin/core/RSocketConnectorBuilder { public final fun acceptor (Lio/rsocket/kotlin/ConnectionAcceptor;)V public final fun connectionConfig (Lkotlin/jvm/functions/Function1;)V + public final fun getBufferPool-ulmh1bs ()Lio/ktor/utils/io/pool/ObjectPool; public final fun getLoggerFactory ()Lio/rsocket/kotlin/logging/LoggerFactory; public final fun getMaxFragmentSize ()I public final fun interceptors (Lkotlin/jvm/functions/Function1;)V public final fun reconnectable (JLkotlin/jvm/functions/Function2;)V public final fun reconnectable (Lkotlin/jvm/functions/Function3;)V public static synthetic fun reconnectable$default (Lio/rsocket/kotlin/core/RSocketConnectorBuilder;JLkotlin/jvm/functions/Function2;ILjava/lang/Object;)V + public final fun setBufferPool-nnChvZA (Lio/ktor/utils/io/pool/ObjectPool;)V public final fun setLoggerFactory (Lio/rsocket/kotlin/logging/LoggerFactory;)V public final fun setMaxFragmentSize (I)V } @@ -242,9 +239,11 @@ public final class io/rsocket/kotlin/core/RSocketServer { } public final class io/rsocket/kotlin/core/RSocketServerBuilder { + public final fun getBufferPool-ulmh1bs ()Lio/ktor/utils/io/pool/ObjectPool; public final fun getLoggerFactory ()Lio/rsocket/kotlin/logging/LoggerFactory; public final fun getMaxFragmentSize ()I public final fun interceptors (Lkotlin/jvm/functions/Function1;)V + public final fun setBufferPool-nnChvZA (Lio/ktor/utils/io/pool/ObjectPool;)V public final fun setLoggerFactory (Lio/rsocket/kotlin/logging/LoggerFactory;)V public final fun setMaxFragmentSize (I)V } @@ -433,8 +432,8 @@ public final class io/rsocket/kotlin/metadata/CompositeMetadata$Entry { public final class io/rsocket/kotlin/metadata/CompositeMetadata$Reader : io/rsocket/kotlin/metadata/MetadataReader { public fun getMimeType ()Lio/rsocket/kotlin/core/MimeType; - public fun read (Lio/ktor/utils/io/core/ByteReadPacket;Lio/ktor/utils/io/pool/ObjectPool;)Lio/rsocket/kotlin/metadata/CompositeMetadata; - public synthetic fun read (Lio/ktor/utils/io/core/ByteReadPacket;Lio/ktor/utils/io/pool/ObjectPool;)Lio/rsocket/kotlin/metadata/Metadata; + public fun read-sXCisgc (Lio/ktor/utils/io/core/ByteReadPacket;Lio/ktor/utils/io/pool/ObjectPool;)Lio/rsocket/kotlin/metadata/CompositeMetadata; + public synthetic fun read-sXCisgc (Lio/ktor/utils/io/core/ByteReadPacket;Lio/ktor/utils/io/pool/ObjectPool;)Lio/rsocket/kotlin/metadata/Metadata; } public abstract interface class io/rsocket/kotlin/metadata/CompositeMetadataBuilder : java/io/Closeable { @@ -457,10 +456,10 @@ public final class io/rsocket/kotlin/metadata/CompositeMetadataExtensionsKt { public static final fun hasMimeTypeOf (Lio/rsocket/kotlin/metadata/CompositeMetadata$Entry;Lio/rsocket/kotlin/metadata/MetadataReader;)Z public static final fun list (Lio/rsocket/kotlin/metadata/CompositeMetadata;Lio/rsocket/kotlin/core/MimeType;)Ljava/util/List; public static final fun list (Lio/rsocket/kotlin/metadata/CompositeMetadata;Lio/rsocket/kotlin/metadata/MetadataReader;)Ljava/util/List; - public static final fun read (Lio/rsocket/kotlin/metadata/CompositeMetadata$Entry;Lio/rsocket/kotlin/metadata/MetadataReader;Lio/ktor/utils/io/pool/ObjectPool;)Lio/rsocket/kotlin/metadata/Metadata; - public static synthetic fun read$default (Lio/rsocket/kotlin/metadata/CompositeMetadata$Entry;Lio/rsocket/kotlin/metadata/MetadataReader;Lio/ktor/utils/io/pool/ObjectPool;ILjava/lang/Object;)Lio/rsocket/kotlin/metadata/Metadata; - public static final fun readOrNull (Lio/rsocket/kotlin/metadata/CompositeMetadata$Entry;Lio/rsocket/kotlin/metadata/MetadataReader;Lio/ktor/utils/io/pool/ObjectPool;)Lio/rsocket/kotlin/metadata/Metadata; - public static synthetic fun readOrNull$default (Lio/rsocket/kotlin/metadata/CompositeMetadata$Entry;Lio/rsocket/kotlin/metadata/MetadataReader;Lio/ktor/utils/io/pool/ObjectPool;ILjava/lang/Object;)Lio/rsocket/kotlin/metadata/Metadata; + public static final fun read-FTxoUho (Lio/rsocket/kotlin/metadata/CompositeMetadata$Entry;Lio/rsocket/kotlin/metadata/MetadataReader;Lio/ktor/utils/io/pool/ObjectPool;)Lio/rsocket/kotlin/metadata/Metadata; + public static synthetic fun read-FTxoUho$default (Lio/rsocket/kotlin/metadata/CompositeMetadata$Entry;Lio/rsocket/kotlin/metadata/MetadataReader;Lio/ktor/utils/io/pool/ObjectPool;ILjava/lang/Object;)Lio/rsocket/kotlin/metadata/Metadata; + public static final fun readOrNull-FTxoUho (Lio/rsocket/kotlin/metadata/CompositeMetadata$Entry;Lio/rsocket/kotlin/metadata/MetadataReader;Lio/ktor/utils/io/pool/ObjectPool;)Lio/rsocket/kotlin/metadata/Metadata; + public static synthetic fun readOrNull-FTxoUho$default (Lio/rsocket/kotlin/metadata/CompositeMetadata$Entry;Lio/rsocket/kotlin/metadata/MetadataReader;Lio/ktor/utils/io/pool/ObjectPool;ILjava/lang/Object;)Lio/rsocket/kotlin/metadata/Metadata; } public final class io/rsocket/kotlin/metadata/CompositeMetadataFromBuilder : io/rsocket/kotlin/metadata/CompositeMetadata, io/rsocket/kotlin/metadata/CompositeMetadataBuilder { @@ -485,15 +484,15 @@ public abstract interface class io/rsocket/kotlin/metadata/Metadata : java/io/Cl public final class io/rsocket/kotlin/metadata/MetadataKt { public static final fun metadata (Lio/rsocket/kotlin/payload/PayloadBuilder;Lio/rsocket/kotlin/metadata/Metadata;)V - public static final fun read (Lio/ktor/utils/io/core/ByteReadPacket;Lio/rsocket/kotlin/metadata/MetadataReader;Lio/ktor/utils/io/pool/ObjectPool;)Lio/rsocket/kotlin/metadata/Metadata; - public static synthetic fun read$default (Lio/ktor/utils/io/core/ByteReadPacket;Lio/rsocket/kotlin/metadata/MetadataReader;Lio/ktor/utils/io/pool/ObjectPool;ILjava/lang/Object;)Lio/rsocket/kotlin/metadata/Metadata; - public static final fun toPacket (Lio/rsocket/kotlin/metadata/Metadata;Lio/ktor/utils/io/pool/ObjectPool;)Lio/ktor/utils/io/core/ByteReadPacket; - public static synthetic fun toPacket$default (Lio/rsocket/kotlin/metadata/Metadata;Lio/ktor/utils/io/pool/ObjectPool;ILjava/lang/Object;)Lio/ktor/utils/io/core/ByteReadPacket; + public static final fun read-FTxoUho (Lio/ktor/utils/io/core/ByteReadPacket;Lio/rsocket/kotlin/metadata/MetadataReader;Lio/ktor/utils/io/pool/ObjectPool;)Lio/rsocket/kotlin/metadata/Metadata; + public static synthetic fun read-FTxoUho$default (Lio/ktor/utils/io/core/ByteReadPacket;Lio/rsocket/kotlin/metadata/MetadataReader;Lio/ktor/utils/io/pool/ObjectPool;ILjava/lang/Object;)Lio/rsocket/kotlin/metadata/Metadata; + public static final fun toPacket-sXCisgc (Lio/rsocket/kotlin/metadata/Metadata;Lio/ktor/utils/io/pool/ObjectPool;)Lio/ktor/utils/io/core/ByteReadPacket; + public static synthetic fun toPacket-sXCisgc$default (Lio/rsocket/kotlin/metadata/Metadata;Lio/ktor/utils/io/pool/ObjectPool;ILjava/lang/Object;)Lio/ktor/utils/io/core/ByteReadPacket; } public abstract interface class io/rsocket/kotlin/metadata/MetadataReader { public abstract fun getMimeType ()Lio/rsocket/kotlin/core/MimeType; - public abstract fun read (Lio/ktor/utils/io/core/ByteReadPacket;Lio/ktor/utils/io/pool/ObjectPool;)Lio/rsocket/kotlin/metadata/Metadata; + public abstract fun read-sXCisgc (Lio/ktor/utils/io/core/ByteReadPacket;Lio/ktor/utils/io/pool/ObjectPool;)Lio/rsocket/kotlin/metadata/Metadata; } public final class io/rsocket/kotlin/metadata/PerStreamAcceptableDataMimeTypesMetadata : io/rsocket/kotlin/metadata/Metadata { @@ -507,8 +506,8 @@ public final class io/rsocket/kotlin/metadata/PerStreamAcceptableDataMimeTypesMe public final class io/rsocket/kotlin/metadata/PerStreamAcceptableDataMimeTypesMetadata$Reader : io/rsocket/kotlin/metadata/MetadataReader { public fun getMimeType ()Lio/rsocket/kotlin/core/MimeType; - public synthetic fun read (Lio/ktor/utils/io/core/ByteReadPacket;Lio/ktor/utils/io/pool/ObjectPool;)Lio/rsocket/kotlin/metadata/Metadata; - public fun read (Lio/ktor/utils/io/core/ByteReadPacket;Lio/ktor/utils/io/pool/ObjectPool;)Lio/rsocket/kotlin/metadata/PerStreamAcceptableDataMimeTypesMetadata; + public synthetic fun read-sXCisgc (Lio/ktor/utils/io/core/ByteReadPacket;Lio/ktor/utils/io/pool/ObjectPool;)Lio/rsocket/kotlin/metadata/Metadata; + public fun read-sXCisgc (Lio/ktor/utils/io/core/ByteReadPacket;Lio/ktor/utils/io/pool/ObjectPool;)Lio/rsocket/kotlin/metadata/PerStreamAcceptableDataMimeTypesMetadata; } public final class io/rsocket/kotlin/metadata/PerStreamAcceptableDataMimeTypesMetadataKt { @@ -526,8 +525,8 @@ public final class io/rsocket/kotlin/metadata/PerStreamDataMimeTypeMetadata : io public final class io/rsocket/kotlin/metadata/PerStreamDataMimeTypeMetadata$Reader : io/rsocket/kotlin/metadata/MetadataReader { public fun getMimeType ()Lio/rsocket/kotlin/core/MimeType; - public synthetic fun read (Lio/ktor/utils/io/core/ByteReadPacket;Lio/ktor/utils/io/pool/ObjectPool;)Lio/rsocket/kotlin/metadata/Metadata; - public fun read (Lio/ktor/utils/io/core/ByteReadPacket;Lio/ktor/utils/io/pool/ObjectPool;)Lio/rsocket/kotlin/metadata/PerStreamDataMimeTypeMetadata; + public synthetic fun read-sXCisgc (Lio/ktor/utils/io/core/ByteReadPacket;Lio/ktor/utils/io/pool/ObjectPool;)Lio/rsocket/kotlin/metadata/Metadata; + public fun read-sXCisgc (Lio/ktor/utils/io/core/ByteReadPacket;Lio/ktor/utils/io/pool/ObjectPool;)Lio/rsocket/kotlin/metadata/PerStreamDataMimeTypeMetadata; } public final class io/rsocket/kotlin/metadata/RawMetadata : io/rsocket/kotlin/metadata/Metadata { @@ -554,8 +553,8 @@ public final class io/rsocket/kotlin/metadata/RoutingMetadata : io/rsocket/kotli public final class io/rsocket/kotlin/metadata/RoutingMetadata$Reader : io/rsocket/kotlin/metadata/MetadataReader { public fun getMimeType ()Lio/rsocket/kotlin/core/MimeType; - public synthetic fun read (Lio/ktor/utils/io/core/ByteReadPacket;Lio/ktor/utils/io/pool/ObjectPool;)Lio/rsocket/kotlin/metadata/Metadata; - public fun read (Lio/ktor/utils/io/core/ByteReadPacket;Lio/ktor/utils/io/pool/ObjectPool;)Lio/rsocket/kotlin/metadata/RoutingMetadata; + public synthetic fun read-sXCisgc (Lio/ktor/utils/io/core/ByteReadPacket;Lio/ktor/utils/io/pool/ObjectPool;)Lio/rsocket/kotlin/metadata/Metadata; + public fun read-sXCisgc (Lio/ktor/utils/io/core/ByteReadPacket;Lio/ktor/utils/io/pool/ObjectPool;)Lio/rsocket/kotlin/metadata/RoutingMetadata; } public final class io/rsocket/kotlin/metadata/RoutingMetadataKt { @@ -588,8 +587,8 @@ public final class io/rsocket/kotlin/metadata/ZipkinTracingMetadata$Kind : java/ public final class io/rsocket/kotlin/metadata/ZipkinTracingMetadata$Reader : io/rsocket/kotlin/metadata/MetadataReader { public fun getMimeType ()Lio/rsocket/kotlin/core/MimeType; - public synthetic fun read (Lio/ktor/utils/io/core/ByteReadPacket;Lio/ktor/utils/io/pool/ObjectPool;)Lio/rsocket/kotlin/metadata/Metadata; - public fun read (Lio/ktor/utils/io/core/ByteReadPacket;Lio/ktor/utils/io/pool/ObjectPool;)Lio/rsocket/kotlin/metadata/ZipkinTracingMetadata; + public synthetic fun read-sXCisgc (Lio/ktor/utils/io/core/ByteReadPacket;Lio/ktor/utils/io/pool/ObjectPool;)Lio/rsocket/kotlin/metadata/Metadata; + public fun read-sXCisgc (Lio/ktor/utils/io/core/ByteReadPacket;Lio/ktor/utils/io/pool/ObjectPool;)Lio/rsocket/kotlin/metadata/ZipkinTracingMetadata; } public final class io/rsocket/kotlin/metadata/ZipkinTracingMetadataKt { @@ -614,13 +613,13 @@ public final class io/rsocket/kotlin/metadata/security/AuthMetadata$DefaultImpls public abstract interface class io/rsocket/kotlin/metadata/security/AuthMetadataReader : io/rsocket/kotlin/metadata/MetadataReader { public abstract fun getMimeType ()Lio/rsocket/kotlin/core/MimeType; - public abstract fun read (Lio/ktor/utils/io/core/ByteReadPacket;Lio/ktor/utils/io/pool/ObjectPool;)Lio/rsocket/kotlin/metadata/security/AuthMetadata; - public abstract fun readContent (Lio/ktor/utils/io/core/ByteReadPacket;Lio/rsocket/kotlin/metadata/security/AuthType;Lio/ktor/utils/io/pool/ObjectPool;)Lio/rsocket/kotlin/metadata/security/AuthMetadata; + public abstract fun read-sXCisgc (Lio/ktor/utils/io/core/ByteReadPacket;Lio/ktor/utils/io/pool/ObjectPool;)Lio/rsocket/kotlin/metadata/security/AuthMetadata; + public abstract fun readContent-FTxoUho (Lio/ktor/utils/io/core/ByteReadPacket;Lio/rsocket/kotlin/metadata/security/AuthType;Lio/ktor/utils/io/pool/ObjectPool;)Lio/rsocket/kotlin/metadata/security/AuthMetadata; } public final class io/rsocket/kotlin/metadata/security/AuthMetadataReader$DefaultImpls { public static fun getMimeType (Lio/rsocket/kotlin/metadata/security/AuthMetadataReader;)Lio/rsocket/kotlin/core/MimeType; - public static fun read (Lio/rsocket/kotlin/metadata/security/AuthMetadataReader;Lio/ktor/utils/io/core/ByteReadPacket;Lio/ktor/utils/io/pool/ObjectPool;)Lio/rsocket/kotlin/metadata/security/AuthMetadata; + public static fun read-sXCisgc (Lio/rsocket/kotlin/metadata/security/AuthMetadataReader;Lio/ktor/utils/io/core/ByteReadPacket;Lio/ktor/utils/io/pool/ObjectPool;)Lio/rsocket/kotlin/metadata/security/AuthMetadata; } public abstract interface class io/rsocket/kotlin/metadata/security/AuthType { @@ -647,11 +646,11 @@ public final class io/rsocket/kotlin/metadata/security/BearerAuthMetadata : io/r public final class io/rsocket/kotlin/metadata/security/BearerAuthMetadata$Reader : io/rsocket/kotlin/metadata/security/AuthMetadataReader { public fun getMimeType ()Lio/rsocket/kotlin/core/MimeType; - public synthetic fun read (Lio/ktor/utils/io/core/ByteReadPacket;Lio/ktor/utils/io/pool/ObjectPool;)Lio/rsocket/kotlin/metadata/Metadata; - public synthetic fun read (Lio/ktor/utils/io/core/ByteReadPacket;Lio/ktor/utils/io/pool/ObjectPool;)Lio/rsocket/kotlin/metadata/security/AuthMetadata; - public fun read (Lio/ktor/utils/io/core/ByteReadPacket;Lio/ktor/utils/io/pool/ObjectPool;)Lio/rsocket/kotlin/metadata/security/BearerAuthMetadata; - public synthetic fun readContent (Lio/ktor/utils/io/core/ByteReadPacket;Lio/rsocket/kotlin/metadata/security/AuthType;Lio/ktor/utils/io/pool/ObjectPool;)Lio/rsocket/kotlin/metadata/security/AuthMetadata; - public fun readContent (Lio/ktor/utils/io/core/ByteReadPacket;Lio/rsocket/kotlin/metadata/security/AuthType;Lio/ktor/utils/io/pool/ObjectPool;)Lio/rsocket/kotlin/metadata/security/BearerAuthMetadata; + public synthetic fun read-sXCisgc (Lio/ktor/utils/io/core/ByteReadPacket;Lio/ktor/utils/io/pool/ObjectPool;)Lio/rsocket/kotlin/metadata/Metadata; + public synthetic fun read-sXCisgc (Lio/ktor/utils/io/core/ByteReadPacket;Lio/ktor/utils/io/pool/ObjectPool;)Lio/rsocket/kotlin/metadata/security/AuthMetadata; + public fun read-sXCisgc (Lio/ktor/utils/io/core/ByteReadPacket;Lio/ktor/utils/io/pool/ObjectPool;)Lio/rsocket/kotlin/metadata/security/BearerAuthMetadata; + public synthetic fun readContent-FTxoUho (Lio/ktor/utils/io/core/ByteReadPacket;Lio/rsocket/kotlin/metadata/security/AuthType;Lio/ktor/utils/io/pool/ObjectPool;)Lio/rsocket/kotlin/metadata/security/AuthMetadata; + public fun readContent-FTxoUho (Lio/ktor/utils/io/core/ByteReadPacket;Lio/rsocket/kotlin/metadata/security/AuthType;Lio/ktor/utils/io/pool/ObjectPool;)Lio/rsocket/kotlin/metadata/security/BearerAuthMetadata; } public final class io/rsocket/kotlin/metadata/security/CustomAuthType : io/rsocket/kotlin/metadata/security/AuthTypeWithName { @@ -678,19 +677,19 @@ public final class io/rsocket/kotlin/metadata/security/RawAuthMetadata : io/rsoc public final class io/rsocket/kotlin/metadata/security/RawAuthMetadata$Reader : io/rsocket/kotlin/metadata/security/AuthMetadataReader { public fun getMimeType ()Lio/rsocket/kotlin/core/MimeType; - public synthetic fun read (Lio/ktor/utils/io/core/ByteReadPacket;Lio/ktor/utils/io/pool/ObjectPool;)Lio/rsocket/kotlin/metadata/Metadata; - public synthetic fun read (Lio/ktor/utils/io/core/ByteReadPacket;Lio/ktor/utils/io/pool/ObjectPool;)Lio/rsocket/kotlin/metadata/security/AuthMetadata; - public fun read (Lio/ktor/utils/io/core/ByteReadPacket;Lio/ktor/utils/io/pool/ObjectPool;)Lio/rsocket/kotlin/metadata/security/RawAuthMetadata; - public synthetic fun readContent (Lio/ktor/utils/io/core/ByteReadPacket;Lio/rsocket/kotlin/metadata/security/AuthType;Lio/ktor/utils/io/pool/ObjectPool;)Lio/rsocket/kotlin/metadata/security/AuthMetadata; - public fun readContent (Lio/ktor/utils/io/core/ByteReadPacket;Lio/rsocket/kotlin/metadata/security/AuthType;Lio/ktor/utils/io/pool/ObjectPool;)Lio/rsocket/kotlin/metadata/security/RawAuthMetadata; + public synthetic fun read-sXCisgc (Lio/ktor/utils/io/core/ByteReadPacket;Lio/ktor/utils/io/pool/ObjectPool;)Lio/rsocket/kotlin/metadata/Metadata; + public synthetic fun read-sXCisgc (Lio/ktor/utils/io/core/ByteReadPacket;Lio/ktor/utils/io/pool/ObjectPool;)Lio/rsocket/kotlin/metadata/security/AuthMetadata; + public fun read-sXCisgc (Lio/ktor/utils/io/core/ByteReadPacket;Lio/ktor/utils/io/pool/ObjectPool;)Lio/rsocket/kotlin/metadata/security/RawAuthMetadata; + public synthetic fun readContent-FTxoUho (Lio/ktor/utils/io/core/ByteReadPacket;Lio/rsocket/kotlin/metadata/security/AuthType;Lio/ktor/utils/io/pool/ObjectPool;)Lio/rsocket/kotlin/metadata/security/AuthMetadata; + public fun readContent-FTxoUho (Lio/ktor/utils/io/core/ByteReadPacket;Lio/rsocket/kotlin/metadata/security/AuthType;Lio/ktor/utils/io/pool/ObjectPool;)Lio/rsocket/kotlin/metadata/security/RawAuthMetadata; } public final class io/rsocket/kotlin/metadata/security/RawAuthMetadataKt { public static final fun hasAuthTypeOf (Lio/rsocket/kotlin/metadata/security/RawAuthMetadata;Lio/rsocket/kotlin/metadata/security/AuthMetadataReader;)Z - public static final fun read (Lio/rsocket/kotlin/metadata/security/RawAuthMetadata;Lio/rsocket/kotlin/metadata/security/AuthMetadataReader;Lio/ktor/utils/io/pool/ObjectPool;)Lio/rsocket/kotlin/metadata/security/AuthMetadata; - public static synthetic fun read$default (Lio/rsocket/kotlin/metadata/security/RawAuthMetadata;Lio/rsocket/kotlin/metadata/security/AuthMetadataReader;Lio/ktor/utils/io/pool/ObjectPool;ILjava/lang/Object;)Lio/rsocket/kotlin/metadata/security/AuthMetadata; - public static final fun readOrNull (Lio/rsocket/kotlin/metadata/security/RawAuthMetadata;Lio/rsocket/kotlin/metadata/security/AuthMetadataReader;Lio/ktor/utils/io/pool/ObjectPool;)Lio/rsocket/kotlin/metadata/security/AuthMetadata; - public static synthetic fun readOrNull$default (Lio/rsocket/kotlin/metadata/security/RawAuthMetadata;Lio/rsocket/kotlin/metadata/security/AuthMetadataReader;Lio/ktor/utils/io/pool/ObjectPool;ILjava/lang/Object;)Lio/rsocket/kotlin/metadata/security/AuthMetadata; + public static final fun read-FTxoUho (Lio/rsocket/kotlin/metadata/security/RawAuthMetadata;Lio/rsocket/kotlin/metadata/security/AuthMetadataReader;Lio/ktor/utils/io/pool/ObjectPool;)Lio/rsocket/kotlin/metadata/security/AuthMetadata; + public static synthetic fun read-FTxoUho$default (Lio/rsocket/kotlin/metadata/security/RawAuthMetadata;Lio/rsocket/kotlin/metadata/security/AuthMetadataReader;Lio/ktor/utils/io/pool/ObjectPool;ILjava/lang/Object;)Lio/rsocket/kotlin/metadata/security/AuthMetadata; + public static final fun readOrNull-FTxoUho (Lio/rsocket/kotlin/metadata/security/RawAuthMetadata;Lio/rsocket/kotlin/metadata/security/AuthMetadataReader;Lio/ktor/utils/io/pool/ObjectPool;)Lio/rsocket/kotlin/metadata/security/AuthMetadata; + public static synthetic fun readOrNull-FTxoUho$default (Lio/rsocket/kotlin/metadata/security/RawAuthMetadata;Lio/rsocket/kotlin/metadata/security/AuthMetadataReader;Lio/ktor/utils/io/pool/ObjectPool;ILjava/lang/Object;)Lio/rsocket/kotlin/metadata/security/AuthMetadata; } public final class io/rsocket/kotlin/metadata/security/ReservedAuthType : io/rsocket/kotlin/metadata/security/AuthTypeWithId { @@ -718,11 +717,11 @@ public final class io/rsocket/kotlin/metadata/security/SimpleAuthMetadata : io/r public final class io/rsocket/kotlin/metadata/security/SimpleAuthMetadata$Reader : io/rsocket/kotlin/metadata/security/AuthMetadataReader { public fun getMimeType ()Lio/rsocket/kotlin/core/MimeType; - public synthetic fun read (Lio/ktor/utils/io/core/ByteReadPacket;Lio/ktor/utils/io/pool/ObjectPool;)Lio/rsocket/kotlin/metadata/Metadata; - public synthetic fun read (Lio/ktor/utils/io/core/ByteReadPacket;Lio/ktor/utils/io/pool/ObjectPool;)Lio/rsocket/kotlin/metadata/security/AuthMetadata; - public fun read (Lio/ktor/utils/io/core/ByteReadPacket;Lio/ktor/utils/io/pool/ObjectPool;)Lio/rsocket/kotlin/metadata/security/SimpleAuthMetadata; - public synthetic fun readContent (Lio/ktor/utils/io/core/ByteReadPacket;Lio/rsocket/kotlin/metadata/security/AuthType;Lio/ktor/utils/io/pool/ObjectPool;)Lio/rsocket/kotlin/metadata/security/AuthMetadata; - public fun readContent (Lio/ktor/utils/io/core/ByteReadPacket;Lio/rsocket/kotlin/metadata/security/AuthType;Lio/ktor/utils/io/pool/ObjectPool;)Lio/rsocket/kotlin/metadata/security/SimpleAuthMetadata; + public synthetic fun read-sXCisgc (Lio/ktor/utils/io/core/ByteReadPacket;Lio/ktor/utils/io/pool/ObjectPool;)Lio/rsocket/kotlin/metadata/Metadata; + public synthetic fun read-sXCisgc (Lio/ktor/utils/io/core/ByteReadPacket;Lio/ktor/utils/io/pool/ObjectPool;)Lio/rsocket/kotlin/metadata/security/AuthMetadata; + public fun read-sXCisgc (Lio/ktor/utils/io/core/ByteReadPacket;Lio/ktor/utils/io/pool/ObjectPool;)Lio/rsocket/kotlin/metadata/security/SimpleAuthMetadata; + public synthetic fun readContent-FTxoUho (Lio/ktor/utils/io/core/ByteReadPacket;Lio/rsocket/kotlin/metadata/security/AuthType;Lio/ktor/utils/io/pool/ObjectPool;)Lio/rsocket/kotlin/metadata/security/AuthMetadata; + public fun readContent-FTxoUho (Lio/ktor/utils/io/core/ByteReadPacket;Lio/rsocket/kotlin/metadata/security/AuthType;Lio/ktor/utils/io/pool/ObjectPool;)Lio/rsocket/kotlin/metadata/security/SimpleAuthMetadata; } public final class io/rsocket/kotlin/metadata/security/WellKnowAuthType : java/lang/Enum, io/rsocket/kotlin/metadata/security/AuthTypeWithId, io/rsocket/kotlin/metadata/security/AuthTypeWithName { diff --git a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/Connection.kt b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/Connection.kt index 71e2aa08..8cb03268 100644 --- a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/Connection.kt +++ b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/Connection.kt @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,10 +17,9 @@ package io.rsocket.kotlin import io.ktor.utils.io.core.* -import io.ktor.utils.io.core.internal.* -import io.ktor.utils.io.pool.* import io.rsocket.kotlin.frame.* import io.rsocket.kotlin.internal.* +import io.rsocket.kotlin.internal.io.* import kotlinx.coroutines.* /** @@ -28,17 +27,15 @@ import kotlinx.coroutines.* */ @TransportApi public interface Connection : CoroutineScope { - public val pool: ObjectPool get() = ChunkBuffer.Pool - public suspend fun send(packet: ByteReadPacket) public suspend fun receive(): ByteReadPacket } @OptIn(TransportApi::class) -internal suspend inline fun Connection.receiveFrame(block: (frame: Frame) -> T): T = +internal suspend inline fun Connection.receiveFrame(pool: BufferPool, block: (frame: Frame) -> T): T = receive().readFrame(pool).closeOnError(block) @OptIn(TransportApi::class) -internal suspend fun Connection.sendFrame(frame: Frame) { +internal suspend fun Connection.sendFrame(pool: BufferPool, frame: Frame) { frame.toPacket(pool).closeOnError { send(it) } } diff --git a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/core/RSocketConnector.kt b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/core/RSocketConnector.kt index e76ab2a9..de4858c0 100644 --- a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/core/RSocketConnector.kt +++ b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/core/RSocketConnector.kt @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,6 +20,7 @@ import io.rsocket.kotlin.* import io.rsocket.kotlin.frame.* import io.rsocket.kotlin.frame.io.* import io.rsocket.kotlin.internal.* +import io.rsocket.kotlin.internal.io.* import io.rsocket.kotlin.logging.* import io.rsocket.kotlin.transport.* import kotlinx.coroutines.* @@ -32,6 +33,7 @@ public class RSocketConnector internal constructor( private val connectionConfigProvider: () -> ConnectionConfig, private val acceptor: ConnectionAcceptor, private val reconnectPredicate: ReconnectPredicate?, + private val bufferPool: BufferPool, ) { public suspend fun connect(transport: ClientTransport): RSocket = when (reconnectPredicate) { @@ -68,9 +70,10 @@ public class RSocketConnector internal constructor( maxFragmentSize = maxFragmentSize, interceptors = interceptors, connectionConfig = connectionConfig, - acceptor = acceptor + acceptor = acceptor, + bufferPool = bufferPool ) - connection.sendFrame(setupFrame) + connection.sendFrame(bufferPool, setupFrame) return requester } catch (cause: Throwable) { connectionConfig.setupPayload.close() @@ -82,5 +85,5 @@ public class RSocketConnector internal constructor( private fun Connection.wrapConnection(): Connection = interceptors.wrapConnection(this) - .logging(loggerFactory.logger("io.rsocket.kotlin.frame")) + .logging(loggerFactory.logger("io.rsocket.kotlin.frame"), bufferPool) } diff --git a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/core/RSocketConnectorBuilder.kt b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/core/RSocketConnectorBuilder.kt index 6e2cc19d..6adb1ccc 100644 --- a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/core/RSocketConnectorBuilder.kt +++ b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/core/RSocketConnectorBuilder.kt @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,6 +18,7 @@ package io.rsocket.kotlin.core import io.rsocket.kotlin.* import io.rsocket.kotlin.internal.* +import io.rsocket.kotlin.internal.io.* import io.rsocket.kotlin.keepalive.* import io.rsocket.kotlin.logging.* import io.rsocket.kotlin.payload.* @@ -35,6 +36,9 @@ public class RSocketConnectorBuilder internal constructor() { field = value } + @Deprecated("Only for tests in rsocket", level = DeprecationLevel.ERROR) + public var bufferPool: BufferPool = BufferPool.Default + private val connectionConfig: ConnectionConfigBuilder = ConnectionConfigBuilder() private val interceptors: InterceptorsBuilder = InterceptorsBuilder() private var acceptor: ConnectionAcceptor? = null @@ -108,7 +112,8 @@ public class RSocketConnectorBuilder internal constructor() { interceptors.build(), connectionConfig.producer(), acceptor ?: defaultAcceptor, - reconnectPredicate + reconnectPredicate, + @Suppress("DEPRECATION_ERROR") bufferPool ) private companion object { diff --git a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/core/RSocketServer.kt b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/core/RSocketServer.kt index f1391fce..0641d839 100644 --- a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/core/RSocketServer.kt +++ b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/core/RSocketServer.kt @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,6 +20,7 @@ import io.rsocket.kotlin.* import io.rsocket.kotlin.frame.* import io.rsocket.kotlin.frame.io.* import io.rsocket.kotlin.internal.* +import io.rsocket.kotlin.internal.io.* import io.rsocket.kotlin.logging.* import io.rsocket.kotlin.transport.* import kotlinx.coroutines.* @@ -29,6 +30,7 @@ public class RSocketServer internal constructor( private val loggerFactory: LoggerFactory, private val maxFragmentSize: Int, private val interceptors: Interceptors, + private val bufferPool: BufferPool, ) { @DelicateCoroutinesApi @@ -47,7 +49,7 @@ public class RSocketServer internal constructor( } } - private suspend fun Connection.bind(acceptor: ConnectionAcceptor): Job = receiveFrame { setupFrame -> + private suspend fun Connection.bind(acceptor: ConnectionAcceptor): Job = receiveFrame(bufferPool) { setupFrame -> when { setupFrame !is SetupFrame -> failSetup(RSocketError.Setup.Invalid("Invalid setup frame: ${setupFrame.type}")) setupFrame.version != Version.Current -> failSetup(RSocketError.Setup.Unsupported("Unsupported version: ${setupFrame.version}")) @@ -64,7 +66,8 @@ public class RSocketServer internal constructor( payloadMimeType = setupFrame.payloadMimeType, setupPayload = setupFrame.payload ), - acceptor = acceptor + acceptor = acceptor, + bufferPool = bufferPool ) coroutineContext.job } catch (e: Throwable) { @@ -75,13 +78,13 @@ public class RSocketServer internal constructor( @Suppress("SuspendFunctionOnCoroutineScope") private suspend fun Connection.failSetup(error: RSocketError.Setup): Nothing { - sendFrame(ErrorFrame(0, error)) + sendFrame(bufferPool, ErrorFrame(0, error)) cancel("Connection establishment failed", error) throw error } private fun Connection.wrapConnection(): Connection = interceptors.wrapConnection(this) - .logging(loggerFactory.logger("io.rsocket.kotlin.frame")) + .logging(loggerFactory.logger("io.rsocket.kotlin.frame"), bufferPool) } diff --git a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/core/RSocketServerBuilder.kt b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/core/RSocketServerBuilder.kt index 8b15c5ef..f79538e7 100644 --- a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/core/RSocketServerBuilder.kt +++ b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/core/RSocketServerBuilder.kt @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,6 +17,7 @@ package io.rsocket.kotlin.core import io.rsocket.kotlin.* +import io.rsocket.kotlin.internal.io.* import io.rsocket.kotlin.logging.* public class RSocketServerBuilder internal constructor() { @@ -30,6 +31,9 @@ public class RSocketServerBuilder internal constructor() { field = value } + @Deprecated("Only for tests in rsocket", level = DeprecationLevel.ERROR) + public var bufferPool: BufferPool = BufferPool.Default + private val interceptors: InterceptorsBuilder = InterceptorsBuilder() public fun interceptors(configure: InterceptorsBuilder.() -> Unit) { @@ -37,7 +41,12 @@ public class RSocketServerBuilder internal constructor() { } @OptIn(RSocketLoggingApi::class) - internal fun build(): RSocketServer = RSocketServer(loggerFactory, maxFragmentSize, interceptors.build()) + internal fun build(): RSocketServer = RSocketServer( + loggerFactory, + maxFragmentSize, + interceptors.build(), + @Suppress("DEPRECATION_ERROR") bufferPool + ) } public fun RSocketServer(configure: RSocketServerBuilder.() -> Unit = {}): RSocketServer { diff --git a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/frame/ExtensionFrame.kt b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/frame/ExtensionFrame.kt index 11350031..427fa9be 100644 --- a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/frame/ExtensionFrame.kt +++ b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/frame/ExtensionFrame.kt @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,9 +17,8 @@ package io.rsocket.kotlin.frame import io.ktor.utils.io.core.* -import io.ktor.utils.io.core.internal.* -import io.ktor.utils.io.pool.* import io.rsocket.kotlin.frame.io.* +import io.rsocket.kotlin.internal.io.* import io.rsocket.kotlin.payload.* internal class ExtensionFrame( @@ -49,7 +48,7 @@ internal class ExtensionFrame( } } -internal fun ByteReadPacket.readExtension(pool: ObjectPool, streamId: Int, flags: Int): ExtensionFrame { +internal fun ByteReadPacket.readExtension(pool: BufferPool, streamId: Int, flags: Int): ExtensionFrame { val extendedType = readInt() val payload = readPayload(pool, flags) return ExtensionFrame(streamId, extendedType, payload) diff --git a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/frame/Frame.kt b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/frame/Frame.kt index 6b15cb65..53b3f95c 100644 --- a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/frame/Frame.kt +++ b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/frame/Frame.kt @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,9 +17,8 @@ package io.rsocket.kotlin.frame import io.ktor.utils.io.core.* -import io.ktor.utils.io.core.internal.* -import io.ktor.utils.io.pool.* import io.rsocket.kotlin.frame.io.* +import io.rsocket.kotlin.internal.io.* private const val FlagsMask: Int = 1023 private const val FrameTypeShift: Int = 10 @@ -33,9 +32,9 @@ internal sealed class Frame : Closeable { protected abstract fun StringBuilder.appendFlags() protected abstract fun StringBuilder.appendSelf() - internal fun toPacket(pool: ObjectPool): ByteReadPacket { + internal fun toPacket(pool: BufferPool): ByteReadPacket { check(type.canHaveMetadata || !(flags check Flags.Metadata)) { "bad value for metadata flag" } - return buildPacket(pool) { + return pool.buildPacket { writeInt(streamId) writeShort((type.encodedType shl FrameTypeShift or flags).toShort()) writeSelf() @@ -54,7 +53,7 @@ internal sealed class Frame : Closeable { } } -internal fun ByteReadPacket.readFrame(pool: ObjectPool): Frame = use { +internal fun ByteReadPacket.readFrame(pool: BufferPool): Frame = use { val streamId = readInt() val typeAndFlags = readShort().toInt() and 0xFFFF val flags = typeAndFlags and FlagsMask @@ -75,9 +74,11 @@ internal fun ByteReadPacket.readFrame(pool: ObjectPool): Frame = us FrameType.RequestFnF, FrameType.RequestResponse, -> readRequest(pool, type, streamId, flags, withInitial = false) + FrameType.RequestStream, FrameType.RequestChannel, -> readRequest(pool, type, streamId, flags, withInitial = true) + FrameType.Reserved -> error("Reserved") } } diff --git a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/frame/KeepAliveFrame.kt b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/frame/KeepAliveFrame.kt index 64c1b436..06d44a77 100644 --- a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/frame/KeepAliveFrame.kt +++ b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/frame/KeepAliveFrame.kt @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,9 +17,8 @@ package io.rsocket.kotlin.frame import io.ktor.utils.io.core.* -import io.ktor.utils.io.core.internal.* -import io.ktor.utils.io.pool.* import io.rsocket.kotlin.frame.io.* +import io.rsocket.kotlin.internal.io.* private const val RespondFlag = 128 @@ -51,7 +50,7 @@ internal class KeepAliveFrame( } } -internal fun ByteReadPacket.readKeepAlive(pool: ObjectPool, flags: Int): KeepAliveFrame { +internal fun ByteReadPacket.readKeepAlive(pool: BufferPool, flags: Int): KeepAliveFrame { val respond = flags check RespondFlag val lastPosition = readLong() val data = readPacket(pool) diff --git a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/frame/LeaseFrame.kt b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/frame/LeaseFrame.kt index cd705d81..ab20e34a 100644 --- a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/frame/LeaseFrame.kt +++ b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/frame/LeaseFrame.kt @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,9 +17,8 @@ package io.rsocket.kotlin.frame import io.ktor.utils.io.core.* -import io.ktor.utils.io.core.internal.* -import io.ktor.utils.io.pool.* import io.rsocket.kotlin.frame.io.* +import io.rsocket.kotlin.internal.io.* internal class LeaseFrame( val ttl: Int, @@ -50,7 +49,7 @@ internal class LeaseFrame( } } -internal fun ByteReadPacket.readLease(pool: ObjectPool, flags: Int): LeaseFrame { +internal fun ByteReadPacket.readLease(pool: BufferPool, flags: Int): LeaseFrame { val ttl = readInt() val numberOfRequests = readInt() val metadata = if (flags check Flags.Metadata) readMetadata(pool) else null diff --git a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/frame/MetadataPushFrame.kt b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/frame/MetadataPushFrame.kt index 91e6d536..87dab899 100644 --- a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/frame/MetadataPushFrame.kt +++ b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/frame/MetadataPushFrame.kt @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,9 +17,8 @@ package io.rsocket.kotlin.frame import io.ktor.utils.io.core.* -import io.ktor.utils.io.core.internal.* -import io.ktor.utils.io.pool.* import io.rsocket.kotlin.frame.io.* +import io.rsocket.kotlin.internal.io.* internal class MetadataPushFrame( val metadata: ByteReadPacket, @@ -45,5 +44,5 @@ internal class MetadataPushFrame( } } -internal fun ByteReadPacket.readMetadataPush(pool: ObjectPool): MetadataPushFrame = +internal fun ByteReadPacket.readMetadataPush(pool: BufferPool): MetadataPushFrame = MetadataPushFrame(readPacket(pool)) diff --git a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/frame/RequestFrame.kt b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/frame/RequestFrame.kt index b78885ec..8bc70164 100644 --- a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/frame/RequestFrame.kt +++ b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/frame/RequestFrame.kt @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,9 +19,8 @@ package io.rsocket.kotlin.frame import io.ktor.utils.io.core.* -import io.ktor.utils.io.core.internal.* -import io.ktor.utils.io.pool.* import io.rsocket.kotlin.frame.io.* +import io.rsocket.kotlin.internal.io.* import io.rsocket.kotlin.payload.* internal class RequestFrame( @@ -66,11 +65,11 @@ internal class RequestFrame( } internal fun ByteReadPacket.readRequest( - pool: ObjectPool, + pool: BufferPool, type: FrameType, streamId: Int, flags: Int, - withInitial: Boolean + withInitial: Boolean, ): RequestFrame { val fragmentFollows = flags check Flags.Follows val complete = flags check Flags.Complete diff --git a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/frame/ResumeFrame.kt b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/frame/ResumeFrame.kt index 34ee468c..414b86f4 100644 --- a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/frame/ResumeFrame.kt +++ b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/frame/ResumeFrame.kt @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,9 +17,8 @@ package io.rsocket.kotlin.frame import io.ktor.utils.io.core.* -import io.ktor.utils.io.core.internal.* -import io.ktor.utils.io.pool.* import io.rsocket.kotlin.frame.io.* +import io.rsocket.kotlin.internal.io.* internal class ResumeFrame( val version: Version, @@ -50,7 +49,7 @@ internal class ResumeFrame( } } -internal fun ByteReadPacket.readResume(pool: ObjectPool): ResumeFrame { +internal fun ByteReadPacket.readResume(pool: BufferPool): ResumeFrame { val version = readVersion() val resumeToken = readResumeToken(pool) val lastReceivedServerPosition = readLong() diff --git a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/frame/SetupFrame.kt b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/frame/SetupFrame.kt index c2f37402..2345226d 100644 --- a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/frame/SetupFrame.kt +++ b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/frame/SetupFrame.kt @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,9 +17,8 @@ package io.rsocket.kotlin.frame import io.ktor.utils.io.core.* -import io.ktor.utils.io.core.internal.* -import io.ktor.utils.io.pool.* import io.rsocket.kotlin.frame.io.* +import io.rsocket.kotlin.internal.io.* import io.rsocket.kotlin.keepalive.* import io.rsocket.kotlin.payload.* @@ -76,7 +75,7 @@ internal class SetupFrame( } } -internal fun ByteReadPacket.readSetup(pool: ObjectPool, flags: Int): SetupFrame { +internal fun ByteReadPacket.readSetup(pool: BufferPool, flags: Int): SetupFrame { val version = readVersion() val keepAlive = run { val interval = readInt() diff --git a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/frame/io/payload.kt b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/frame/io/payload.kt index b1144874..289cac11 100644 --- a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/frame/io/payload.kt +++ b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/frame/io/payload.kt @@ -1,5 +1,5 @@ /* - * Copyright 2015-2023 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,12 +17,10 @@ package io.rsocket.kotlin.frame.io import io.ktor.utils.io.core.* -import io.ktor.utils.io.core.internal.* -import io.ktor.utils.io.pool.* import io.rsocket.kotlin.internal.io.* import io.rsocket.kotlin.payload.* -internal fun ByteReadPacket.readMetadata(pool: ObjectPool): ByteReadPacket { +internal fun ByteReadPacket.readMetadata(pool: BufferPool): ByteReadPacket { val length = readInt24() return readPacket(pool, length) } @@ -34,7 +32,7 @@ internal fun BytePacketBuilder.writeMetadata(metadata: ByteReadPacket?) { } } -internal fun ByteReadPacket.readPayload(pool: ObjectPool, flags: Int): Payload { +internal fun ByteReadPacket.readPayload(pool: BufferPool, flags: Int): Payload { val metadata = if (flags check Flags.Metadata) readMetadata(pool) else null val data = readPacket(pool) return Payload(data = data, metadata = metadata) diff --git a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/frame/io/util.kt b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/frame/io/util.kt index ca679034..377e7dd6 100644 --- a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/frame/io/util.kt +++ b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/frame/io/util.kt @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,10 +17,9 @@ package io.rsocket.kotlin.frame.io import io.ktor.utils.io.core.* -import io.ktor.utils.io.core.internal.* -import io.ktor.utils.io.pool.* +import io.rsocket.kotlin.internal.io.* -internal fun ByteReadPacket.readResumeToken(pool: ObjectPool): ByteReadPacket { +internal fun ByteReadPacket.readResumeToken(pool: BufferPool): ByteReadPacket { val length = readShort().toInt() and 0xFFFF return readPacket(pool, length) } @@ -33,16 +32,16 @@ internal fun BytePacketBuilder.writeResumeToken(resumeToken: ByteReadPacket?) { } } -internal fun ByteReadPacket.readPacket(pool: ObjectPool): ByteReadPacket { +internal fun ByteReadPacket.readPacket(pool: BufferPool): ByteReadPacket { if (isEmpty) return ByteReadPacket.Empty - return buildPacket(pool) { + return pool.buildPacket { writePacket(this@readPacket) } } -internal fun ByteReadPacket.readPacket(pool: ObjectPool, length: Int): ByteReadPacket { +internal fun ByteReadPacket.readPacket(pool: BufferPool, length: Int): ByteReadPacket { if (length == 0) return ByteReadPacket.Empty - return buildPacket(pool) { + return pool.buildPacket { writePacket(this@readPacket, length) } } diff --git a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/internal/Connect.kt b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/internal/Connect.kt index 71493a64..3d2ece0a 100644 --- a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/internal/Connect.kt +++ b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/internal/Connect.kt @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,7 @@ package io.rsocket.kotlin.internal import io.rsocket.kotlin.* import io.rsocket.kotlin.core.* import io.rsocket.kotlin.frame.* +import io.rsocket.kotlin.internal.io.* import kotlinx.coroutines.* @OptIn(TransportApi::class) @@ -28,11 +29,12 @@ internal suspend inline fun connect( maxFragmentSize: Int, interceptors: Interceptors, connectionConfig: ConnectionConfig, - acceptor: ConnectionAcceptor + acceptor: ConnectionAcceptor, + bufferPool: BufferPool, ): RSocket { val prioritizer = Prioritizer() - val frameSender = FrameSender(prioritizer, connection.pool, maxFragmentSize) - val streamsStorage = StreamsStorage(isServer, connection.pool) + val frameSender = FrameSender(prioritizer, bufferPool, maxFragmentSize) + val streamsStorage = StreamsStorage(isServer) val keepAliveHandler = KeepAliveHandler(connectionConfig.keepAlive, frameSender) val requestJob = SupervisorJob(connection.coroutineContext[Job]) @@ -49,7 +51,6 @@ internal suspend inline fun connect( requestContext + CoroutineName("rSocket-requester"), frameSender, streamsStorage, - connection.pool ) ) val requestHandler = interceptors.wrapResponder( @@ -82,12 +83,12 @@ internal suspend inline fun connect( // start sending frames to connection (connection + CoroutineName("rSocket-connection-send")).launch { - while (isActive) connection.sendFrame(prioritizer.receive()) + while (isActive) connection.sendFrame(bufferPool, prioritizer.receive()) } // start frame handling (connection + CoroutineName("rSocket-connection-receive")).launch { - while (isActive) connection.receiveFrame { frame -> + while (isActive) connection.receiveFrame(bufferPool) { frame -> when (frame.streamId) { 0 -> when (frame) { is MetadataPushFrame -> responder.handleMetadataPush(frame.metadata) diff --git a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/internal/FrameSender.kt b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/internal/FrameSender.kt index bddb76b3..240936bb 100644 --- a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/internal/FrameSender.kt +++ b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/internal/FrameSender.kt @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,10 +17,9 @@ package io.rsocket.kotlin.internal import io.ktor.utils.io.core.* -import io.ktor.utils.io.core.internal.* -import io.ktor.utils.io.pool.* import io.rsocket.kotlin.frame.* import io.rsocket.kotlin.frame.io.* +import io.rsocket.kotlin.internal.io.* import io.rsocket.kotlin.payload.* import kotlinx.coroutines.* import kotlin.math.* @@ -32,8 +31,8 @@ private const val fragmentOffsetWithMetadata = fragmentOffset + lengthSize internal class FrameSender( private val prioritizer: Prioritizer, - private val pool: ObjectPool, - private val maxFragmentSize: Int + private val pool: BufferPool, + private val maxFragmentSize: Int, ) { suspend fun sendKeepAlive(respond: Boolean, lastPosition: Long, data: ByteReadPacket): Unit = diff --git a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/internal/LoggingConnection.kt b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/internal/LoggingConnection.kt index ff77435f..0ac632b8 100644 --- a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/internal/LoggingConnection.kt +++ b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/internal/LoggingConnection.kt @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,19 +21,21 @@ package io.rsocket.kotlin.internal import io.ktor.utils.io.core.* import io.rsocket.kotlin.* import io.rsocket.kotlin.frame.* +import io.rsocket.kotlin.internal.io.* import io.rsocket.kotlin.logging.* -internal fun Connection.logging(logger: Logger): Connection = - if (logger.isLoggable(LoggingLevel.DEBUG)) LoggingConnection(this, logger) else this +internal fun Connection.logging(logger: Logger, bufferPool: BufferPool): Connection = + if (logger.isLoggable(LoggingLevel.DEBUG)) LoggingConnection(this, logger, bufferPool) else this private class LoggingConnection( private val delegate: Connection, private val logger: Logger, + private val bufferPool: BufferPool, ) : Connection by delegate { private fun ByteReadPacket.dumpFrameToString(): String { val length = remaining - return copy().use { it.readFrame(pool).use { it.dump(length) } } + return copy().use { it.readFrame(bufferPool).use { it.dump(length) } } } override suspend fun send(packet: ByteReadPacket) { diff --git a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/internal/RSocketRequester.kt b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/internal/RSocketRequester.kt index edf2fbca..e3b91e32 100644 --- a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/internal/RSocketRequester.kt +++ b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/internal/RSocketRequester.kt @@ -1,5 +1,5 @@ /* - * Copyright 2015-2023 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,8 +17,6 @@ package io.rsocket.kotlin.internal import io.ktor.utils.io.core.* -import io.ktor.utils.io.core.internal.* -import io.ktor.utils.io.pool.* import io.rsocket.kotlin.* import io.rsocket.kotlin.frame.* import io.rsocket.kotlin.internal.handler.* @@ -35,7 +33,6 @@ internal class RSocketRequester( override val coroutineContext: CoroutineContext, private val sender: FrameSender, private val streamsStorage: StreamsStorage, - private val pool: ObjectPool ) : RSocket { override suspend fun metadataPush(metadata: ByteReadPacket) { @@ -64,7 +61,7 @@ internal class RSocketRequester( val id = streamsStorage.nextId() val deferred = CompletableDeferred() - val handler = RequesterRequestResponseFrameHandler(id, streamsStorage, deferred, pool) + val handler = RequesterRequestResponseFrameHandler(id, streamsStorage, deferred) streamsStorage.save(id, handler) return handler.receiveOrCancel(id, payload) { @@ -79,7 +76,7 @@ internal class RSocketRequester( val id = streamsStorage.nextId() val channel = channelForCloseable(Channel.UNLIMITED) - val handler = RequesterRequestStreamFrameHandler(id, streamsStorage, channel, pool) + val handler = RequesterRequestStreamFrameHandler(id, streamsStorage, channel) streamsStorage.save(id, handler) handler.receiveOrCancel(id, payload) { @@ -97,7 +94,7 @@ internal class RSocketRequester( val channel = channelForCloseable(Channel.UNLIMITED) val limiter = Limiter(0) val payloadsJob = Job(this@RSocketRequester.coroutineContext.job) - val handler = RequesterRequestChannelFrameHandler(id, streamsStorage, limiter, payloadsJob, channel, pool) + val handler = RequesterRequestChannelFrameHandler(id, streamsStorage, limiter, payloadsJob, channel) streamsStorage.save(id, handler) handler.receiveOrCancel(id, initPayload) { diff --git a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/internal/StreamsStorage.kt b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/internal/StreamsStorage.kt index 65aa2eb6..e6956a9f 100644 --- a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/internal/StreamsStorage.kt +++ b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/internal/StreamsStorage.kt @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,15 +16,12 @@ package io.rsocket.kotlin.internal -import io.ktor.utils.io.core.internal.* -import io.ktor.utils.io.pool.* import io.rsocket.kotlin.frame.* import io.rsocket.kotlin.internal.handler.* import kotlinx.atomicfu.locks.* internal class StreamsStorage( private val isServer: Boolean, - private val pool: ObjectPool ) : SynchronizedObject() { private val streamId: StreamId = StreamId(isServer) private val handlers: IntMap = IntMap() @@ -60,21 +57,19 @@ internal class StreamsStorage( else -> { val initialRequest = frame.initialRequest val handler = when (frame.type) { - FrameType.RequestFnF -> ResponderFireAndForgetFrameHandler(id, this, responder, pool) - FrameType.RequestResponse -> ResponderRequestResponseFrameHandler(id, this, responder, pool) + FrameType.RequestFnF -> ResponderFireAndForgetFrameHandler(id, this, responder) + FrameType.RequestResponse -> ResponderRequestResponseFrameHandler(id, this, responder) FrameType.RequestStream -> ResponderRequestStreamFrameHandler( id, this, responder, initialRequest, - pool ) FrameType.RequestChannel -> ResponderRequestChannelFrameHandler( id, this, responder, initialRequest, - pool ) else -> error("Wrong request frame type") // should never happen } diff --git a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/internal/handler/FrameHandler.kt b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/internal/handler/FrameHandler.kt index 2c531e65..3ac33d79 100644 --- a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/internal/handler/FrameHandler.kt +++ b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/internal/handler/FrameHandler.kt @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,9 +23,9 @@ import io.rsocket.kotlin.frame.* import io.rsocket.kotlin.payload.* import kotlinx.coroutines.* -internal abstract class FrameHandler(pool: ObjectPool) : Closeable { - private val data = BytePacketBuilder(pool) - private val metadata = BytePacketBuilder(pool) +internal abstract class FrameHandler : Closeable { + private val data = BytePacketBuilder(NoPool) + private val metadata = BytePacketBuilder(NoPool) private var hasMetadata: Boolean = false fun handleRequest(frame: RequestFrame) { @@ -73,7 +73,7 @@ internal interface SendFrameHandler { fun onSendFailed(cause: Throwable): Boolean // if true, then request is failed } -internal abstract class RequesterFrameHandler(pool: ObjectPool) : FrameHandler(pool), ReceiveFrameHandler { +internal abstract class RequesterFrameHandler : FrameHandler(), ReceiveFrameHandler { override fun handleCancel() { //should be called only for RC } @@ -83,7 +83,7 @@ internal abstract class RequesterFrameHandler(pool: ObjectPool) : F } } -internal abstract class ResponderFrameHandler(pool: ObjectPool) : FrameHandler(pool), SendFrameHandler { +internal abstract class ResponderFrameHandler : FrameHandler(), SendFrameHandler { protected var job: Job? = null protected abstract fun start(payload: Payload): Job @@ -105,3 +105,20 @@ internal abstract class ResponderFrameHandler(pool: ObjectPool) : F //should be called only for RC } } + +private object NoPool : ObjectPool { + override val capacity: Int + get() = error("should not be called") + + override fun borrow(): ChunkBuffer { + error("should not be called") + } + + override fun dispose() { + error("should not be called") + } + + override fun recycle(instance: ChunkBuffer) { + error("should not be called") + } +} diff --git a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/internal/handler/RequesterRequestChannelFrameHandler.kt b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/internal/handler/RequesterRequestChannelFrameHandler.kt index ad5f007a..709438f9 100644 --- a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/internal/handler/RequesterRequestChannelFrameHandler.kt +++ b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/internal/handler/RequesterRequestChannelFrameHandler.kt @@ -1,5 +1,5 @@ /* - * Copyright 2015-2023 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,8 +16,6 @@ package io.rsocket.kotlin.internal.handler -import io.ktor.utils.io.core.internal.* -import io.ktor.utils.io.pool.* import io.rsocket.kotlin.internal.* import io.rsocket.kotlin.internal.io.* import io.rsocket.kotlin.payload.* @@ -30,8 +28,7 @@ internal class RequesterRequestChannelFrameHandler( private val limiter: Limiter, private val sender: Job, private val channel: Channel, - pool: ObjectPool -) : RequesterFrameHandler(pool), SendFrameHandler { +) : RequesterFrameHandler(), SendFrameHandler { override fun handleNext(payload: Payload) { channel.safeTrySend(payload) diff --git a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/internal/handler/RequesterRequestResponseFrameHandler.kt b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/internal/handler/RequesterRequestResponseFrameHandler.kt index 85146fbb..dfe734e7 100644 --- a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/internal/handler/RequesterRequestResponseFrameHandler.kt +++ b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/internal/handler/RequesterRequestResponseFrameHandler.kt @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,8 +16,6 @@ package io.rsocket.kotlin.internal.handler -import io.ktor.utils.io.core.internal.* -import io.ktor.utils.io.pool.* import io.rsocket.kotlin.internal.* import io.rsocket.kotlin.payload.* import kotlinx.coroutines.* @@ -26,8 +24,7 @@ internal class RequesterRequestResponseFrameHandler( private val id: Int, private val streamsStorage: StreamsStorage, private val deferred: CompletableDeferred, - pool: ObjectPool -) : RequesterFrameHandler(pool) { +) : RequesterFrameHandler() { override fun handleNext(payload: Payload) { deferred.complete(payload) } diff --git a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/internal/handler/RequesterRequestStreamFrameHandler.kt b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/internal/handler/RequesterRequestStreamFrameHandler.kt index fbc1bc32..227fd3c3 100644 --- a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/internal/handler/RequesterRequestStreamFrameHandler.kt +++ b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/internal/handler/RequesterRequestStreamFrameHandler.kt @@ -1,5 +1,5 @@ /* - * Copyright 2015-2023 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,8 +16,6 @@ package io.rsocket.kotlin.internal.handler -import io.ktor.utils.io.core.internal.* -import io.ktor.utils.io.pool.* import io.rsocket.kotlin.internal.* import io.rsocket.kotlin.internal.io.* import io.rsocket.kotlin.payload.* @@ -27,8 +25,7 @@ internal class RequesterRequestStreamFrameHandler( private val id: Int, private val streamsStorage: StreamsStorage, private val channel: Channel, - pool: ObjectPool -) : RequesterFrameHandler(pool) { +) : RequesterFrameHandler() { override fun handleNext(payload: Payload) { channel.safeTrySend(payload) diff --git a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/internal/handler/ResponderFireAndForgetFrameHandler.kt b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/internal/handler/ResponderFireAndForgetFrameHandler.kt index f56cbdd1..abef9352 100644 --- a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/internal/handler/ResponderFireAndForgetFrameHandler.kt +++ b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/internal/handler/ResponderFireAndForgetFrameHandler.kt @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,8 +16,6 @@ package io.rsocket.kotlin.internal.handler -import io.ktor.utils.io.core.internal.* -import io.ktor.utils.io.pool.* import io.rsocket.kotlin.internal.* import io.rsocket.kotlin.payload.* import kotlinx.coroutines.* @@ -26,8 +24,7 @@ internal class ResponderFireAndForgetFrameHandler( private val id: Int, private val streamsStorage: StreamsStorage, private val responder: RSocketResponder, - pool: ObjectPool -) : ResponderFrameHandler(pool) { +) : ResponderFrameHandler() { override fun start(payload: Payload): Job = responder.handleFireAndForget(payload, this) diff --git a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/internal/handler/ResponderRequestChannelFrameHandler.kt b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/internal/handler/ResponderRequestChannelFrameHandler.kt index 45be9a63..c73c2b0b 100644 --- a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/internal/handler/ResponderRequestChannelFrameHandler.kt +++ b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/internal/handler/ResponderRequestChannelFrameHandler.kt @@ -1,5 +1,5 @@ /* - * Copyright 2015-2023 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,8 +16,6 @@ package io.rsocket.kotlin.internal.handler -import io.ktor.utils.io.core.internal.* -import io.ktor.utils.io.pool.* import io.rsocket.kotlin.* import io.rsocket.kotlin.internal.* import io.rsocket.kotlin.internal.io.* @@ -30,8 +28,7 @@ internal class ResponderRequestChannelFrameHandler( private val streamsStorage: StreamsStorage, private val responder: RSocketResponder, initialRequest: Int, - pool: ObjectPool -) : ResponderFrameHandler(pool), ReceiveFrameHandler { +) : ResponderFrameHandler(), ReceiveFrameHandler { val limiter = Limiter(initialRequest) val channel = channelForCloseable(Channel.UNLIMITED) diff --git a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/internal/handler/ResponderRequestResponseFrameHandler.kt b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/internal/handler/ResponderRequestResponseFrameHandler.kt index b24a0c75..61084100 100644 --- a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/internal/handler/ResponderRequestResponseFrameHandler.kt +++ b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/internal/handler/ResponderRequestResponseFrameHandler.kt @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,8 +16,6 @@ package io.rsocket.kotlin.internal.handler -import io.ktor.utils.io.core.internal.* -import io.ktor.utils.io.pool.* import io.rsocket.kotlin.internal.* import io.rsocket.kotlin.payload.* import kotlinx.coroutines.* @@ -26,8 +24,7 @@ internal class ResponderRequestResponseFrameHandler( private val id: Int, private val streamsStorage: StreamsStorage, private val responder: RSocketResponder, - pool: ObjectPool -) : ResponderFrameHandler(pool) { +) : ResponderFrameHandler() { override fun start(payload: Payload): Job = responder.handleRequestResponse(payload, id, this) diff --git a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/internal/handler/ResponderRequestStreamFrameHandler.kt b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/internal/handler/ResponderRequestStreamFrameHandler.kt index 6cfa95a6..f7932b46 100644 --- a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/internal/handler/ResponderRequestStreamFrameHandler.kt +++ b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/internal/handler/ResponderRequestStreamFrameHandler.kt @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,8 +16,6 @@ package io.rsocket.kotlin.internal.handler -import io.ktor.utils.io.core.internal.* -import io.ktor.utils.io.pool.* import io.rsocket.kotlin.internal.* import io.rsocket.kotlin.payload.* import kotlinx.coroutines.* @@ -27,8 +25,7 @@ internal class ResponderRequestStreamFrameHandler( private val streamsStorage: StreamsStorage, private val responder: RSocketResponder, initialRequest: Int, - pool: ObjectPool -) : ResponderFrameHandler(pool) { +) : ResponderFrameHandler() { val limiter = Limiter(initialRequest) override fun start(payload: Payload): Job = responder.handleRequestStream(payload, id, this) diff --git a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/metadata/CompositeMetadata.kt b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/metadata/CompositeMetadata.kt index 3b40dd82..1e2b75a5 100644 --- a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/metadata/CompositeMetadata.kt +++ b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/metadata/CompositeMetadata.kt @@ -1,5 +1,5 @@ /* - * Copyright 2015-2023 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,8 +17,6 @@ package io.rsocket.kotlin.metadata import io.ktor.utils.io.core.* -import io.ktor.utils.io.core.internal.* -import io.ktor.utils.io.pool.* import io.rsocket.kotlin.* import io.rsocket.kotlin.core.* import io.rsocket.kotlin.frame.io.* @@ -55,7 +53,7 @@ public sealed interface CompositeMetadata : Metadata { public companion object Reader : MetadataReader { override val mimeType: MimeType get() = WellKnownMimeType.MessageRSocketCompositeMetadata - override fun ByteReadPacket.read(pool: ObjectPool): CompositeMetadata { + override fun ByteReadPacket.read(pool: BufferPool): CompositeMetadata { val list = mutableListOf() while (isNotEmpty) { val type = readMimeType() diff --git a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/metadata/CompositeMetadataExtensions.kt b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/metadata/CompositeMetadataExtensions.kt index 573742df..18c480fe 100644 --- a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/metadata/CompositeMetadataExtensions.kt +++ b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/metadata/CompositeMetadataExtensions.kt @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,10 +17,9 @@ package io.rsocket.kotlin.metadata import io.ktor.utils.io.core.* -import io.ktor.utils.io.core.internal.* -import io.ktor.utils.io.pool.* import io.rsocket.kotlin.* import io.rsocket.kotlin.core.* +import io.rsocket.kotlin.internal.io.* @ExperimentalMetadataApi public fun CompositeMetadata.Entry.hasMimeTypeOf(reader: MetadataReader<*>): Boolean = mimeType == reader.mimeType @@ -28,7 +27,7 @@ public fun CompositeMetadata.Entry.hasMimeTypeOf(reader: MetadataReader<*>): Boo @ExperimentalMetadataApi public fun CompositeMetadata.Entry.read( reader: MetadataReader, - pool: ObjectPool = ChunkBuffer.Pool + pool: BufferPool = BufferPool.Default, ): M { if (mimeType == reader.mimeType) return content.read(reader, pool) @@ -39,7 +38,7 @@ public fun CompositeMetadata.Entry.read( @ExperimentalMetadataApi public fun CompositeMetadata.Entry.readOrNull( reader: MetadataReader, - pool: ObjectPool = ChunkBuffer.Pool + pool: BufferPool = BufferPool.Default, ): M? { return if (mimeType == reader.mimeType) content.read(reader, pool) else null } diff --git a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/metadata/Metadata.kt b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/metadata/Metadata.kt index 5ab9b987..11085933 100644 --- a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/metadata/Metadata.kt +++ b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/metadata/Metadata.kt @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,11 +17,9 @@ package io.rsocket.kotlin.metadata import io.ktor.utils.io.core.* -import io.ktor.utils.io.core.internal.* -import io.ktor.utils.io.pool.* import io.rsocket.kotlin.* import io.rsocket.kotlin.core.* -import io.rsocket.kotlin.frame.io.* +import io.rsocket.kotlin.internal.io.* import io.rsocket.kotlin.payload.* @ExperimentalMetadataApi @@ -33,7 +31,7 @@ public interface Metadata : Closeable { @ExperimentalMetadataApi public interface MetadataReader { public val mimeType: MimeType - public fun ByteReadPacket.read(pool: ObjectPool): M + public fun ByteReadPacket.read(pool: BufferPool): M } @@ -43,11 +41,11 @@ public fun PayloadBuilder.metadata(metadata: Metadata): Unit = metadata(metadata @ExperimentalMetadataApi public fun ByteReadPacket.read( reader: MetadataReader, - pool: ObjectPool = ChunkBuffer.Pool + pool: BufferPool = BufferPool.Default, ): M = use { with(reader) { read(pool) } } @ExperimentalMetadataApi -public fun Metadata.toPacket(pool: ObjectPool = ChunkBuffer.Pool): ByteReadPacket = - buildPacket(pool) { writeSelf() } +public fun Metadata.toPacket(pool: BufferPool = BufferPool.Default): ByteReadPacket = + pool.buildPacket { writeSelf() } diff --git a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/metadata/PerStreamAcceptableDataMimeTypesMetadata.kt b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/metadata/PerStreamAcceptableDataMimeTypesMetadata.kt index c0fc8a79..c3de0e13 100644 --- a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/metadata/PerStreamAcceptableDataMimeTypesMetadata.kt +++ b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/metadata/PerStreamAcceptableDataMimeTypesMetadata.kt @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,11 +17,10 @@ package io.rsocket.kotlin.metadata import io.ktor.utils.io.core.* -import io.ktor.utils.io.core.internal.* -import io.ktor.utils.io.pool.* import io.rsocket.kotlin.* import io.rsocket.kotlin.core.* import io.rsocket.kotlin.frame.io.* +import io.rsocket.kotlin.internal.io.* @ExperimentalMetadataApi public fun PerStreamAcceptableDataMimeTypesMetadata(vararg tags: MimeType): PerStreamAcceptableDataMimeTypesMetadata = @@ -41,7 +40,7 @@ public class PerStreamAcceptableDataMimeTypesMetadata(public val types: List { override val mimeType: MimeType get() = WellKnownMimeType.MessageRSocketAcceptMimeTypes - override fun ByteReadPacket.read(pool: ObjectPool): PerStreamAcceptableDataMimeTypesMetadata { + override fun ByteReadPacket.read(pool: BufferPool): PerStreamAcceptableDataMimeTypesMetadata { val list = mutableListOf() while (isNotEmpty) list.add(readMimeType()) return PerStreamAcceptableDataMimeTypesMetadata(list.toList()) diff --git a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/metadata/PerStreamDataMimeTypeMetadata.kt b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/metadata/PerStreamDataMimeTypeMetadata.kt index 90efad3e..b28c5efc 100644 --- a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/metadata/PerStreamDataMimeTypeMetadata.kt +++ b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/metadata/PerStreamDataMimeTypeMetadata.kt @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,11 +17,10 @@ package io.rsocket.kotlin.metadata import io.ktor.utils.io.core.* -import io.ktor.utils.io.core.internal.* -import io.ktor.utils.io.pool.* import io.rsocket.kotlin.* import io.rsocket.kotlin.core.* import io.rsocket.kotlin.frame.io.* +import io.rsocket.kotlin.internal.io.* @ExperimentalMetadataApi public class PerStreamDataMimeTypeMetadata(public val type: MimeType) : Metadata { @@ -35,7 +34,7 @@ public class PerStreamDataMimeTypeMetadata(public val type: MimeType) : Metadata public companion object Reader : MetadataReader { override val mimeType: MimeType get() = WellKnownMimeType.MessageRSocketMimeType - override fun ByteReadPacket.read(pool: ObjectPool): PerStreamDataMimeTypeMetadata = + override fun ByteReadPacket.read(pool: BufferPool): PerStreamDataMimeTypeMetadata = PerStreamDataMimeTypeMetadata(readMimeType()) } } diff --git a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/metadata/RawMetadata.kt b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/metadata/RawMetadata.kt index c24727f9..366d8008 100644 --- a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/metadata/RawMetadata.kt +++ b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/metadata/RawMetadata.kt @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,11 +17,10 @@ package io.rsocket.kotlin.metadata import io.ktor.utils.io.core.* -import io.ktor.utils.io.core.internal.* -import io.ktor.utils.io.pool.* import io.rsocket.kotlin.* import io.rsocket.kotlin.core.* import io.rsocket.kotlin.frame.io.* +import io.rsocket.kotlin.internal.io.* @ExperimentalMetadataApi public class RawMetadata( @@ -37,7 +36,7 @@ public class RawMetadata( } private class Reader(override val mimeType: MimeType) : MetadataReader { - override fun ByteReadPacket.read(pool: ObjectPool): RawMetadata = + override fun ByteReadPacket.read(pool: BufferPool): RawMetadata = RawMetadata(mimeType, readPacket(pool)) } diff --git a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/metadata/RoutingMetadata.kt b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/metadata/RoutingMetadata.kt index 2a726b28..da1913d0 100644 --- a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/metadata/RoutingMetadata.kt +++ b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/metadata/RoutingMetadata.kt @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,10 +17,9 @@ package io.rsocket.kotlin.metadata import io.ktor.utils.io.core.* -import io.ktor.utils.io.core.internal.* -import io.ktor.utils.io.pool.* import io.rsocket.kotlin.* import io.rsocket.kotlin.core.* +import io.rsocket.kotlin.internal.io.* @ExperimentalMetadataApi public fun RoutingMetadata(vararg tags: String): RoutingMetadata = RoutingMetadata(tags.toList()) @@ -47,7 +46,7 @@ public class RoutingMetadata(public val tags: List) : Metadata { public companion object Reader : MetadataReader { override val mimeType: MimeType get() = WellKnownMimeType.MessageRSocketRouting - override fun ByteReadPacket.read(pool: ObjectPool): RoutingMetadata { + override fun ByteReadPacket.read(pool: BufferPool): RoutingMetadata { val list = mutableListOf() while (isNotEmpty) { val length = readByte().toInt() and 0xFF diff --git a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/metadata/ZipkinTracingMetadata.kt b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/metadata/ZipkinTracingMetadata.kt index 059fade2..7787f9c2 100644 --- a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/metadata/ZipkinTracingMetadata.kt +++ b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/metadata/ZipkinTracingMetadata.kt @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,11 +17,10 @@ package io.rsocket.kotlin.metadata import io.ktor.utils.io.core.* -import io.ktor.utils.io.core.internal.* -import io.ktor.utils.io.pool.* import io.rsocket.kotlin.* import io.rsocket.kotlin.core.* import io.rsocket.kotlin.frame.io.* +import io.rsocket.kotlin.internal.io.* import kotlin.experimental.* @ExperimentalMetadataApi @@ -71,7 +70,7 @@ public class ZipkinTracingMetadata internal constructor( public companion object Reader : MetadataReader { override val mimeType: MimeType get() = WellKnownMimeType.MessageRSocketTracingZipkin - override fun ByteReadPacket.read(pool: ObjectPool): ZipkinTracingMetadata { + override fun ByteReadPacket.read(pool: BufferPool): ZipkinTracingMetadata { val flags = readByte() val kind = when { diff --git a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/metadata/security/AuthMetadata.kt b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/metadata/security/AuthMetadata.kt index 9ddf5566..a02c7cf5 100644 --- a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/metadata/security/AuthMetadata.kt +++ b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/metadata/security/AuthMetadata.kt @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,11 +17,10 @@ package io.rsocket.kotlin.metadata.security import io.ktor.utils.io.core.* -import io.ktor.utils.io.core.internal.* -import io.ktor.utils.io.pool.* import io.rsocket.kotlin.* import io.rsocket.kotlin.core.* import io.rsocket.kotlin.frame.io.* +import io.rsocket.kotlin.internal.io.* import io.rsocket.kotlin.metadata.* @ExperimentalMetadataApi @@ -39,10 +38,10 @@ public sealed interface AuthMetadata : Metadata { @ExperimentalMetadataApi public sealed interface AuthMetadataReader : MetadataReader { - public fun ByteReadPacket.readContent(type: AuthType, pool: ObjectPool): AM + public fun ByteReadPacket.readContent(type: AuthType, pool: BufferPool): AM override val mimeType: MimeType get() = WellKnownMimeType.MessageRSocketAuthentication - override fun ByteReadPacket.read(pool: ObjectPool): AM { + override fun ByteReadPacket.read(pool: BufferPool): AM { val type = readAuthType() return readContent(type, pool) } diff --git a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/metadata/security/BearerAuthMetadata.kt b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/metadata/security/BearerAuthMetadata.kt index 99af4fd0..bd59a815 100644 --- a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/metadata/security/BearerAuthMetadata.kt +++ b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/metadata/security/BearerAuthMetadata.kt @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,9 +17,8 @@ package io.rsocket.kotlin.metadata.security import io.ktor.utils.io.core.* -import io.ktor.utils.io.core.internal.* -import io.ktor.utils.io.pool.* import io.rsocket.kotlin.* +import io.rsocket.kotlin.internal.io.* @ExperimentalMetadataApi public class BearerAuthMetadata( @@ -33,7 +32,7 @@ public class BearerAuthMetadata( override fun close(): Unit = Unit public companion object Reader : AuthMetadataReader { - override fun ByteReadPacket.readContent(type: AuthType, pool: ObjectPool): BearerAuthMetadata { + override fun ByteReadPacket.readContent(type: AuthType, pool: BufferPool): BearerAuthMetadata { require(type == WellKnowAuthType.Bearer) { "Metadata auth type should be 'bearer'" } val token = readText() return BearerAuthMetadata(token) diff --git a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/metadata/security/RawAuthMetadata.kt b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/metadata/security/RawAuthMetadata.kt index b6cd43e1..2dfa8075 100644 --- a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/metadata/security/RawAuthMetadata.kt +++ b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/metadata/security/RawAuthMetadata.kt @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,10 +17,9 @@ package io.rsocket.kotlin.metadata.security import io.ktor.utils.io.core.* -import io.ktor.utils.io.core.internal.* -import io.ktor.utils.io.pool.* import io.rsocket.kotlin.* import io.rsocket.kotlin.frame.io.* +import io.rsocket.kotlin.internal.io.* @ExperimentalMetadataApi public class RawAuthMetadata( @@ -37,7 +36,7 @@ public class RawAuthMetadata( } public companion object Reader : AuthMetadataReader { - override fun ByteReadPacket.readContent(type: AuthType, pool: ObjectPool): RawAuthMetadata { + override fun ByteReadPacket.readContent(type: AuthType, pool: BufferPool): RawAuthMetadata { val content = readPacket(pool) return RawAuthMetadata(type, content) } @@ -50,7 +49,7 @@ public fun RawAuthMetadata.hasAuthTypeOf(reader: AuthMetadataReader<*>): Boolean @ExperimentalMetadataApi public fun RawAuthMetadata.read( reader: AuthMetadataReader, - pool: ObjectPool = ChunkBuffer.Pool + pool: BufferPool = BufferPool.Default, ): AM { return readOrNull(reader, pool) ?: run { content.close() @@ -62,7 +61,7 @@ public fun RawAuthMetadata.read( public fun RawAuthMetadata.readOrNull( reader: AuthMetadataReader, - pool: ObjectPool = ChunkBuffer.Pool + pool: BufferPool = BufferPool.Default, ): AM? { if (type != reader.mimeType) return null diff --git a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/metadata/security/SimpleAuthMetadata.kt b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/metadata/security/SimpleAuthMetadata.kt index 2e622fe6..8a3be020 100644 --- a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/metadata/security/SimpleAuthMetadata.kt +++ b/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/metadata/security/SimpleAuthMetadata.kt @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,9 +17,8 @@ package io.rsocket.kotlin.metadata.security import io.ktor.utils.io.core.* -import io.ktor.utils.io.core.internal.* -import io.ktor.utils.io.pool.* import io.rsocket.kotlin.* +import io.rsocket.kotlin.internal.io.* @ExperimentalMetadataApi public class SimpleAuthMetadata( @@ -43,7 +42,7 @@ public class SimpleAuthMetadata( override fun close(): Unit = Unit public companion object Reader : AuthMetadataReader { - override fun ByteReadPacket.readContent(type: AuthType, pool: ObjectPool): SimpleAuthMetadata { + override fun ByteReadPacket.readContent(type: AuthType, pool: BufferPool): SimpleAuthMetadata { require(type == WellKnowAuthType.Simple) { "Metadata auth type should be 'simple'" } val length = readShort().toInt() val username = readTextExactBytes(length) diff --git a/rsocket-core/src/commonTest/kotlin/io/rsocket/kotlin/TestConnection.kt b/rsocket-core/src/commonTest/kotlin/io/rsocket/kotlin/TestConnection.kt index 31ebe822..74f89c76 100644 --- a/rsocket-core/src/commonTest/kotlin/io/rsocket/kotlin/TestConnection.kt +++ b/rsocket-core/src/commonTest/kotlin/io/rsocket/kotlin/TestConnection.kt @@ -1,5 +1,5 @@ /* - * Copyright 2015-2023 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,8 +18,6 @@ package io.rsocket.kotlin import app.cash.turbine.* import io.ktor.utils.io.core.* -import io.ktor.utils.io.core.internal.* -import io.ktor.utils.io.pool.* import io.rsocket.kotlin.frame.* import io.rsocket.kotlin.internal.io.* import io.rsocket.kotlin.test.* @@ -33,7 +31,6 @@ import kotlin.time.* import kotlin.time.Duration.Companion.seconds class TestConnection : Connection, ClientTransport { - override val pool: ObjectPool = InUseTrackingPool override val coroutineContext: CoroutineContext = Job() + Dispatchers.Unconfined + TestExceptionHandler diff --git a/rsocket-core/src/commonTest/kotlin/io/rsocket/kotlin/core/RSocketTest.kt b/rsocket-core/src/commonTest/kotlin/io/rsocket/kotlin/core/RSocketTest.kt index 92229147..a8fb0fac 100644 --- a/rsocket-core/src/commonTest/kotlin/io/rsocket/kotlin/core/RSocketTest.kt +++ b/rsocket-core/src/commonTest/kotlin/io/rsocket/kotlin/core/RSocketTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -41,7 +41,7 @@ class RSocketTest : SuspendTest, TestWithLeakCheck { private suspend fun start(handler: RSocket? = null): RSocket { val localServer = TestServer().bindIn( CoroutineScope(Dispatchers.Unconfined + testJob + TestExceptionHandler), - LocalServerTransport(InUseTrackingPool) + LocalServerTransport() ) { handler ?: RSocketRequestHandler { requestResponse { it } diff --git a/rsocket-core/src/commonTest/kotlin/io/rsocket/kotlin/frame/Util.kt b/rsocket-core/src/commonTest/kotlin/io/rsocket/kotlin/frame/Util.kt index 9c14011b..a2b61f06 100644 --- a/rsocket-core/src/commonTest/kotlin/io/rsocket/kotlin/frame/Util.kt +++ b/rsocket-core/src/commonTest/kotlin/io/rsocket/kotlin/frame/Util.kt @@ -1,5 +1,5 @@ /* - * Copyright 2015-2023 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,12 +17,11 @@ package io.rsocket.kotlin.frame import io.ktor.utils.io.core.* -import io.rsocket.kotlin.frame.io.* import io.rsocket.kotlin.internal.io.* import io.rsocket.kotlin.test.* import kotlin.test.* -internal fun Frame.toPacketWithLength(): ByteReadPacket = buildPacket(InUseTrackingPool) { +internal fun Frame.toPacketWithLength(): ByteReadPacket = InUseTrackingPool.buildPacket { val packet = toPacket(InUseTrackingPool) writeInt24(packet.remaining.toInt()) writePacket(packet) diff --git a/rsocket-core/src/commonTest/kotlin/io/rsocket/kotlin/internal/handler/RequesterRequestResponseFrameHandlerTest.kt b/rsocket-core/src/commonTest/kotlin/io/rsocket/kotlin/internal/handler/RequesterRequestResponseFrameHandlerTest.kt index 70cdda9b..00557af6 100644 --- a/rsocket-core/src/commonTest/kotlin/io/rsocket/kotlin/internal/handler/RequesterRequestResponseFrameHandlerTest.kt +++ b/rsocket-core/src/commonTest/kotlin/io/rsocket/kotlin/internal/handler/RequesterRequestResponseFrameHandlerTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,10 +25,10 @@ import kotlinx.coroutines.* import kotlin.test.* class RequesterRequestResponseFrameHandlerTest : SuspendTest, TestWithLeakCheck { - private val storage = StreamsStorage(true, InUseTrackingPool) + private val storage = StreamsStorage(true) private val deferred = CompletableDeferred() private val handler = - RequesterRequestResponseFrameHandler(1, storage, deferred, InUseTrackingPool).also { storage.save(1, it) } + RequesterRequestResponseFrameHandler(1, storage, deferred).also { storage.save(1, it) } @Test fun testCompleteOnPayloadReceive() = test { diff --git a/rsocket-internal-io/api/rsocket-internal-io.api b/rsocket-internal-io/api/rsocket-internal-io.api index b51a5afd..2245d547 100644 --- a/rsocket-internal-io/api/rsocket-internal-io.api +++ b/rsocket-internal-io/api/rsocket-internal-io.api @@ -1,3 +1,22 @@ +public final class io/rsocket/kotlin/internal/io/BufferPool { + public static final field Companion Lio/rsocket/kotlin/internal/io/BufferPool$Companion; + public static final synthetic fun box-impl (Lio/ktor/utils/io/pool/ObjectPool;)Lio/rsocket/kotlin/internal/io/BufferPool; + public static final fun buildPacket-impl (Lio/ktor/utils/io/pool/ObjectPool;Lkotlin/jvm/functions/Function1;)Lio/ktor/utils/io/core/ByteReadPacket; + public static fun constructor-impl (Lio/ktor/utils/io/pool/ObjectPool;)Lio/ktor/utils/io/pool/ObjectPool; + public fun equals (Ljava/lang/Object;)Z + public static fun equals-impl (Lio/ktor/utils/io/pool/ObjectPool;Ljava/lang/Object;)Z + public static final fun equals-impl0 (Lio/ktor/utils/io/pool/ObjectPool;Lio/ktor/utils/io/pool/ObjectPool;)Z + public fun hashCode ()I + public static fun hashCode-impl (Lio/ktor/utils/io/pool/ObjectPool;)I + public fun toString ()Ljava/lang/String; + public static fun toString-impl (Lio/ktor/utils/io/pool/ObjectPool;)Ljava/lang/String; + public final synthetic fun unbox-impl ()Lio/ktor/utils/io/pool/ObjectPool; +} + +public final class io/rsocket/kotlin/internal/io/BufferPool$Companion { + public final fun getDefault-ulmh1bs ()Lio/ktor/utils/io/pool/ObjectPool; +} + public final class io/rsocket/kotlin/internal/io/ChannelsKt { public static final fun cancelWithCause (Lkotlinx/coroutines/channels/Channel;Ljava/lang/Throwable;)V public static final fun channelForCloseable (I)Lkotlinx/coroutines/channels/Channel; diff --git a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/frame/io/packet.kt b/rsocket-internal-io/src/commonMain/kotlin/io/rsocket/kotlin/internal/io/BufferPool.kt similarity index 51% rename from rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/frame/io/packet.kt rename to rsocket-internal-io/src/commonMain/kotlin/io/rsocket/kotlin/internal/io/BufferPool.kt index 517b2fdc..1b157aff 100644 --- a/rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/frame/io/packet.kt +++ b/rsocket-internal-io/src/commonMain/kotlin/io/rsocket/kotlin/internal/io/BufferPool.kt @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,19 +14,30 @@ * limitations under the License. */ -package io.rsocket.kotlin.frame.io +package io.rsocket.kotlin.internal.io import io.ktor.utils.io.core.* import io.ktor.utils.io.core.internal.* import io.ktor.utils.io.pool.* +import kotlin.jvm.* -internal inline fun buildPacket(pool: ObjectPool, block: BytePacketBuilder.() -> Unit): ByteReadPacket { - val builder = BytePacketBuilder(pool) - try { - block(builder) - return builder.build() - } catch (t: Throwable) { - builder.close() - throw t +@JvmInline +public value class BufferPool( + @PublishedApi + internal val pool: ObjectPool, +) { + public inline fun buildPacket(block: BytePacketBuilder.() -> Unit): ByteReadPacket { + val builder = BytePacketBuilder(pool) + try { + block(builder) + return builder.build() + } catch (t: Throwable) { + builder.close() + throw t + } + } + + public companion object { + public val Default: BufferPool = BufferPool(ChunkBuffer.Pool) } } diff --git a/rsocket-ktor/rsocket-ktor-client/api/rsocket-ktor-client.api b/rsocket-ktor/rsocket-ktor-client/api/rsocket-ktor-client.api index ab614712..3209d534 100644 --- a/rsocket-ktor/rsocket-ktor-client/api/rsocket-ktor-client.api +++ b/rsocket-ktor/rsocket-ktor-client/api/rsocket-ktor-client.api @@ -8,14 +8,12 @@ public final class io/rsocket/kotlin/ktor/client/BuildersKt { public final class io/rsocket/kotlin/ktor/client/RSocketSupport { public static final field Plugin Lio/rsocket/kotlin/ktor/client/RSocketSupport$Plugin; - public synthetic fun (Lio/rsocket/kotlin/core/RSocketConnector;Lio/ktor/utils/io/pool/ObjectPool;Lkotlin/jvm/internal/DefaultConstructorMarker;)V + public synthetic fun (Lio/rsocket/kotlin/core/RSocketConnector;Lkotlin/jvm/internal/DefaultConstructorMarker;)V } public final class io/rsocket/kotlin/ktor/client/RSocketSupport$Config { public final fun connector (Lkotlin/jvm/functions/Function1;)V - public final fun getBufferPool ()Lio/ktor/utils/io/pool/ObjectPool; public final fun getConnector ()Lio/rsocket/kotlin/core/RSocketConnector; - public final fun setBufferPool (Lio/ktor/utils/io/pool/ObjectPool;)V public final fun setConnector (Lio/rsocket/kotlin/core/RSocketConnector;)V } diff --git a/rsocket-ktor/rsocket-ktor-client/src/commonMain/kotlin/io/rsocket/kotlin/ktor/client/Builders.kt b/rsocket-ktor/rsocket-ktor-client/src/commonMain/kotlin/io/rsocket/kotlin/ktor/client/Builders.kt index 95a6537e..49850ce2 100644 --- a/rsocket-ktor/rsocket-ktor-client/src/commonMain/kotlin/io/rsocket/kotlin/ktor/client/Builders.kt +++ b/rsocket-ktor/rsocket-ktor-client/src/commonMain/kotlin/io/rsocket/kotlin/ktor/client/Builders.kt @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,8 +21,6 @@ import io.ktor.client.plugins.* import io.ktor.client.plugins.websocket.* import io.ktor.client.request.* import io.ktor.http.* -import io.ktor.utils.io.core.internal.* -import io.ktor.utils.io.pool.* import io.rsocket.kotlin.* import io.rsocket.kotlin.transport.* import io.rsocket.kotlin.transport.ktor.websocket.* @@ -31,7 +29,7 @@ import kotlin.coroutines.* public suspend fun HttpClient.rSocket( request: HttpRequestBuilder.() -> Unit, ): RSocket = plugin(RSocketSupport).run { - connector.connect(KtorClientTransport(this@rSocket, request, bufferPool)) + connector.connect(KtorClientTransport(this@rSocket, request)) } public suspend fun HttpClient.rSocket( @@ -65,10 +63,9 @@ public suspend fun HttpClient.rSocket( private class KtorClientTransport( private val client: HttpClient, private val request: HttpRequestBuilder.() -> Unit, - private val pool: ObjectPool ) : ClientTransport { override val coroutineContext: CoroutineContext get() = client.coroutineContext @TransportApi - override suspend fun connect(): Connection = WebSocketConnection(client.webSocketSession(request), pool) + override suspend fun connect(): Connection = WebSocketConnection(client.webSocketSession(request)) } diff --git a/rsocket-ktor/rsocket-ktor-client/src/commonMain/kotlin/io/rsocket/kotlin/ktor/client/RSocketSupport.kt b/rsocket-ktor/rsocket-ktor-client/src/commonMain/kotlin/io/rsocket/kotlin/ktor/client/RSocketSupport.kt index 50026c3f..02d90584 100644 --- a/rsocket-ktor/rsocket-ktor-client/src/commonMain/kotlin/io/rsocket/kotlin/ktor/client/RSocketSupport.kt +++ b/rsocket-ktor/rsocket-ktor-client/src/commonMain/kotlin/io/rsocket/kotlin/ktor/client/RSocketSupport.kt @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,17 +20,13 @@ import io.ktor.client.* import io.ktor.client.plugins.* import io.ktor.client.plugins.websocket.* import io.ktor.util.* -import io.ktor.utils.io.core.internal.* -import io.ktor.utils.io.pool.* import io.rsocket.kotlin.core.* public class RSocketSupport private constructor( internal val connector: RSocketConnector, - internal val bufferPool: ObjectPool ) { public class Config internal constructor() { - public var bufferPool: ObjectPool = ChunkBuffer.Pool public var connector: RSocketConnector = RSocketConnector() public fun connector(block: RSocketConnectorBuilder.() -> Unit) { connector = RSocketConnector(block) @@ -41,7 +37,7 @@ public class RSocketSupport private constructor( override val key: AttributeKey = AttributeKey("RSocket") override fun prepare(block: Config.() -> Unit): RSocketSupport = Config().run { block() - RSocketSupport(connector, bufferPool) + RSocketSupport(connector) } override fun install(plugin: RSocketSupport, scope: HttpClient) { diff --git a/rsocket-ktor/rsocket-ktor-server/api/rsocket-ktor-server.api b/rsocket-ktor/rsocket-ktor-server/api/rsocket-ktor-server.api index 08f142c4..101de298 100644 --- a/rsocket-ktor/rsocket-ktor-server/api/rsocket-ktor-server.api +++ b/rsocket-ktor/rsocket-ktor-server/api/rsocket-ktor-server.api @@ -1,13 +1,11 @@ public final class io/rsocket/kotlin/ktor/server/RSocketSupport { public static final field Feature Lio/rsocket/kotlin/ktor/server/RSocketSupport$Feature; - public synthetic fun (Lio/rsocket/kotlin/core/RSocketServer;Lio/ktor/utils/io/pool/ObjectPool;Lkotlin/jvm/internal/DefaultConstructorMarker;)V + public synthetic fun (Lio/rsocket/kotlin/core/RSocketServer;Lkotlin/jvm/internal/DefaultConstructorMarker;)V } public final class io/rsocket/kotlin/ktor/server/RSocketSupport$Config { - public final fun getBufferPool ()Lio/ktor/utils/io/pool/ObjectPool; public final fun getServer ()Lio/rsocket/kotlin/core/RSocketServer; public final fun server (Lkotlin/jvm/functions/Function1;)V - public final fun setBufferPool (Lio/ktor/utils/io/pool/ObjectPool;)V public final fun setServer (Lio/rsocket/kotlin/core/RSocketServer;)V } diff --git a/rsocket-ktor/rsocket-ktor-server/src/commonMain/kotlin/io/rsocket/kotlin/ktor/server/RSocketSupport.kt b/rsocket-ktor/rsocket-ktor-server/src/commonMain/kotlin/io/rsocket/kotlin/ktor/server/RSocketSupport.kt index 9fef2728..d7373750 100644 --- a/rsocket-ktor/rsocket-ktor-server/src/commonMain/kotlin/io/rsocket/kotlin/ktor/server/RSocketSupport.kt +++ b/rsocket-ktor/rsocket-ktor-server/src/commonMain/kotlin/io/rsocket/kotlin/ktor/server/RSocketSupport.kt @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,16 +19,12 @@ package io.rsocket.kotlin.ktor.server import io.ktor.server.application.* import io.ktor.server.websocket.* import io.ktor.util.* -import io.ktor.utils.io.core.internal.* -import io.ktor.utils.io.pool.* import io.rsocket.kotlin.core.* public class RSocketSupport private constructor( internal val server: RSocketServer, - internal val bufferPool: ObjectPool ) { public class Config internal constructor() { - public var bufferPool: ObjectPool = ChunkBuffer.Pool public var server: RSocketServer = RSocketServer() public fun server(block: RSocketServerBuilder.() -> Unit) { server = RSocketServer(block) @@ -43,7 +39,7 @@ public class RSocketSupport private constructor( return Config().run { configure() - RSocketSupport(server, bufferPool) + RSocketSupport(server) } } } diff --git a/rsocket-ktor/rsocket-ktor-server/src/commonMain/kotlin/io/rsocket/kotlin/ktor/server/Routing.kt b/rsocket-ktor/rsocket-ktor-server/src/commonMain/kotlin/io/rsocket/kotlin/ktor/server/Routing.kt index 1a1b7af9..20fcb27a 100644 --- a/rsocket-ktor/rsocket-ktor-server/src/commonMain/kotlin/io/rsocket/kotlin/ktor/server/Routing.kt +++ b/rsocket-ktor/rsocket-ktor-server/src/commonMain/kotlin/io/rsocket/kotlin/ktor/server/Routing.kt @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,8 +19,6 @@ package io.rsocket.kotlin.ktor.server import io.ktor.server.application.* import io.ktor.server.routing.* import io.ktor.server.websocket.* -import io.ktor.utils.io.core.internal.* -import io.ktor.utils.io.pool.* import io.rsocket.kotlin.* import io.rsocket.kotlin.transport.* import io.rsocket.kotlin.transport.ktor.websocket.* @@ -31,19 +29,18 @@ public fun Route.rSocket( protocol: String? = null, acceptor: ConnectionAcceptor, ): Unit = application.plugin(RSocketSupport).run { - server.bindIn(application, KtorServerTransport(this@rSocket, path, protocol, bufferPool), acceptor) + server.bindIn(application, KtorServerTransport(this@rSocket, path, protocol), acceptor) } private class KtorServerTransport( private val route: Route, private val path: String?, private val protocol: String?, - private val pool: ObjectPool ) : ServerTransport { @TransportApi override fun CoroutineScope.start(accept: suspend CoroutineScope.(Connection) -> Unit) { val handler: suspend DefaultWebSocketServerSession.() -> Unit = { - val connection = WebSocketConnection(this, pool) + val connection = WebSocketConnection(this) accept(connection) } when (path) { diff --git a/rsocket-test/build.gradle.kts b/rsocket-test/build.gradle.kts index 692bef2d..82ad0ee3 100644 --- a/rsocket-test/build.gradle.kts +++ b/rsocket-test/build.gradle.kts @@ -1,5 +1,5 @@ /* - * Copyright 2015-2023 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,6 +26,7 @@ kotlin { dependencies { api(kotlin("test")) api(projects.rsocketCore) + implementation(projects.rsocketInternalIo) api(libs.ktor.utils) api(libs.turbine) diff --git a/rsocket-test/src/commonMain/kotlin/io/rsocket/kotlin/test/InUseTrackingPool.kt b/rsocket-test/src/commonMain/kotlin/io/rsocket/kotlin/test/InUseTrackingPool.kt index 493fd51e..ac5b3c1c 100644 --- a/rsocket-test/src/commonMain/kotlin/io/rsocket/kotlin/test/InUseTrackingPool.kt +++ b/rsocket-test/src/commonMain/kotlin/io/rsocket/kotlin/test/InUseTrackingPool.kt @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,10 +20,13 @@ import io.ktor.utils.io.bits.* import io.ktor.utils.io.core.* import io.ktor.utils.io.core.internal.* import io.ktor.utils.io.pool.* +import io.rsocket.kotlin.internal.io.* import kotlinx.atomicfu.locks.* import kotlin.test.* -object InUseTrackingPool : ObjectPool, SynchronizedObject() { +val InUseTrackingPool: BufferPool = BufferPool(InUseTrackingPoolInstance) + +private object InUseTrackingPoolInstance : ObjectPool, SynchronizedObject() { override val capacity: Int get() = BufferPool.capacity private val inUse = mutableSetOf() @@ -92,7 +95,7 @@ object InUseTrackingPool : ObjectPool, SynchronizedObject() { @Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") private object BufferPool : DefaultPool(1000) { override fun produceInstance(): ChunkBuffer { - return ChunkBuffer(DefaultAllocator.alloc(DEFAULT_BUFFER_SIZE), null, InUseTrackingPool) + return ChunkBuffer(DefaultAllocator.alloc(DEFAULT_BUFFER_SIZE), null, InUseTrackingPoolInstance) } override fun disposeInstance(instance: ChunkBuffer) { @@ -123,7 +126,7 @@ object InUseTrackingPool : ObjectPool, SynchronizedObject() { private class IdentityWrapper( private val instance: ChunkBuffer, - val throwable: Throwable? + val throwable: Throwable?, ) { override fun equals(other: Any?): Boolean { if (other !is IdentityWrapper) return false @@ -140,11 +143,11 @@ interface TestWithLeakCheck { @BeforeTest fun resetInUse() { - InUseTrackingPool.resetInUse() + InUseTrackingPoolInstance.resetInUse() } @AfterTest fun checkNoBuffersInUse() { - InUseTrackingPool.assertNoInUse() + InUseTrackingPoolInstance.assertNoInUse() } } diff --git a/rsocket-test/src/commonMain/kotlin/io/rsocket/kotlin/test/Packets.kt b/rsocket-test/src/commonMain/kotlin/io/rsocket/kotlin/test/Packets.kt index 7b193773..3f3d4651 100644 --- a/rsocket-test/src/commonMain/kotlin/io/rsocket/kotlin/test/Packets.kt +++ b/rsocket-test/src/commonMain/kotlin/io/rsocket/kotlin/test/Packets.kt @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,16 +18,14 @@ package io.rsocket.kotlin.test import io.ktor.util.* import io.ktor.utils.io.core.* -import io.ktor.utils.io.core.internal.* -import io.ktor.utils.io.pool.* import io.rsocket.kotlin.payload.* import kotlin.test.* -fun packet(block: BytePacketBuilder.() -> Unit): ByteReadPacket = buildPacket(InUseTrackingPool, block) +fun packet(block: BytePacketBuilder.() -> Unit): ByteReadPacket = InUseTrackingPool.buildPacket(block) -fun packet(text: String): ByteReadPacket = buildPacket(InUseTrackingPool) { writeText(text) } +fun packet(text: String): ByteReadPacket = InUseTrackingPool.buildPacket { writeText(text) } -fun packet(array: ByteArray): ByteReadPacket = buildPacket(InUseTrackingPool) { writeFully(array) } +fun packet(array: ByteArray): ByteReadPacket = InUseTrackingPool.buildPacket { writeFully(array) } fun payload(data: ByteArray, metadata: ByteArray? = null): Payload = Payload(packet(data), metadata?.let(::packet)) @@ -36,14 +34,3 @@ fun payload(data: String, metadata: String? = null): Payload = Payload(packet(da fun assertBytesEquals(expected: ByteArray?, actual: ByteArray?) { assertEquals(expected?.let(::hex), actual?.let(::hex)) } - -private inline fun buildPacket(pool: ObjectPool, block: BytePacketBuilder.() -> Unit): ByteReadPacket { - val builder = BytePacketBuilder(pool) - try { - block(builder) - return builder.build() - } catch (t: Throwable) { - builder.close() - throw t - } -} diff --git a/rsocket-test/src/commonMain/kotlin/io/rsocket/kotlin/test/TestConfig.kt b/rsocket-test/src/commonMain/kotlin/io/rsocket/kotlin/test/TestConfig.kt index 97c538d6..642a83dc 100644 --- a/rsocket-test/src/commonMain/kotlin/io/rsocket/kotlin/test/TestConfig.kt +++ b/rsocket-test/src/commonMain/kotlin/io/rsocket/kotlin/test/TestConfig.kt @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,6 +25,8 @@ fun TestServer( logging: Boolean = true, block: RSocketServerBuilder.() -> Unit = {} ): RSocketServer = RSocketServer { + @Suppress("DEPRECATION_ERROR") + bufferPool = InUseTrackingPool loggerFactory = if (logging) { LoggerFactory { PrintLogger.withLevel(LoggingLevel.DEBUG).logger("SERVER |$it") } } else { @@ -37,6 +39,8 @@ fun TestConnector( logging: Boolean = true, block: RSocketConnectorBuilder.() -> Unit = {} ): RSocketConnector = RSocketConnector { + @Suppress("DEPRECATION_ERROR") + bufferPool = InUseTrackingPool loggerFactory = if (logging) { LoggerFactory { PrintLogger.withLevel(LoggingLevel.DEBUG).logger("CLIENT |$it") } } else { diff --git a/rsocket-transport-ktor/rsocket-transport-ktor-tcp/api/rsocket-transport-ktor-tcp.api b/rsocket-transport-ktor/rsocket-transport-ktor-tcp/api/rsocket-transport-ktor-tcp.api index 85916b79..5833bcf1 100644 --- a/rsocket-transport-ktor/rsocket-transport-ktor-tcp/api/rsocket-transport-ktor-tcp.api +++ b/rsocket-transport-ktor/rsocket-transport-ktor-tcp/api/rsocket-transport-ktor-tcp.api @@ -1,8 +1,8 @@ public final class io/rsocket/kotlin/transport/ktor/tcp/TcpClientTransportKt { - public static final fun TcpClientTransport (Lio/ktor/network/sockets/InetSocketAddress;Lkotlin/coroutines/CoroutineContext;Lio/ktor/utils/io/pool/ObjectPool;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Lio/rsocket/kotlin/transport/ClientTransport; - public static final fun TcpClientTransport (Ljava/lang/String;ILkotlin/coroutines/CoroutineContext;Lio/ktor/utils/io/pool/ObjectPool;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Lio/rsocket/kotlin/transport/ClientTransport; - public static synthetic fun TcpClientTransport$default (Lio/ktor/network/sockets/InetSocketAddress;Lkotlin/coroutines/CoroutineContext;Lio/ktor/utils/io/pool/ObjectPool;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lio/rsocket/kotlin/transport/ClientTransport; - public static synthetic fun TcpClientTransport$default (Ljava/lang/String;ILkotlin/coroutines/CoroutineContext;Lio/ktor/utils/io/pool/ObjectPool;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lio/rsocket/kotlin/transport/ClientTransport; + public static final fun TcpClientTransport (Lio/ktor/network/sockets/InetSocketAddress;Lkotlin/coroutines/CoroutineContext;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Lio/rsocket/kotlin/transport/ClientTransport; + public static final fun TcpClientTransport (Ljava/lang/String;ILkotlin/coroutines/CoroutineContext;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Lio/rsocket/kotlin/transport/ClientTransport; + public static synthetic fun TcpClientTransport$default (Lio/ktor/network/sockets/InetSocketAddress;Lkotlin/coroutines/CoroutineContext;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lio/rsocket/kotlin/transport/ClientTransport; + public static synthetic fun TcpClientTransport$default (Ljava/lang/String;ILkotlin/coroutines/CoroutineContext;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lio/rsocket/kotlin/transport/ClientTransport; } public final class io/rsocket/kotlin/transport/ktor/tcp/TcpServer { @@ -11,9 +11,9 @@ public final class io/rsocket/kotlin/transport/ktor/tcp/TcpServer { } public final class io/rsocket/kotlin/transport/ktor/tcp/TcpServerTransportKt { - public static final fun TcpServerTransport (Lio/ktor/network/sockets/InetSocketAddress;Lio/ktor/utils/io/pool/ObjectPool;Lkotlin/jvm/functions/Function1;)Lio/rsocket/kotlin/transport/ServerTransport; - public static final fun TcpServerTransport (Ljava/lang/String;ILio/ktor/utils/io/pool/ObjectPool;Lkotlin/jvm/functions/Function1;)Lio/rsocket/kotlin/transport/ServerTransport; - public static synthetic fun TcpServerTransport$default (Lio/ktor/network/sockets/InetSocketAddress;Lio/ktor/utils/io/pool/ObjectPool;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lio/rsocket/kotlin/transport/ServerTransport; - public static synthetic fun TcpServerTransport$default (Ljava/lang/String;ILio/ktor/utils/io/pool/ObjectPool;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lio/rsocket/kotlin/transport/ServerTransport; + public static final fun TcpServerTransport (Lio/ktor/network/sockets/InetSocketAddress;Lkotlin/jvm/functions/Function1;)Lio/rsocket/kotlin/transport/ServerTransport; + public static final fun TcpServerTransport (Ljava/lang/String;ILkotlin/jvm/functions/Function1;)Lio/rsocket/kotlin/transport/ServerTransport; + public static synthetic fun TcpServerTransport$default (Lio/ktor/network/sockets/InetSocketAddress;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lio/rsocket/kotlin/transport/ServerTransport; + public static synthetic fun TcpServerTransport$default (Ljava/lang/String;ILkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lio/rsocket/kotlin/transport/ServerTransport; } diff --git a/rsocket-transport-ktor/rsocket-transport-ktor-tcp/src/commonMain/kotlin/io/rsocket/kotlin/transport/ktor/tcp/TcpClientTransport.kt b/rsocket-transport-ktor/rsocket-transport-ktor-tcp/src/commonMain/kotlin/io/rsocket/kotlin/transport/ktor/tcp/TcpClientTransport.kt index 0281987a..cd3a208a 100644 --- a/rsocket-transport-ktor/rsocket-transport-ktor-tcp/src/commonMain/kotlin/io/rsocket/kotlin/transport/ktor/tcp/TcpClientTransport.kt +++ b/rsocket-transport-ktor/rsocket-transport-ktor-tcp/src/commonMain/kotlin/io/rsocket/kotlin/transport/ktor/tcp/TcpClientTransport.kt @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,8 +21,6 @@ package io.rsocket.kotlin.transport.ktor.tcp import io.ktor.network.selector.* import io.ktor.network.sockets.* -import io.ktor.utils.io.core.internal.* -import io.ktor.utils.io.pool.* import io.rsocket.kotlin.* import io.rsocket.kotlin.transport.* import kotlinx.coroutines.* @@ -36,15 +34,13 @@ internal expect val defaultDispatcher: CoroutineDispatcher public fun TcpClientTransport( hostname: String, port: Int, context: CoroutineContext = EmptyCoroutineContext, - pool: ObjectPool = ChunkBuffer.Pool, intercept: (Socket) -> Socket = { it }, //f.e. for tls, which is currently supported by ktor only on JVM - configure: SocketOptions.TCPClientSocketOptions.() -> Unit = {} -): ClientTransport = TcpClientTransport(InetSocketAddress(hostname, port), context, pool, intercept, configure) + configure: SocketOptions.TCPClientSocketOptions.() -> Unit = {}, +): ClientTransport = TcpClientTransport(InetSocketAddress(hostname, port), context, intercept, configure) public fun TcpClientTransport( remoteAddress: InetSocketAddress, context: CoroutineContext = EmptyCoroutineContext, - pool: ObjectPool = ChunkBuffer.Pool, intercept: (Socket) -> Socket = { it }, //f.e. for tls, which is currently supported by ktor only on JVM configure: SocketOptions.TCPClientSocketOptions.() -> Unit = {} ): ClientTransport { @@ -54,6 +50,6 @@ public fun TcpClientTransport( Job(transportJob).invokeOnCompletion { selector.close() } return ClientTransport(transportContext) { val socket = aSocket(selector).tcp().connect(remoteAddress, configure) - TcpConnection(intercept(socket), transportContext + Job(transportJob), pool) + TcpConnection(intercept(socket), transportContext + Job(transportJob)) } } diff --git a/rsocket-transport-ktor/rsocket-transport-ktor-tcp/src/commonMain/kotlin/io/rsocket/kotlin/transport/ktor/tcp/TcpConnection.kt b/rsocket-transport-ktor/rsocket-transport-ktor-tcp/src/commonMain/kotlin/io/rsocket/kotlin/transport/ktor/tcp/TcpConnection.kt index 1fb18421..abd29390 100644 --- a/rsocket-transport-ktor/rsocket-transport-ktor-tcp/src/commonMain/kotlin/io/rsocket/kotlin/transport/ktor/tcp/TcpConnection.kt +++ b/rsocket-transport-ktor/rsocket-transport-ktor-tcp/src/commonMain/kotlin/io/rsocket/kotlin/transport/ktor/tcp/TcpConnection.kt @@ -1,5 +1,5 @@ /* - * Copyright 2015-2023 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,8 +20,6 @@ import io.ktor.network.sockets.* import io.ktor.util.cio.* import io.ktor.utils.io.* import io.ktor.utils.io.core.* -import io.ktor.utils.io.core.internal.* -import io.ktor.utils.io.pool.* import io.rsocket.kotlin.* import io.rsocket.kotlin.Connection import io.rsocket.kotlin.internal.io.* @@ -32,7 +30,6 @@ import kotlin.coroutines.* internal class TcpConnection( socket: Socket, override val coroutineContext: CoroutineContext, - override val pool: ObjectPool ) : Connection { private val socketConnection = socket.connection() diff --git a/rsocket-transport-ktor/rsocket-transport-ktor-tcp/src/commonMain/kotlin/io/rsocket/kotlin/transport/ktor/tcp/TcpServerTransport.kt b/rsocket-transport-ktor/rsocket-transport-ktor-tcp/src/commonMain/kotlin/io/rsocket/kotlin/transport/ktor/tcp/TcpServerTransport.kt index 8df7f5d3..7282068f 100644 --- a/rsocket-transport-ktor/rsocket-transport-ktor-tcp/src/commonMain/kotlin/io/rsocket/kotlin/transport/ktor/tcp/TcpServerTransport.kt +++ b/rsocket-transport-ktor/rsocket-transport-ktor-tcp/src/commonMain/kotlin/io/rsocket/kotlin/transport/ktor/tcp/TcpServerTransport.kt @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,8 +22,6 @@ package io.rsocket.kotlin.transport.ktor.tcp import io.ktor.network.selector.* import io.ktor.network.sockets.* import io.ktor.utils.io.core.* -import io.ktor.utils.io.core.internal.* -import io.ktor.utils.io.pool.* import io.rsocket.kotlin.* import io.rsocket.kotlin.transport.* import kotlinx.coroutines.* @@ -35,13 +33,11 @@ public class TcpServer internal constructor( public fun TcpServerTransport( hostname: String = "0.0.0.0", port: Int = 0, - pool: ObjectPool = ChunkBuffer.Pool, configure: SocketOptions.AcceptorOptions.() -> Unit = {}, -): ServerTransport = TcpServerTransport(InetSocketAddress(hostname, port), pool, configure) +): ServerTransport = TcpServerTransport(InetSocketAddress(hostname, port), configure) public fun TcpServerTransport( localAddress: InetSocketAddress? = null, - pool: ObjectPool = ChunkBuffer.Pool, configure: SocketOptions.AcceptorOptions.() -> Unit = {}, ): ServerTransport = ServerTransport { accept -> val serverSocketDeferred = CompletableDeferred() @@ -54,7 +50,7 @@ public fun TcpServerTransport( while (isActive) { val clientSocket = serverSocket.accept() connectionScope.launch { - accept(TcpConnection(clientSocket, coroutineContext, pool)) + accept(TcpConnection(clientSocket, coroutineContext)) }.invokeOnCompletion { clientSocket.close() } diff --git a/rsocket-transport-ktor/rsocket-transport-ktor-tcp/src/commonTest/kotlin/io/rsocket/kotlin/transport/ktor/tcp/TcpServerTest.kt b/rsocket-transport-ktor/rsocket-transport-ktor-tcp/src/commonTest/kotlin/io/rsocket/kotlin/transport/ktor/tcp/TcpServerTest.kt index 6df57063..f7065fbf 100644 --- a/rsocket-transport-ktor/rsocket-transport-ktor-tcp/src/commonTest/kotlin/io/rsocket/kotlin/transport/ktor/tcp/TcpServerTest.kt +++ b/rsocket-transport-ktor/rsocket-transport-ktor-tcp/src/commonTest/kotlin/io/rsocket/kotlin/transport/ktor/tcp/TcpServerTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,8 +27,8 @@ class TcpServerTest : SuspendTest, TestWithLeakCheck { private val testJob = Job() private val testContext = testJob + TestExceptionHandler private val address = InetSocketAddress("0.0.0.0", PortProvider.next()) - private val serverTransport = TcpServerTransport(address, InUseTrackingPool) - private val clientTransport = TcpClientTransport(address, testContext, InUseTrackingPool) + private val serverTransport = TcpServerTransport(address) + private val clientTransport = TcpClientTransport(address, testContext) override suspend fun after() { testJob.cancelAndJoin() diff --git a/rsocket-transport-ktor/rsocket-transport-ktor-tcp/src/commonTest/kotlin/io/rsocket/kotlin/transport/ktor/tcp/TcpTransportTest.kt b/rsocket-transport-ktor/rsocket-transport-ktor-tcp/src/commonTest/kotlin/io/rsocket/kotlin/transport/ktor/tcp/TcpTransportTest.kt index 070b8d68..d2410604 100644 --- a/rsocket-transport-ktor/rsocket-transport-ktor-tcp/src/commonTest/kotlin/io/rsocket/kotlin/transport/ktor/tcp/TcpTransportTest.kt +++ b/rsocket-transport-ktor/rsocket-transport-ktor-tcp/src/commonTest/kotlin/io/rsocket/kotlin/transport/ktor/tcp/TcpTransportTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,13 +17,12 @@ package io.rsocket.kotlin.transport.ktor.tcp import io.ktor.network.sockets.* -import io.rsocket.kotlin.test.* import io.rsocket.kotlin.transport.tests.* class TcpTransportTest : TransportTest() { override suspend fun before() { val address = InetSocketAddress("0.0.0.0", PortProvider.next()) - startServer(TcpServerTransport(address, InUseTrackingPool)).serverSocket.await() - client = connectClient(TcpClientTransport(address, testContext, InUseTrackingPool)) + startServer(TcpServerTransport(address)).serverSocket.await() + client = connectClient(TcpClientTransport(address, testContext)) } } diff --git a/rsocket-transport-ktor/rsocket-transport-ktor-websocket-client/api/rsocket-transport-ktor-websocket-client.api b/rsocket-transport-ktor/rsocket-transport-ktor-websocket-client/api/rsocket-transport-ktor-websocket-client.api index c278b288..9aaa4d11 100644 --- a/rsocket-transport-ktor/rsocket-transport-ktor-websocket-client/api/rsocket-transport-ktor-websocket-client.api +++ b/rsocket-transport-ktor/rsocket-transport-ktor-websocket-client/api/rsocket-transport-ktor-websocket-client.api @@ -1,9 +1,9 @@ public final class io/rsocket/kotlin/transport/ktor/websocket/client/WebSocketClientTransportKt { - public static final fun WebSocketClientTransport (Lio/ktor/client/engine/HttpClientEngineFactory;Ljava/lang/String;Ljava/lang/Integer;Ljava/lang/String;ZLkotlin/coroutines/CoroutineContext;Lio/ktor/utils/io/pool/ObjectPool;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Lio/rsocket/kotlin/transport/ClientTransport; - public static final fun WebSocketClientTransport (Lio/ktor/client/engine/HttpClientEngineFactory;Ljava/lang/String;ZLkotlin/coroutines/CoroutineContext;Lio/ktor/utils/io/pool/ObjectPool;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Lio/rsocket/kotlin/transport/ClientTransport; - public static final fun WebSocketClientTransport (Lio/ktor/client/engine/HttpClientEngineFactory;Lkotlin/coroutines/CoroutineContext;Lio/ktor/utils/io/pool/ObjectPool;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Lio/rsocket/kotlin/transport/ClientTransport; - public static synthetic fun WebSocketClientTransport$default (Lio/ktor/client/engine/HttpClientEngineFactory;Ljava/lang/String;Ljava/lang/Integer;Ljava/lang/String;ZLkotlin/coroutines/CoroutineContext;Lio/ktor/utils/io/pool/ObjectPool;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lio/rsocket/kotlin/transport/ClientTransport; - public static synthetic fun WebSocketClientTransport$default (Lio/ktor/client/engine/HttpClientEngineFactory;Ljava/lang/String;ZLkotlin/coroutines/CoroutineContext;Lio/ktor/utils/io/pool/ObjectPool;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lio/rsocket/kotlin/transport/ClientTransport; - public static synthetic fun WebSocketClientTransport$default (Lio/ktor/client/engine/HttpClientEngineFactory;Lkotlin/coroutines/CoroutineContext;Lio/ktor/utils/io/pool/ObjectPool;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lio/rsocket/kotlin/transport/ClientTransport; + public static final fun WebSocketClientTransport (Lio/ktor/client/engine/HttpClientEngineFactory;Ljava/lang/String;Ljava/lang/Integer;Ljava/lang/String;ZLkotlin/coroutines/CoroutineContext;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Lio/rsocket/kotlin/transport/ClientTransport; + public static final fun WebSocketClientTransport (Lio/ktor/client/engine/HttpClientEngineFactory;Ljava/lang/String;ZLkotlin/coroutines/CoroutineContext;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Lio/rsocket/kotlin/transport/ClientTransport; + public static final fun WebSocketClientTransport (Lio/ktor/client/engine/HttpClientEngineFactory;Lkotlin/coroutines/CoroutineContext;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Lio/rsocket/kotlin/transport/ClientTransport; + public static synthetic fun WebSocketClientTransport$default (Lio/ktor/client/engine/HttpClientEngineFactory;Ljava/lang/String;Ljava/lang/Integer;Ljava/lang/String;ZLkotlin/coroutines/CoroutineContext;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lio/rsocket/kotlin/transport/ClientTransport; + public static synthetic fun WebSocketClientTransport$default (Lio/ktor/client/engine/HttpClientEngineFactory;Ljava/lang/String;ZLkotlin/coroutines/CoroutineContext;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lio/rsocket/kotlin/transport/ClientTransport; + public static synthetic fun WebSocketClientTransport$default (Lio/ktor/client/engine/HttpClientEngineFactory;Lkotlin/coroutines/CoroutineContext;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lio/rsocket/kotlin/transport/ClientTransport; } diff --git a/rsocket-transport-ktor/rsocket-transport-ktor-websocket-client/src/commonMain/kotlin/io/rsocket/kotlin/transport/ktor/websocket/client/WebSocketClientTransport.kt b/rsocket-transport-ktor/rsocket-transport-ktor-websocket-client/src/commonMain/kotlin/io/rsocket/kotlin/transport/ktor/websocket/client/WebSocketClientTransport.kt index dc5149c5..0f33ee44 100644 --- a/rsocket-transport-ktor/rsocket-transport-ktor-websocket-client/src/commonMain/kotlin/io/rsocket/kotlin/transport/ktor/websocket/client/WebSocketClientTransport.kt +++ b/rsocket-transport-ktor/rsocket-transport-ktor-websocket-client/src/commonMain/kotlin/io/rsocket/kotlin/transport/ktor/websocket/client/WebSocketClientTransport.kt @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,8 +24,6 @@ import io.ktor.client.engine.* import io.ktor.client.plugins.websocket.* import io.ktor.client.request.* import io.ktor.http.* -import io.ktor.utils.io.core.internal.* -import io.ktor.utils.io.pool.* import io.rsocket.kotlin.* import io.rsocket.kotlin.transport.* import io.rsocket.kotlin.transport.ktor.websocket.* @@ -37,7 +35,6 @@ import kotlin.coroutines.* public fun WebSocketClientTransport( engineFactory: HttpClientEngineFactory, context: CoroutineContext = EmptyCoroutineContext, - pool: ObjectPool = ChunkBuffer.Pool, engine: T.() -> Unit = {}, webSockets: WebSockets.Config.() -> Unit = {}, request: HttpRequestBuilder.() -> Unit @@ -60,7 +57,7 @@ public fun WebSocketClientTransport( return ClientTransport(transportContext) { val session = httpClient.webSocketSession(request) - WebSocketConnection(session, pool) + WebSocketConnection(session) } } @@ -68,11 +65,10 @@ public fun WebSocketClientTransport( engineFactory: HttpClientEngineFactory, urlString: String, secure: Boolean = false, context: CoroutineContext = EmptyCoroutineContext, - pool: ObjectPool = ChunkBuffer.Pool, engine: HttpClientEngineConfig.() -> Unit = {}, webSockets: WebSockets.Config.() -> Unit = {}, - request: HttpRequestBuilder.() -> Unit = {} -): ClientTransport = WebSocketClientTransport(engineFactory, context, pool, engine, webSockets) { + request: HttpRequestBuilder.() -> Unit = {}, +): ClientTransport = WebSocketClientTransport(engineFactory, context, engine, webSockets) { url { this.protocol = if (secure) URLProtocol.WSS else URLProtocol.WS this.port = protocol.defaultPort @@ -88,11 +84,10 @@ public fun WebSocketClientTransport( path: String? = null, secure: Boolean = false, context: CoroutineContext = EmptyCoroutineContext, - pool: ObjectPool = ChunkBuffer.Pool, engine: HttpClientEngineConfig.() -> Unit = {}, webSockets: WebSockets.Config.() -> Unit = {}, - request: HttpRequestBuilder.() -> Unit = {} -): ClientTransport = WebSocketClientTransport(engineFactory, context, pool, engine, webSockets) { + request: HttpRequestBuilder.() -> Unit = {}, +): ClientTransport = WebSocketClientTransport(engineFactory, context, engine, webSockets) { url { this.protocol = if (secure) URLProtocol.WSS else URLProtocol.WS this.port = protocol.defaultPort diff --git a/rsocket-transport-ktor/rsocket-transport-ktor-websocket-server/api/rsocket-transport-ktor-websocket-server.api b/rsocket-transport-ktor/rsocket-transport-ktor-websocket-server/api/rsocket-transport-ktor-websocket-server.api index 046037db..4c9b6cde 100644 --- a/rsocket-transport-ktor/rsocket-transport-ktor-websocket-server/api/rsocket-transport-ktor-websocket-server.api +++ b/rsocket-transport-ktor/rsocket-transport-ktor-websocket-server/api/rsocket-transport-ktor-websocket-server.api @@ -1,7 +1,7 @@ public final class io/rsocket/kotlin/transport/ktor/websocket/server/WebSocketServerTransportKt { - public static final fun WebSocketServerTransport (Lio/ktor/server/engine/ApplicationEngineFactory;ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;Lio/ktor/utils/io/pool/ObjectPool;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Lio/rsocket/kotlin/transport/ServerTransport; - public static final fun WebSocketServerTransport (Lio/ktor/server/engine/ApplicationEngineFactory;[Lio/ktor/server/engine/EngineConnectorConfig;Ljava/lang/String;Ljava/lang/String;Lio/ktor/utils/io/pool/ObjectPool;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Lio/rsocket/kotlin/transport/ServerTransport; - public static synthetic fun WebSocketServerTransport$default (Lio/ktor/server/engine/ApplicationEngineFactory;ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;Lio/ktor/utils/io/pool/ObjectPool;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lio/rsocket/kotlin/transport/ServerTransport; - public static synthetic fun WebSocketServerTransport$default (Lio/ktor/server/engine/ApplicationEngineFactory;[Lio/ktor/server/engine/EngineConnectorConfig;Ljava/lang/String;Ljava/lang/String;Lio/ktor/utils/io/pool/ObjectPool;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lio/rsocket/kotlin/transport/ServerTransport; + public static final fun WebSocketServerTransport (Lio/ktor/server/engine/ApplicationEngineFactory;ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Lio/rsocket/kotlin/transport/ServerTransport; + public static final fun WebSocketServerTransport (Lio/ktor/server/engine/ApplicationEngineFactory;[Lio/ktor/server/engine/EngineConnectorConfig;Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Lio/rsocket/kotlin/transport/ServerTransport; + public static synthetic fun WebSocketServerTransport$default (Lio/ktor/server/engine/ApplicationEngineFactory;ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lio/rsocket/kotlin/transport/ServerTransport; + public static synthetic fun WebSocketServerTransport$default (Lio/ktor/server/engine/ApplicationEngineFactory;[Lio/ktor/server/engine/EngineConnectorConfig;Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lio/rsocket/kotlin/transport/ServerTransport; } diff --git a/rsocket-transport-ktor/rsocket-transport-ktor-websocket-server/src/commonMain/kotlin/io/rsocket/kotlin/transport/ktor/websocket/server/WebSocketServerTransport.kt b/rsocket-transport-ktor/rsocket-transport-ktor-websocket-server/src/commonMain/kotlin/io/rsocket/kotlin/transport/ktor/websocket/server/WebSocketServerTransport.kt index c7e64aa3..12426887 100644 --- a/rsocket-transport-ktor/rsocket-transport-ktor-websocket-server/src/commonMain/kotlin/io/rsocket/kotlin/transport/ktor/websocket/server/WebSocketServerTransport.kt +++ b/rsocket-transport-ktor/rsocket-transport-ktor-websocket-server/src/commonMain/kotlin/io/rsocket/kotlin/transport/ktor/websocket/server/WebSocketServerTransport.kt @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,8 +20,6 @@ import io.ktor.server.application.* import io.ktor.server.engine.* import io.ktor.server.routing.* import io.ktor.server.websocket.* -import io.ktor.utils.io.core.internal.* -import io.ktor.utils.io.pool.* import io.rsocket.kotlin.* import io.rsocket.kotlin.transport.* import io.rsocket.kotlin.transport.ktor.websocket.* @@ -33,7 +31,6 @@ public fun WebSocke engineFactory: ApplicationEngineFactory, port: Int = 80, host: String = "0.0.0.0", path: String? = null, protocol: String? = null, - pool: ObjectPool = ChunkBuffer.Pool, engine: T.() -> Unit = {}, webSockets: WebSockets.WebSocketOptions.() -> Unit = {}, ): ServerTransport = WebSocketServerTransport( @@ -44,7 +41,6 @@ public fun WebSocke } as EngineConnectorConfig, path = path, protocol = protocol, - pool = pool, engine = engine, webSockets = webSockets, ) @@ -55,12 +51,11 @@ public fun WebSocke engineFactory: ApplicationEngineFactory, vararg connectors: EngineConnectorConfig, path: String? = null, protocol: String? = null, - pool: ObjectPool = ChunkBuffer.Pool, engine: T.() -> Unit = {}, webSockets: WebSockets.WebSocketOptions.() -> Unit = {}, ): ServerTransport = ServerTransport { acceptor -> val handler: suspend DefaultWebSocketServerSession.() -> Unit = { - val connection = WebSocketConnection(this, pool) + val connection = WebSocketConnection(this) acceptor(connection) } embeddedServer(engineFactory, *connectors, configure = engine) { diff --git a/rsocket-transport-ktor/rsocket-transport-ktor-websocket-server/src/commonTest/kotlin/io/rsocket/kotlin/transport/ktor/websocket/server/WebSocketTransportTest.kt b/rsocket-transport-ktor/rsocket-transport-ktor-websocket-server/src/commonTest/kotlin/io/rsocket/kotlin/transport/ktor/websocket/server/WebSocketTransportTest.kt index 6bc5d35c..d47c9a7d 100644 --- a/rsocket-transport-ktor/rsocket-transport-ktor-websocket-server/src/commonTest/kotlin/io/rsocket/kotlin/transport/ktor/websocket/server/WebSocketTransportTest.kt +++ b/rsocket-transport-ktor/rsocket-transport-ktor-websocket-server/src/commonTest/kotlin/io/rsocket/kotlin/transport/ktor/websocket/server/WebSocketTransportTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,7 +18,6 @@ package io.rsocket.kotlin.transport.ktor.websocket.server import io.ktor.client.engine.* import io.ktor.server.engine.* -import io.rsocket.kotlin.test.* import io.rsocket.kotlin.transport.ktor.websocket.client.* import io.rsocket.kotlin.transport.tests.* @@ -29,10 +28,10 @@ abstract class WebSocketTransportTest( override suspend fun before() { val port = PortProvider.next() startServer( - WebSocketServerTransport(serverEngine, port = port, pool = InUseTrackingPool) + WebSocketServerTransport(serverEngine, port = port) ) client = connectClient( - WebSocketClientTransport(clientEngine, port = port, context = testContext, pool = InUseTrackingPool) + WebSocketClientTransport(clientEngine, port = port, context = testContext) ) } } diff --git a/rsocket-transport-ktor/rsocket-transport-ktor-websocket/api/rsocket-transport-ktor-websocket.api b/rsocket-transport-ktor/rsocket-transport-ktor-websocket/api/rsocket-transport-ktor-websocket.api index a8992de9..90f9c276 100644 --- a/rsocket-transport-ktor/rsocket-transport-ktor-websocket/api/rsocket-transport-ktor-websocket.api +++ b/rsocket-transport-ktor/rsocket-transport-ktor-websocket/api/rsocket-transport-ktor-websocket.api @@ -1,7 +1,6 @@ public final class io/rsocket/kotlin/transport/ktor/websocket/WebSocketConnection : io/rsocket/kotlin/Connection, kotlinx/coroutines/CoroutineScope { - public fun (Lio/ktor/websocket/WebSocketSession;Lio/ktor/utils/io/pool/ObjectPool;)V + public fun (Lio/ktor/websocket/WebSocketSession;)V public fun getCoroutineContext ()Lkotlin/coroutines/CoroutineContext; - public fun getPool ()Lio/ktor/utils/io/pool/ObjectPool; public fun receive (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public fun send (Lio/ktor/utils/io/core/ByteReadPacket;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; } diff --git a/rsocket-transport-ktor/rsocket-transport-ktor-websocket/src/commonMain/kotlin/io/rsocket/kotlin/transport/ktor/websocket/WebSocketConnection.kt b/rsocket-transport-ktor/rsocket-transport-ktor-websocket/src/commonMain/kotlin/io/rsocket/kotlin/transport/ktor/websocket/WebSocketConnection.kt index 065d1760..47423e62 100644 --- a/rsocket-transport-ktor/rsocket-transport-ktor-websocket/src/commonMain/kotlin/io/rsocket/kotlin/transport/ktor/websocket/WebSocketConnection.kt +++ b/rsocket-transport-ktor/rsocket-transport-ktor-websocket/src/commonMain/kotlin/io/rsocket/kotlin/transport/ktor/websocket/WebSocketConnection.kt @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,8 +17,6 @@ package io.rsocket.kotlin.transport.ktor.websocket import io.ktor.utils.io.core.* -import io.ktor.utils.io.core.internal.* -import io.ktor.utils.io.pool.* import io.ktor.websocket.* import io.rsocket.kotlin.* import kotlinx.coroutines.* @@ -26,7 +24,6 @@ import kotlinx.coroutines.* @TransportApi public class WebSocketConnection( private val session: WebSocketSession, - override val pool: ObjectPool ) : Connection, CoroutineScope by session { override suspend fun send(packet: ByteReadPacket) { session.send(packet.readBytes()) diff --git a/rsocket-transport-local/api/rsocket-transport-local.api b/rsocket-transport-local/api/rsocket-transport-local.api index 327d0e99..6d416bc0 100644 --- a/rsocket-transport-local/api/rsocket-transport-local.api +++ b/rsocket-transport-local/api/rsocket-transport-local.api @@ -4,7 +4,6 @@ public final class io/rsocket/kotlin/transport/local/LocalServer : io/rsocket/ko } public final class io/rsocket/kotlin/transport/local/LocalServerKt { - public static final fun LocalServerTransport (Lio/ktor/utils/io/pool/ObjectPool;)Lio/rsocket/kotlin/transport/ServerTransport; - public static synthetic fun LocalServerTransport$default (Lio/ktor/utils/io/pool/ObjectPool;ILjava/lang/Object;)Lio/rsocket/kotlin/transport/ServerTransport; + public static final fun LocalServerTransport ()Lio/rsocket/kotlin/transport/ServerTransport; } diff --git a/rsocket-transport-local/src/commonMain/kotlin/io/rsocket/kotlin/transport/local/LocalConnection.kt b/rsocket-transport-local/src/commonMain/kotlin/io/rsocket/kotlin/transport/local/LocalConnection.kt index 120acf7c..3ea281e4 100644 --- a/rsocket-transport-local/src/commonMain/kotlin/io/rsocket/kotlin/transport/local/LocalConnection.kt +++ b/rsocket-transport-local/src/commonMain/kotlin/io/rsocket/kotlin/transport/local/LocalConnection.kt @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,8 +17,6 @@ package io.rsocket.kotlin.transport.local import io.ktor.utils.io.core.* -import io.ktor.utils.io.core.internal.* -import io.ktor.utils.io.pool.* import io.rsocket.kotlin.* import kotlinx.coroutines.channels.* import kotlin.coroutines.* @@ -27,7 +25,6 @@ import kotlin.coroutines.* internal class LocalConnection( private val sender: SendChannel, private val receiver: ReceiveChannel, - override val pool: ObjectPool, override val coroutineContext: CoroutineContext ) : Connection { diff --git a/rsocket-transport-local/src/commonMain/kotlin/io/rsocket/kotlin/transport/local/LocalServer.kt b/rsocket-transport-local/src/commonMain/kotlin/io/rsocket/kotlin/transport/local/LocalServer.kt index e0a34f93..d52cab25 100644 --- a/rsocket-transport-local/src/commonMain/kotlin/io/rsocket/kotlin/transport/local/LocalServer.kt +++ b/rsocket-transport-local/src/commonMain/kotlin/io/rsocket/kotlin/transport/local/LocalServer.kt @@ -1,5 +1,5 @@ /* - * Copyright 2015-2023 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,8 +20,6 @@ package io.rsocket.kotlin.transport.local import io.ktor.utils.io.core.* -import io.ktor.utils.io.core.internal.* -import io.ktor.utils.io.pool.* import io.rsocket.kotlin.* import io.rsocket.kotlin.internal.io.* import io.rsocket.kotlin.transport.* @@ -29,9 +27,7 @@ import kotlinx.coroutines.* import kotlinx.coroutines.channels.* import kotlin.coroutines.* -public fun LocalServerTransport( - pool: ObjectPool = ChunkBuffer.Pool, -): ServerTransport = ServerTransport { accept -> +public fun LocalServerTransport(): ServerTransport = ServerTransport { accept -> val connections = Channel() val handlerJob = launch { supervisorScope { @@ -40,11 +36,10 @@ public fun LocalServerTransport( } } } - LocalServer(pool, connections, coroutineContext + SupervisorJob(handlerJob)) + LocalServer(connections, coroutineContext + SupervisorJob(handlerJob)) } public class LocalServer internal constructor( - private val pool: ObjectPool, private val connections: Channel, override val coroutineContext: CoroutineContext, ) : ClientTransport { @@ -60,13 +55,11 @@ public class LocalServer internal constructor( val clientConnection = LocalConnection( sender = serverChannel, receiver = clientChannel, - pool = pool, coroutineContext = connectionContext + CoroutineName("rSocket-local-client") ) val serverConnection = LocalConnection( sender = clientChannel, receiver = serverChannel, - pool = pool, coroutineContext = connectionContext + CoroutineName("rSocket-local-server") ) connections.send(serverConnection) diff --git a/rsocket-transport-local/src/commonTest/kotlin/io/rsocket/kotlin/transport/local/LocalTransportTest.kt b/rsocket-transport-local/src/commonTest/kotlin/io/rsocket/kotlin/transport/local/LocalTransportTest.kt index a51eba76..384e1944 100644 --- a/rsocket-transport-local/src/commonTest/kotlin/io/rsocket/kotlin/transport/local/LocalTransportTest.kt +++ b/rsocket-transport-local/src/commonTest/kotlin/io/rsocket/kotlin/transport/local/LocalTransportTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,12 +16,11 @@ package io.rsocket.kotlin.transport.local -import io.rsocket.kotlin.test.* import io.rsocket.kotlin.transport.tests.* class LocalTransportTest : TransportTest() { override suspend fun before() { - val server = startServer(LocalServerTransport(InUseTrackingPool)) + val server = startServer(LocalServerTransport()) client = connectClient(server) } } diff --git a/rsocket-transport-nodejs-tcp/src/jsMain/kotlin/io/rsocket/kotlin/transport/nodejs/tcp/TcpClientTransport.kt b/rsocket-transport-nodejs-tcp/src/jsMain/kotlin/io/rsocket/kotlin/transport/nodejs/tcp/TcpClientTransport.kt index f0c536d9..06b10a95 100644 --- a/rsocket-transport-nodejs-tcp/src/jsMain/kotlin/io/rsocket/kotlin/transport/nodejs/tcp/TcpClientTransport.kt +++ b/rsocket-transport-nodejs-tcp/src/jsMain/kotlin/io/rsocket/kotlin/transport/nodejs/tcp/TcpClientTransport.kt @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,8 +16,6 @@ package io.rsocket.kotlin.transport.nodejs.tcp -import io.ktor.utils.io.core.internal.* -import io.ktor.utils.io.pool.* import io.rsocket.kotlin.* import io.rsocket.kotlin.transport.* import io.rsocket.kotlin.transport.nodejs.tcp.internal.* @@ -27,7 +25,6 @@ import kotlin.coroutines.* public class TcpClientTransport( private val port: Int, private val hostname: String, - private val pool: ObjectPool = ChunkBuffer.Pool, coroutineContext: CoroutineContext = EmptyCoroutineContext ) : ClientTransport { @@ -36,6 +33,6 @@ public class TcpClientTransport( @TransportApi override suspend fun connect(): Connection { val socket = connect(port, hostname) - return TcpConnection(coroutineContext, pool, socket) + return TcpConnection(coroutineContext, socket) } } diff --git a/rsocket-transport-nodejs-tcp/src/jsMain/kotlin/io/rsocket/kotlin/transport/nodejs/tcp/TcpConnection.kt b/rsocket-transport-nodejs-tcp/src/jsMain/kotlin/io/rsocket/kotlin/transport/nodejs/tcp/TcpConnection.kt index 4d49201b..adf50244 100644 --- a/rsocket-transport-nodejs-tcp/src/jsMain/kotlin/io/rsocket/kotlin/transport/nodejs/tcp/TcpConnection.kt +++ b/rsocket-transport-nodejs-tcp/src/jsMain/kotlin/io/rsocket/kotlin/transport/nodejs/tcp/TcpConnection.kt @@ -1,5 +1,5 @@ /* - * Copyright 2015-2023 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,9 +17,7 @@ package io.rsocket.kotlin.transport.nodejs.tcp import io.ktor.utils.io.core.* -import io.ktor.utils.io.core.internal.* import io.ktor.utils.io.js.* -import io.ktor.utils.io.pool.* import io.rsocket.kotlin.* import io.rsocket.kotlin.internal.io.* import io.rsocket.kotlin.transport.nodejs.tcp.internal.* @@ -31,7 +29,6 @@ import kotlin.coroutines.* @TransportApi internal class TcpConnection( override val coroutineContext: CoroutineContext, - override val pool: ObjectPool, private val socket: Socket, ) : Connection { diff --git a/rsocket-transport-nodejs-tcp/src/jsMain/kotlin/io/rsocket/kotlin/transport/nodejs/tcp/TcpServerTransport.kt b/rsocket-transport-nodejs-tcp/src/jsMain/kotlin/io/rsocket/kotlin/transport/nodejs/tcp/TcpServerTransport.kt index 77fcea61..d6872a48 100644 --- a/rsocket-transport-nodejs-tcp/src/jsMain/kotlin/io/rsocket/kotlin/transport/nodejs/tcp/TcpServerTransport.kt +++ b/rsocket-transport-nodejs-tcp/src/jsMain/kotlin/io/rsocket/kotlin/transport/nodejs/tcp/TcpServerTransport.kt @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,8 +16,6 @@ package io.rsocket.kotlin.transport.nodejs.tcp -import io.ktor.utils.io.core.internal.* -import io.ktor.utils.io.pool.* import io.rsocket.kotlin.* import io.rsocket.kotlin.transport.* import io.rsocket.kotlin.transport.nodejs.tcp.internal.* @@ -33,14 +31,14 @@ public class TcpServer internal constructor( } public class TcpServerTransport( - private val port: Int, private val hostname: String, private val pool: ObjectPool = ChunkBuffer.Pool + private val port: Int, private val hostname: String, ) : ServerTransport { @TransportApi override fun CoroutineScope.start(accept: suspend CoroutineScope.(Connection) -> Unit): TcpServer { val supervisorJob = SupervisorJob(coroutineContext[Job]) val server = createServer(port, hostname, { supervisorJob.cancel() }) { launch(supervisorJob) { - accept(TcpConnection(coroutineContext, pool, it)) + accept(TcpConnection(coroutineContext, it)) } } return TcpServer(supervisorJob, server) diff --git a/rsocket-transport-nodejs-tcp/src/jsTest/kotlin/io/rsocket/kotlin/transport/nodejs/tcp/TcpTransportTest.kt b/rsocket-transport-nodejs-tcp/src/jsTest/kotlin/io/rsocket/kotlin/transport/nodejs/tcp/TcpTransportTest.kt index 6699f3db..0fd9a497 100644 --- a/rsocket-transport-nodejs-tcp/src/jsTest/kotlin/io/rsocket/kotlin/transport/nodejs/tcp/TcpTransportTest.kt +++ b/rsocket-transport-nodejs-tcp/src/jsTest/kotlin/io/rsocket/kotlin/transport/nodejs/tcp/TcpTransportTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,6 @@ package io.rsocket.kotlin.transport.nodejs.tcp -import io.rsocket.kotlin.test.* import io.rsocket.kotlin.transport.tests.* import kotlinx.coroutines.* @@ -25,8 +24,8 @@ class TcpTransportTest : TransportTest() { override suspend fun before() { val port = PortProvider.next() - server = startServer(TcpServerTransport(port, "127.0.0.1", InUseTrackingPool)) - client = connectClient(TcpClientTransport(port, "127.0.0.1", InUseTrackingPool, testContext)) + server = startServer(TcpServerTransport(port, "127.0.0.1")) + client = connectClient(TcpClientTransport(port, "127.0.0.1", testContext)) } override suspend fun after() {