Skip to content

Conversation

lauzadis
Copy link
Member

@lauzadis lauzadis commented Mar 4, 2024

Issue #, if available:
N/A

Description of changes:

  • Replace runSuspendTest with kotlinx-coroutines runTest across the entire repo
  • Implement K/N IO constructs: EventLoopGroup, TlsContext, ClientBootstrap, HostResolver, MutableBuffer

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

private val buf = buffer ?: Allocator.Default.alloc<aws_byte_buf>()

public val bytes: ByteArray
get() = buf.buffer!!.readBytes(buf.capacity.toInt())
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

discussion: This function makes a copy of the underlying bytes, I think it's the best we can do with the available CRT APIs but open to suggestions!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From this KDoc in the class:

NOTE: Platform implementations should provide direct access to the underlying bytes

Do you think we should just not provide access to the underlying bytes?

private val buf = buffer ?: Allocator.Default.alloc<aws_byte_buf>()

public val bytes: ByteArray
get() = buf.buffer!!.readBytes(buf.capacity.toInt())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this?

*/
public actual fun of(src: ByteArray): MutableBuffer {
TODO("Not yet implemented")
public actual fun of(src: ByteArray): MutableBuffer = src.usePinned { pinnedSrc ->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We only appear to use this in tests in smithy-kotlin.

I wonder if we need this or if we can get away with creating an aws_byte_buf without allocating it on the heap and having to free it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'll leave the implementation as-is and we can revisit it once we start implementing K/N in smithy-kotlin?

@lauzadis lauzadis marked this pull request as ready for review March 4, 2024 19:41
@lauzadis lauzadis requested a review from a team as a code owner March 4, 2024 19:41
Comment on lines +24 to +27
private val elg: CPointer<aws_event_loop_group>

override val ptr: CPointer<aws_event_loop_group>
get() = elg
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: I've seen this pattern a few times in the new (to me) Kotlin/Native code. What's the benefit of a separate backing field if the ptr always delegates to it anyway?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we're going to fix this soon. This stems from the original definition of CrtResource but I think we're going to just move to something like:

interface NativeHandle<T: CPointed> {
     val ptr: CPointer<T>
}

or perhaps name ptr to handle or nativeHandle. Either way I think we'd move to where we don't need a separate backing field.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I agree, the backing field sticks out and seems wrong, I plan to refactor after the memory management / CrtResource changes are shipped

Comment on lines +29 to +30
private val shutdownCompleteChannel = Channel<Unit>(Channel.RENDEZVOUS)
private val channelStableRef = StableRef.create(shutdownCompleteChannel)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: I don't understand what this channel is used for. It's a rendezvous channel so either send or receive suspends until the other is called, right? I see a send in onShutdownComplete but no receive call anywhere...won't this just suspend indefinitely?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I commented elsewhere, it should be waited on in waitForShutdown.

It won't block in onShutdownComplete because it's using trySend.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Mar 5, 2024

Quality Gate Passed Quality Gate passed

Issues
7 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants