Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions aws-crt-kotlin/api/aws-crt-kotlin.api
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,7 @@ public final class aws/sdk/kotlin/crt/io/BufferKt {
}

public final class aws/sdk/kotlin/crt/io/ClientBootstrap : aws/sdk/kotlin/crt/AsyncShutdown, aws/sdk/kotlin/crt/Closeable {
public fun <init> ()V
public fun <init> (Laws/sdk/kotlin/crt/io/EventLoopGroup;Laws/sdk/kotlin/crt/io/HostResolver;)V
public fun close ()V
public fun waitForShutdown (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
Expand All @@ -733,6 +734,7 @@ public final class aws/sdk/kotlin/crt/io/EventLoopGroup : aws/sdk/kotlin/crt/Asy
}

public final class aws/sdk/kotlin/crt/io/HostResolver : aws/sdk/kotlin/crt/AsyncShutdown, aws/sdk/kotlin/crt/Closeable {
public fun <init> ()V
public fun <init> (Laws/sdk/kotlin/crt/io/EventLoopGroup;)V
public fun <init> (Laws/sdk/kotlin/crt/io/EventLoopGroup;I)V
public fun close ()V
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import aws.sdk.kotlin.crt.Closeable
public expect class ClientBootstrap(elg: EventLoopGroup, hr: HostResolver) :
Closeable,
AsyncShutdown {
public constructor()

override suspend fun waitForShutdown()
override fun close()
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public expect class HostResolver(elg: EventLoopGroup, maxEntries: Int) :
Closeable,
AsyncShutdown {
public constructor(elg: EventLoopGroup)
public constructor()

override fun close()
override suspend fun waitForShutdown()
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,27 @@ import aws.sdk.kotlin.crt.Closeable
import kotlinx.coroutines.future.await
import software.amazon.awssdk.crt.io.ClientBootstrap as ClientBootstrapJni

public actual class ClientBootstrap actual constructor(elg: EventLoopGroup, hr: HostResolver) :
Closeable,
public actual class ClientBootstrap private constructor(
private val elg: EventLoopGroup,
private val manageElg: Boolean,
private val hr: HostResolver,
private val manageHr: Boolean,
) : Closeable,
AsyncShutdown {

public actual constructor() : this(EventLoopGroup(), true)

private constructor(elg: EventLoopGroup, manageElg: Boolean) : this(elg, manageElg, HostResolver(elg), true)

public actual constructor(elg: EventLoopGroup, hr: HostResolver) : this(elg, false, hr, false)

internal val jniBootstrap = ClientBootstrapJni(elg.jniElg, hr.jniHr)

actual override fun close() {
jniBootstrap.close()

if (manageHr) hr.close()
if (manageElg) elg.close()
}

actual override suspend fun waitForShutdown() {
Expand Down
13 changes: 10 additions & 3 deletions aws-crt-kotlin/jvm/src/aws/sdk/kotlin/crt/io/HostResolverJVM.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,22 @@ import aws.sdk.kotlin.crt.AsyncShutdown
import aws.sdk.kotlin.crt.Closeable
import software.amazon.awssdk.crt.io.HostResolver as HostResolverJni

public actual class HostResolver actual constructor(elg: EventLoopGroup, maxEntries: Int) :
Closeable,
public actual class HostResolver private constructor(
private val elg: EventLoopGroup,
private val manageElg: Boolean,
maxEntries: Int,
) : Closeable,
AsyncShutdown {
internal val jniHr = HostResolverJni(elg.jniElg, maxEntries)

public actual constructor(elg: EventLoopGroup) : this(elg, DEFAULT_MAX_ENTRIES)
public actual constructor(elg: EventLoopGroup, maxEntries: Int) : this(elg, false, maxEntries)
public actual constructor(elg: EventLoopGroup) : this(elg, false, DEFAULT_MAX_ENTRIES)
public actual constructor() : this(EventLoopGroup(), true, DEFAULT_MAX_ENTRIES)

actual override fun close() {
jniHr.close()

if (manageElg) elg.close()
}

actual override suspend fun waitForShutdown() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@

package aws.sdk.kotlin.crt.io

import aws.sdk.kotlin.crt.*
import aws.sdk.kotlin.crt.Allocator
import aws.sdk.kotlin.crt.AsyncShutdown
import aws.sdk.kotlin.crt.Closeable
import aws.sdk.kotlin.crt.NativeHandle
import aws.sdk.kotlin.crt.util.ShutdownChannel
import aws.sdk.kotlin.crt.util.shutdownChannel
import kotlinx.cinterop.*
Expand All @@ -16,12 +18,19 @@ import libcrt.aws_client_bootstrap_options
import libcrt.aws_client_bootstrap_release

@OptIn(ExperimentalForeignApi::class)
public actual class ClientBootstrap actual constructor(
elg: EventLoopGroup,
hr: HostResolver,
public actual class ClientBootstrap private constructor(
private val elg: EventLoopGroup,
private val manageElg: Boolean,
private val hr: HostResolver,
private val manageHr: Boolean,
) : NativeHandle<aws_client_bootstrap>,
Closeable,
AsyncShutdown {

public actual constructor() : this(EventLoopGroup(), true)
private constructor(elg: EventLoopGroup, manageElg: Boolean) : this(elg, manageElg, HostResolver(elg), true)
public actual constructor(elg: EventLoopGroup, hr: HostResolver) : this(elg, false, hr, false)

private val shutdownCompleteChannel = shutdownChannel()
private val channelStableRef = StableRef.create(shutdownCompleteChannel)
override val ptr: CPointer<aws_client_bootstrap>
Expand All @@ -45,6 +54,9 @@ public actual class ClientBootstrap actual constructor(

actual override fun close() {
aws_client_bootstrap_release(ptr)

if (manageHr) hr.close()
if (manageElg) elg.close()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@

package aws.sdk.kotlin.crt.io

import aws.sdk.kotlin.crt.*
import aws.sdk.kotlin.crt.Allocator
import aws.sdk.kotlin.crt.AsyncShutdown
import aws.sdk.kotlin.crt.Closeable
import aws.sdk.kotlin.crt.NativeHandle
import aws.sdk.kotlin.crt.util.ShutdownChannel
import aws.sdk.kotlin.crt.util.shutdownChannel
import cnames.structs.aws_event_loop_group
import kotlinx.cinterop.*
import libcrt.*
import libcrt.aws_event_loop_group_new
import libcrt.aws_event_loop_group_options
import libcrt.aws_event_loop_group_release
import libcrt.aws_shutdown_callback_options

/**
* Creates a new event loop group for the I/O subsystem to use to run blocking I/O requests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,27 @@

package aws.sdk.kotlin.crt.io

import aws.sdk.kotlin.crt.*
import aws.sdk.kotlin.crt.Allocator
import aws.sdk.kotlin.crt.AsyncShutdown
import aws.sdk.kotlin.crt.Closeable
import aws.sdk.kotlin.crt.NativeHandle
import aws.sdk.kotlin.crt.util.ShutdownChannel
import aws.sdk.kotlin.crt.util.shutdownChannel
import kotlinx.cinterop.*
import libcrt.*

@OptIn(ExperimentalForeignApi::class)
public actual class HostResolver actual constructor(elg: EventLoopGroup, maxEntries: Int) :
NativeHandle<aws_host_resolver>,
public actual class HostResolver private constructor(
private val elg: EventLoopGroup,
private val manageElg: Boolean,
private val maxEntries: Int,
) : NativeHandle<aws_host_resolver>,
Closeable,
AsyncShutdown {
public actual constructor(elg: EventLoopGroup) : this(elg, DEFAULT_MAX_ENTRIES)

public actual constructor(elg: EventLoopGroup, maxEntries: Int) : this(elg, false, maxEntries)
public actual constructor(elg: EventLoopGroup) : this(elg, false, DEFAULT_MAX_ENTRIES)
public actual constructor() : this(EventLoopGroup(), true, DEFAULT_MAX_ENTRIES)

override val ptr: CPointer<aws_host_resolver>

Expand Down Expand Up @@ -49,6 +57,8 @@ public actual class HostResolver actual constructor(elg: EventLoopGroup, maxEntr

actual override fun close() {
aws_host_resolver_release(ptr)

if (manageElg) elg.close()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
package aws.sdk.kotlin.crt.io

import aws.sdk.kotlin.crt.*
import aws.sdk.kotlin.crt.Allocator
import aws.sdk.kotlin.crt.awsAssertOpSuccess
import aws.sdk.kotlin.crt.util.asAwsByteCursor
import aws.sdk.kotlin.crt.util.free
import aws.sdk.kotlin.crt.util.toAwsString
Expand Down
Loading