Skip to content
This repository has been archived by the owner on Aug 2, 2023. It is now read-only.

Remove TryGetPointer from RioTcpConnection #1375

Merged
merged 4 commits into from
Mar 28, 2017

Conversation

KodrAus
Copy link
Contributor

@KodrAus KodrAus commented Mar 25, 2017

Part of #1298

Moves the GetSegmentFromMemory method into the RioThread and uses Pin instead of TryGetPointer. I think it's safe to not keep the MemoryHandle around because we verify the memory is from a Slab in the memory pool using its address, which we know is pinned.

So now it's RioThreads responsibility to make sure its buffers are pinned, which is better because it's the one creating the MemoryPool.

I'm not sure about error handling, if it turns out the memory isn't from a known slab then the RIO buffer id is IntPtr.Zero, but we're not explicitly dealing with this.

@benaadams
Copy link
Member

I think that looks good

/cc @davidfowl

@davidfowl
Copy link
Member

@KodrAus You need to call Free so the ref count doesn't just go up forever.

@KodrAus
Copy link
Contributor Author

KodrAus commented Mar 25, 2017

@davidfowl Derp. Fixed. That's a nice segway into there are no tests for any of this code. Looks like the libuv TCP server at least has a stress test. Should RIO have the same when tested on a Windows box?

@KodrAus
Copy link
Contributor Author

KodrAus commented Mar 25, 2017

@dnfclas Show me the CLA
@dnfclas I signed the CLA. ATTACH SIGNED LABEL bleep bloop.

@@ -116,6 +116,23 @@ public IntPtr GetBufferId(IntPtr address, out long startAddress)
return id;
}

public unsafe RioBufferSegment GetSegmentFromMemory(Buffer<byte> memory)
{
var pin = memory.Pin();
Copy link
Member

Choose a reason for hiding this comment

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

Add a comment about why it's ok to unpin here because the memory needs to be pinned already? How do we enforce that though? There's no way to know if the backing memory is already pinned...

Copy link
Member

Choose a reason for hiding this comment

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

But since we create the pool, it's ok. Just add the comment and I'll merge it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How's that?

Copy link
Member

@davidfowl davidfowl left a comment

Choose a reason for hiding this comment

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

LGTM

@davidfowl davidfowl merged commit 1a26917 into dotnet:master Mar 28, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants