Remove Client property from TcpClient and UdpClient#5953
Remove Client property from TcpClient and UdpClient#5953davidsh merged 1 commit intodotnet:masterfrom
Conversation
The property leaks through the abstraction. It's rarely used. And it complicates things on Unix due to exposing the underlying socket instance combined with difficulties with multiple connect calls on a single socket instance. Until we have good reason to expose it in the contract, we're removing it from the contract before it's stable.
|
hm...how to get or set ReceiveTimeout/SendTimeout for UdpClient with these changes? |
There are many granular properties of a |
|
@corivera PTAL |
|
Looks good for SqlClient. |
|
LGTM |
|
@davidsh, you can merge this at your convenience when you're ready to handle any internal test issues. |
I've checked in the internal test changes. So, we can merge this when GREEN. |
|
@stephentoub Thx for doing the PR and driving related downstream changes. |
Remove Client property from TcpClient and UdpClient
|
Here's a good reason we need this - I cannot currently create a UdpClient that shares a socket correctly. I get an exception with "Only one usage of each socket address (protocol/network address/port) is normally permitted". The way I handled this before was to create a UdpClient with the default ctor, use the SetSocketOptions for sharing/non-exclusive use, then call Client.Bind(localEndpoint). It's now impossible to do this because the |
|
One option might be to put another ctor arg for exclusive address use so that we can pass that in up-front and prevent the issue? |
Does it mean that in 1.0 RTM |
No. That was a mistake in Milestone labeling. This PR was merged a while ago. You can look at the current System.Net.Sockets contract here and see what properties are available on the TcpClient class: |
|
Without either Client exposed on UdpClient or a way to set exclusive to false before the bind via the ctor, I need to use this really ugly hack along with a static Socket GetSocketFromUdpClient(UdpClient client)
{
var mi = GetSocketMember.Value as MethodInfo;
if (mi != null)
{
return (Socket)mi.Invoke(client, null);
}
var fi = GetSocketMember.Value as FieldInfo;
if (fi != null)
{
return (Socket)fi.GetValue(client);
}
throw new NotSupportedException("Could not locate Socket");
}
static readonly Lazy<MemberInfo> GetSocketMember = new Lazy<MemberInfo>(GetSocketMemberImpl);
static MemberInfo GetSocketMemberImpl()
{
// See if there's a client prop
var pi = typeof(UdpClient).GetRuntimeProperties().FirstOrDefault(p => p.PropertyType == typeof(Socket));
if (pi != null)
return pi.GetMethod;
var mi = typeof(UdpClient).GetRuntimeFields().First(fi => fi.FieldType == typeof(Socket));
return mi;
}
} |
|
@onovotny I totally understand your requirements. However, it was not possible to leave the Please open a new issue (since this PR is merged and closed) and propose an API change. We then all can discuss how to address this requirement. You can reference this PR in your new issue. Thx. |
To clarify, there were a few concerns with these properties:
|
|
@stephentoub Thanks for the clarification. While the |
Mainly a cleaned-up revert of dotnet#5953.
Mainly a cleaned-up revert of dotnet#5953.
Remove Client property from TcpClient and UdpClient Commit migrated from dotnet/corefx@1384104
Mainly a cleaned-up revert of dotnet/corefx#5953. Commit migrated from dotnet/corefx@34bc6fc
The property leaks through the abstraction. It's rarely used. And it complicates things on Unix due to exposing the underlying socket instance combined with difficulties with multiple connect calls on a single socket instance.
Until we have good reason to expose it in the contract, we're removing it from the contract before it's stable.
cc: @davidsh, @CIPop, @SidharthNabar, @terrajobst, @weshaggard, @saurabh500
Closes #4968
Closes #5411