Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Conversation

geoffkizer
Copy link

We complete all I/O asynchronously, even when the underlying OS operation actually completed synchronously.

Fix this so that both Windows and Unix can do synchronous socket completions.

@stephentoub @CIPop @davidsh @Priya91


}

private static readonly bool IsWindows7OrBefore;
Copy link
Member

Choose a reason for hiding this comment

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

Nit: s_isWindows7OrBefore


private static readonly bool IsWindows7OrBefore;

static Socket()
Copy link
Member

@stephentoub stephentoub Jan 12, 2017

Choose a reason for hiding this comment

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

How about putting this into a static method that's then used to initialize the field rather than using an explicit cctor? e.g.

private static readonly bool s_isWindows7OrBefore = GetIsWindows7OrBefore();
private static bool GetIsWindows7OrBefore()
{
    Version osVersion = Environment.OSVersion.Version;
    return osVersion.Major < 6 || (osVersion.Major == 6 && osVersion.Minor <= 1);
}

Unless something's changed, having an explicit cctor prevents usage of beforefieldinit on the type.

Copy link
Author

Choose a reason for hiding this comment

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

Will do. I need to rework this anyway because it appears to fail on UAP.

var tup = (Tuple<Action<IntPtr, byte[], int, SocketError>, IntPtr, byte[], int>)args;
tup.Item1(tup.Item2, tup.Item3, tup.Item4, SocketError.Success);
}, Tuple.Create(callback, acceptedFd, socketAddress, socketAddressLen));
}
Copy link
Member

Choose a reason for hiding this comment

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

Seeing this code get deleted makes me smile :)

Copy link
Author

Choose a reason for hiding this comment

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

I know what you mean 👍

int bytesReceived;
SocketFlags receivedFlags;
bytesReceived = 0;
receivedFlags = SocketFlags.None;
Copy link
Member

Choose a reason for hiding this comment

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

Should this initialization now be moved down to after the subsequent if? We don't need to set these prior to that, right?

Copy link
Author

Choose a reason for hiding this comment

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

Yes, good catch. Fixed.

int bytesReceived;
SocketFlags receivedFlags;
bytesReceived = 0;
receivedFlags = SocketFlags.None;
Copy link
Member

Choose a reason for hiding this comment

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

Same question here (and anywhere else the same pattern applies).

Copy link
Member

@stephentoub stephentoub left a comment

Choose a reason for hiding this comment

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

Nice job, @geoffkizer. Do you have any perf measurements you can share on the impact of this on some microbenchmarks? I'd expect it to be fairly significant. Once it's merged in I'll plan to rerun some of my experiments with the managed ClientWebSocket implementation; I'd seen some notable perf hits because of this, so hopefully it'll see some sizeable improvements.

@geoffkizer
Copy link
Author

I did preliminary perf runs a while back and they were quite good. I will rerun on this change to confirm and get the latest results.

@geoffkizer
Copy link
Author

@dotnet-bot
test outerloop Windows_NT debug
test outerloop Windows_NT release
test outerloop OSX debug
test outerloop OSX release
test outerloop Ubuntu14.04 debug
test outerloop Ubuntu14.04 release

@stephentoub
Copy link
Member

@dotnet-bot test outerloop Ubuntu14.04 debug
@dotnet-bot test outerloop Windows_NT debug
@dotnet-bot test outerloop Windows_NT release

@geoffkizer
Copy link
Author

Quick and dirty perf results on my machine:

For my simple request/response test, req/s went from 61016 to 70101, or about 15% improvement.

This is Windows, my crappy laptop, client GC, using SocketAsyncEventArgs.

The improvement I previously saw on bigger hardware was larger, but I don't have access to that hardware at the moment.

@geoffkizer
Copy link
Author

@dotnet-bot Innerloop Windows_NT Debug Build and Test

@geoffkizer
Copy link
Author

@dotnet-bot test Innerloop Windows_NT Debug Build and Test

@geoffkizer geoffkizer merged commit 684af05 into dotnet:master Jan 16, 2017
@karelz karelz modified the milestone: 2.0.0 Jan 21, 2017
dotnet-bot pushed a commit that referenced this pull request Jan 13, 2018
dotnet-bot pushed a commit that referenced this pull request Jan 13, 2018
safern pushed a commit that referenced this pull request Jan 16, 2018
safern pushed a commit that referenced this pull request Jan 16, 2018
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
implement synchronous completion support in Sockets

Commit migrated from dotnet/corefx@684af05
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants