Skip to content

Commit d233243

Browse files
committed
Use new constructor fn
1 parent 431e2b4 commit d233243

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

aws-crt-kotlin/native/src/aws/sdk/kotlin/crt/io/EventLoopGroupNative.kt

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import aws.sdk.kotlin.crt.util.ShutdownChannel
1111
import aws.sdk.kotlin.crt.util.shutdownChannel
1212
import kotlinx.cinterop.*
1313
import libcrt.*
14+
import cnames.structs.aws_event_loop_group
1415

1516
/**
1617
* Creates a new event loop group for the I/O subsystem to use to run blocking I/O requests
@@ -32,13 +33,19 @@ public actual class EventLoopGroup actual constructor(maxThreads: Int) :
3233
private val channelStableRef = StableRef.create(shutdownCompleteChannel)
3334

3435
init {
35-
val shutdownOpts = cValue<aws_shutdown_callback_options> {
36-
shutdown_callback_fn = staticCFunction(::onShutdownComplete)
37-
shutdown_callback_user_data = channelStableRef.asCPointer()
38-
}
36+
ptr = memScoped {
37+
val shutdownOpts = cValue<aws_shutdown_callback_options> {
38+
shutdown_callback_fn = staticCFunction(::onShutdownComplete)
39+
shutdown_callback_user_data = channelStableRef.asCPointer()
40+
}
41+
42+
val eventLoopGroupOpts = cValue<aws_event_loop_group_options> {
43+
shutdown_options = shutdownOpts.ptr
44+
}
3945

40-
ptr = checkNotNull(aws_event_loop_group_new_default(Allocator.Default, maxThreads.toUShort(), shutdownOpts)) {
41-
"aws_event_loop_group_new_default()"
46+
checkNotNull(aws_event_loop_group_new(Allocator.Default, eventLoopGroupOpts)) {
47+
"aws_event_loop_group_new()"
48+
}
4249
}
4350
}
4451

0 commit comments

Comments
 (0)