-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
AcceptAsync with existing Socket not implemented on Unix #1483
Comments
So is the idea to implement the equivalent of: runtime/src/libraries/System.Net.Sockets/src/System/Net/Sockets/Socket.Windows.cs Lines 110 to 130 in b5f5d71
in |
Today on Unix we just throw a PlatformNotSupportedException if a non-null accept Socket is supplied: runtime/src/libraries/System.Net.Sockets/src/System/Net/Sockets/Socket.Unix.cs Lines 149 to 159 in c09a25e
Instead, we would need to:
Or something along those lines. |
Ok. I'll have a go at implementing this, including tests. |
Thanks! |
Is this on the right track? private Socket? GetOrCreateAcceptSocket(Socket? acceptSocket, bool unused, string propertyName, out SafeSocketHandle? handle)
{
if (acceptSocket != null)
{
// Accept into new Socket
using var socket = new Socket(_addressFamily, _socketType, _protocolType);
// Copy fields to acceptSocket
acceptSocket._addressFamily = socket._addressFamily;
acceptSocket._cachedTaskEventArgs = socket._cachedTaskEventArgs;
acceptSocket._caches = socket._caches;
acceptSocket._closeTimeout = socket._closeTimeout;
acceptSocket._disposed = socket._disposed;
acceptSocket._handle = socket._handle;
acceptSocket._isConnected = socket._isConnected;
acceptSocket._isDisconnected = socket._isDisconnected;
acceptSocket._isListening = socket._isListening;
acceptSocket._lastReceiveHandle = socket._lastReceiveHandle;
acceptSocket._lastReceiveThread = socket._lastReceiveThread;
acceptSocket._lastReceiveTick = socket._lastReceiveTick;
acceptSocket._nonBlockingConnectInProgress = socket._nonBlockingConnectInProgress;
acceptSocket._nonBlockingConnectRightEndPoint = socket._nonBlockingConnectRightEndPoint;
acceptSocket._protocolType = socket._protocolType;
acceptSocket._receivingPacketInformation = socket._receivingPacketInformation;
acceptSocket._remoteEndPoint = socket._remoteEndPoint;
acceptSocket._rightEndPoint = socket._rightEndPoint;
acceptSocket._socketType = socket._socketType;
acceptSocket._willBlock = socket._willBlock;
acceptSocket._willBlockInternal = socket._willBlockInternal;
handle = acceptSocket._handle;
return acceptSocket;
}
handle = null;
return null;
} |
Yes and no. Yes, that's the kind of copying to be done. No, this isn't the right place to do it: it would need to be after the accept had already happened. You also need to be careful not to tear down the new socket when cleaning up the temporary one. |
I'm going to take a look at this issue @karelz |
We should fix the milestone right? |
Windows has built-in support for accepting into an existing socket, something not available on Unix. But we can approximate it in the .NET layer on Unix, e.g. by accepting into a new socket and transferring over the SafeCloseHandle and related state. This will allow the same APIs to be used cross-platform so that code running on Windows gets the intended benefits while not having to fork based on the OS.
The text was updated successfully, but these errors were encountered: