Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose Socket via a Kestrel ConnectionContext feature #28401

Closed
halter73 opened this issue Dec 4, 2020 · 5 comments · Fixed by #31588
Closed

Expose Socket via a Kestrel ConnectionContext feature #28401

halter73 opened this issue Dec 4, 2020 · 5 comments · Fixed by #31588
Assignees
Labels
affected-very-few This issue impacts very few customers api-approved API was approved in API review, it can be implemented area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions enhancement This issue represents an ask for new feature or an enhancement to an existing one feature-kestrel help wanted Up for grabs. We would accept a PR to help resolve this issue severity-nice-to-have This label is used by an internal tool
Milestone

Comments

@halter73
Copy link
Member

halter73 commented Dec 4, 2020

Is your feature request related to a problem? Please describe.

We should make it so you don't have to resort to something like the following to access the managed Socket if you really want to.

var socket = (Socket)connectionContext.GetType().GetField("_socket", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(connectionContext);

Proposed API

using System.Net.Sockets;

namespace Microsoft.AspNetCore.Connections.Features
{
+    public interface IConnectionSocketFeature
+   {
+        Socket? Socket { get; }
+    }
}

Usage Examples

var socket = connectionContext.Features.Get<IConnectionSocketFeature>().Socket;
@ghost
Copy link

ghost commented Dec 4, 2020

Thanks for contacting us.
We're moving this issue to the Next sprint planning milestone for future evaluation / consideration. We will evaluate the request when we are planning the work for the next milestone. To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

@jkotalik jkotalik added affected-very-few This issue impacts very few customers enhancement This issue represents an ask for new feature or an enhancement to an existing one severity-nice-to-have This label is used by an internal tool labels Dec 4, 2020 — with ASP.NET Core Issue Ranking
@BrennanConroy BrennanConroy added the help wanted Up for grabs. We would accept a PR to help resolve this issue label Feb 10, 2021
@BrennanConroy
Copy link
Member

What are examples of usage for this? What settings do you want after creation of the socket?

@BrennanConroy
Copy link
Member

What are examples of usage for this?

Force a reset.

@davidfowl davidfowl added the api-ready-for-review API is ready for formal API review - https://github.com/dotnet/apireviews label Mar 23, 2021
@davidfowl
Copy link
Member

davidfowl commented Mar 29, 2021

Another use case that came up last week was the ability to get tcp information via a new ioctl SIO_TCP_INFO https://docs.microsoft.com/en-us/windows/win32/winsock/sio-tcp-info.

@pranavkm
Copy link
Contributor

pranavkm commented Apr 5, 2021

Proposed API

using System.Net.Sockets;

namespace Microsoft.AspNetCore.Connections.Features
{
+    public interface IConnectionSocketFeature
+   {
+        Socket Socket { get; }
+    }
}

Usage Examples

var socket = connectionContext.Features.Get<IConnectionSocketFeature>()?.Socket;
if (socket is not null)

@pranavkm pranavkm added api-approved API was approved in API review, it can be implemented and removed api-ready-for-review API is ready for formal API review - https://github.com/dotnet/apireviews labels Apr 5, 2021
@ghost ghost locked as resolved and limited conversation to collaborators May 7, 2021
@amcasey amcasey added area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions and removed area-runtime labels Jun 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affected-very-few This issue impacts very few customers api-approved API was approved in API review, it can be implemented area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions enhancement This issue represents an ask for new feature or an enhancement to an existing one feature-kestrel help wanted Up for grabs. We would accept a PR to help resolve this issue severity-nice-to-have This label is used by an internal tool
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants
@halter73 @davidfowl @pranavkm @BrennanConroy @jkotalik @amcasey and others