diff --git a/src/libraries/Common/src/Interop/Windows/WinSock/Interop.getsockopt.cs b/src/libraries/Common/src/Interop/Windows/WinSock/Interop.getsockopt.cs index 1e9334800edcb..77d7420a6c57e 100644 --- a/src/libraries/Common/src/Interop/Windows/WinSock/Interop.getsockopt.cs +++ b/src/libraries/Common/src/Interop/Windows/WinSock/Interop.getsockopt.cs @@ -22,7 +22,7 @@ internal static extern SocketError getsockopt( [In] SafeSocketHandle socketHandle, [In] SocketOptionLevel optionLevel, [In] SocketOptionName optionName, - [Out] byte[]? optionValue, + [Out] byte[] optionValue, [In, Out] ref int optionLength); [DllImport(Interop.Libraries.Ws2_32, SetLastError = true)] diff --git a/src/libraries/System.Net.Sockets/ref/System.Net.Sockets.cs b/src/libraries/System.Net.Sockets/ref/System.Net.Sockets.cs index a806974cea2e0..56e85e8e488db 100644 --- a/src/libraries/System.Net.Sockets/ref/System.Net.Sockets.cs +++ b/src/libraries/System.Net.Sockets/ref/System.Net.Sockets.cs @@ -235,8 +235,9 @@ public Socket(System.Net.Sockets.SocketType socketType, System.Net.Sockets.Proto public bool ExclusiveAddressUse { get { throw null; } set { } } public System.IntPtr Handle { get { throw null; } } public bool IsBound { get { throw null; } } - public System.Net.Sockets.LingerOption LingerState { get { throw null; } set { } } - public System.Net.EndPoint LocalEndPoint { get { throw null; } } + [System.Diagnostics.CodeAnalysis.DisallowNullAttribute] + public System.Net.Sockets.LingerOption? LingerState { get { throw null; } set { } } + public System.Net.EndPoint? LocalEndPoint { get { throw null; } } public bool MulticastLoopback { get { throw null; } set { } } public bool NoDelay { get { throw null; } set { } } public static bool OSSupportsIPv4 { get { throw null; } } @@ -245,7 +246,7 @@ public Socket(System.Net.Sockets.SocketType socketType, System.Net.Sockets.Proto public System.Net.Sockets.ProtocolType ProtocolType { get { throw null; } } public int ReceiveBufferSize { get { throw null; } set { } } public int ReceiveTimeout { get { throw null; } set { } } - public System.Net.EndPoint RemoteEndPoint { get { throw null; } } + public System.Net.EndPoint? RemoteEndPoint { get { throw null; } } public System.Net.Sockets.SafeSocketHandle SafeHandle { get { throw null; } } public int SendBufferSize { get { throw null; } set { } } public int SendTimeout { get { throw null; } set { } } @@ -258,27 +259,27 @@ public Socket(System.Net.Sockets.SocketType socketType, System.Net.Sockets.Proto public bool UseOnlyOverlappedIO { get { throw null; } set { } } public System.Net.Sockets.Socket Accept() { throw null; } public bool AcceptAsync(System.Net.Sockets.SocketAsyncEventArgs e) { throw null; } - public System.IAsyncResult BeginAccept(System.AsyncCallback callback, object state) { throw null; } - public System.IAsyncResult BeginAccept(int receiveSize, System.AsyncCallback callback, object state) { throw null; } - public System.IAsyncResult BeginAccept(System.Net.Sockets.Socket acceptSocket, int receiveSize, System.AsyncCallback callback, object state) { throw null; } - public System.IAsyncResult BeginConnect(System.Net.EndPoint remoteEP, System.AsyncCallback callback, object state) { throw null; } - public System.IAsyncResult BeginConnect(System.Net.IPAddress address, int port, System.AsyncCallback requestCallback, object state) { throw null; } - public System.IAsyncResult BeginConnect(System.Net.IPAddress[] addresses, int port, System.AsyncCallback requestCallback, object state) { throw null; } - public System.IAsyncResult BeginConnect(string host, int port, System.AsyncCallback requestCallback, object state) { throw null; } - public System.IAsyncResult BeginDisconnect(bool reuseSocket, System.AsyncCallback callback, object state) { throw null; } - public System.IAsyncResult BeginReceive(byte[] buffer, int offset, int size, System.Net.Sockets.SocketFlags socketFlags, System.AsyncCallback callback, object state) { throw null; } - public System.IAsyncResult BeginReceive(byte[] buffer, int offset, int size, System.Net.Sockets.SocketFlags socketFlags, out System.Net.Sockets.SocketError errorCode, System.AsyncCallback callback, object state) { throw null; } - public System.IAsyncResult BeginReceive(System.Collections.Generic.IList> buffers, System.Net.Sockets.SocketFlags socketFlags, System.AsyncCallback callback, object state) { throw null; } - public System.IAsyncResult BeginReceive(System.Collections.Generic.IList> buffers, System.Net.Sockets.SocketFlags socketFlags, out System.Net.Sockets.SocketError errorCode, System.AsyncCallback callback, object state) { throw null; } - public System.IAsyncResult BeginReceiveFrom(byte[] buffer, int offset, int size, System.Net.Sockets.SocketFlags socketFlags, ref System.Net.EndPoint remoteEP, System.AsyncCallback callback, object state) { throw null; } - public System.IAsyncResult BeginReceiveMessageFrom(byte[] buffer, int offset, int size, System.Net.Sockets.SocketFlags socketFlags, ref System.Net.EndPoint remoteEP, System.AsyncCallback callback, object state) { throw null; } - public System.IAsyncResult BeginSend(byte[] buffer, int offset, int size, System.Net.Sockets.SocketFlags socketFlags, System.AsyncCallback callback, object state) { throw null; } - public System.IAsyncResult BeginSend(byte[] buffer, int offset, int size, System.Net.Sockets.SocketFlags socketFlags, out System.Net.Sockets.SocketError errorCode, System.AsyncCallback callback, object state) { throw null; } - public System.IAsyncResult BeginSend(System.Collections.Generic.IList> buffers, System.Net.Sockets.SocketFlags socketFlags, System.AsyncCallback callback, object state) { throw null; } - public System.IAsyncResult BeginSend(System.Collections.Generic.IList> buffers, System.Net.Sockets.SocketFlags socketFlags, out System.Net.Sockets.SocketError errorCode, System.AsyncCallback callback, object state) { throw null; } - public System.IAsyncResult BeginSendFile(string fileName, System.AsyncCallback callback, object state) { throw null; } - public System.IAsyncResult BeginSendFile(string fileName, byte[] preBuffer, byte[] postBuffer, System.Net.Sockets.TransmitFileOptions flags, System.AsyncCallback callback, object state) { throw null; } - public System.IAsyncResult BeginSendTo(byte[] buffer, int offset, int size, System.Net.Sockets.SocketFlags socketFlags, System.Net.EndPoint remoteEP, System.AsyncCallback callback, object state) { throw null; } + public System.IAsyncResult BeginAccept(System.AsyncCallback? callback, object? state) { throw null; } + public System.IAsyncResult BeginAccept(int receiveSize, System.AsyncCallback? callback, object? state) { throw null; } + public System.IAsyncResult BeginAccept(System.Net.Sockets.Socket? acceptSocket, int receiveSize, System.AsyncCallback? callback, object? state) { throw null; } + public System.IAsyncResult BeginConnect(System.Net.EndPoint remoteEP, System.AsyncCallback? callback, object? state) { throw null; } + public System.IAsyncResult BeginConnect(System.Net.IPAddress address, int port, System.AsyncCallback? requestCallback, object? state) { throw null; } + public System.IAsyncResult BeginConnect(System.Net.IPAddress[] addresses, int port, System.AsyncCallback? requestCallback, object? state) { throw null; } + public System.IAsyncResult BeginConnect(string host, int port, System.AsyncCallback? requestCallback, object? state) { throw null; } + public System.IAsyncResult BeginDisconnect(bool reuseSocket, System.AsyncCallback? callback, object? state) { throw null; } + public System.IAsyncResult BeginReceive(byte[] buffer, int offset, int size, System.Net.Sockets.SocketFlags socketFlags, System.AsyncCallback? callback, object? state) { throw null; } + public System.IAsyncResult? BeginReceive(byte[] buffer, int offset, int size, System.Net.Sockets.SocketFlags socketFlags, out System.Net.Sockets.SocketError errorCode, System.AsyncCallback? callback, object? state) { throw null; } + public System.IAsyncResult BeginReceive(System.Collections.Generic.IList> buffers, System.Net.Sockets.SocketFlags socketFlags, System.AsyncCallback? callback, object? state) { throw null; } + public System.IAsyncResult? BeginReceive(System.Collections.Generic.IList> buffers, System.Net.Sockets.SocketFlags socketFlags, out System.Net.Sockets.SocketError errorCode, System.AsyncCallback? callback, object? state) { throw null; } + public System.IAsyncResult BeginReceiveFrom(byte[] buffer, int offset, int size, System.Net.Sockets.SocketFlags socketFlags, ref System.Net.EndPoint remoteEP, System.AsyncCallback? callback, object? state) { throw null; } + public System.IAsyncResult BeginReceiveMessageFrom(byte[] buffer, int offset, int size, System.Net.Sockets.SocketFlags socketFlags, ref System.Net.EndPoint remoteEP, System.AsyncCallback? callback, object? state) { throw null; } + public System.IAsyncResult BeginSend(byte[] buffer, int offset, int size, System.Net.Sockets.SocketFlags socketFlags, System.AsyncCallback? callback, object? state) { throw null; } + public System.IAsyncResult? BeginSend(byte[] buffer, int offset, int size, System.Net.Sockets.SocketFlags socketFlags, out System.Net.Sockets.SocketError errorCode, System.AsyncCallback? callback, object? state) { throw null; } + public System.IAsyncResult BeginSend(System.Collections.Generic.IList> buffers, System.Net.Sockets.SocketFlags socketFlags, System.AsyncCallback? callback, object? state) { throw null; } + public System.IAsyncResult? BeginSend(System.Collections.Generic.IList> buffers, System.Net.Sockets.SocketFlags socketFlags, out System.Net.Sockets.SocketError errorCode, System.AsyncCallback? callback, object? state) { throw null; } + public System.IAsyncResult BeginSendFile(string? fileName, System.AsyncCallback? callback, object? state) { throw null; } + public System.IAsyncResult BeginSendFile(string? fileName, byte[]? preBuffer, byte[]? postBuffer, System.Net.Sockets.TransmitFileOptions flags, System.AsyncCallback? callback, object? state) { throw null; } + public System.IAsyncResult BeginSendTo(byte[] buffer, int offset, int size, System.Net.Sockets.SocketFlags socketFlags, System.Net.EndPoint remoteEP, System.AsyncCallback? callback, object? state) { throw null; } public void Bind(System.Net.EndPoint localEP) { } public static void CancelConnectAsync(System.Net.Sockets.SocketAsyncEventArgs e) { } public void Close() { } @@ -294,8 +295,8 @@ public void Disconnect(bool reuseSocket) { } public void Dispose() { } protected virtual void Dispose(bool disposing) { } public System.Net.Sockets.SocketInformation DuplicateAndClose(int targetProcessId) { throw null; } - public System.Net.Sockets.Socket EndAccept(out byte[] buffer, System.IAsyncResult asyncResult) { throw null; } - public System.Net.Sockets.Socket EndAccept(out byte[] buffer, out int bytesTransferred, System.IAsyncResult asyncResult) { throw null; } + public System.Net.Sockets.Socket EndAccept(out byte[]? buffer, System.IAsyncResult asyncResult) { throw null; } + public System.Net.Sockets.Socket EndAccept(out byte[]? buffer, out int bytesTransferred, System.IAsyncResult asyncResult) { throw null; } public System.Net.Sockets.Socket EndAccept(System.IAsyncResult asyncResult) { throw null; } public void EndConnect(System.IAsyncResult asyncResult) { } public void EndDisconnect(System.IAsyncResult asyncResult) { } @@ -308,11 +309,11 @@ public void EndDisconnect(System.IAsyncResult asyncResult) { } public void EndSendFile(System.IAsyncResult asyncResult) { } public int EndSendTo(System.IAsyncResult asyncResult) { throw null; } ~Socket() { } - public object GetSocketOption(System.Net.Sockets.SocketOptionLevel optionLevel, System.Net.Sockets.SocketOptionName optionName) { throw null; } + public object? GetSocketOption(System.Net.Sockets.SocketOptionLevel optionLevel, System.Net.Sockets.SocketOptionName optionName) { throw null; } public void GetSocketOption(System.Net.Sockets.SocketOptionLevel optionLevel, System.Net.Sockets.SocketOptionName optionName, byte[] optionValue) { } public byte[] GetSocketOption(System.Net.Sockets.SocketOptionLevel optionLevel, System.Net.Sockets.SocketOptionName optionName, int optionLength) { throw null; } - public int IOControl(int ioControlCode, byte[] optionInValue, byte[] optionOutValue) { throw null; } - public int IOControl(System.Net.Sockets.IOControlCode ioControlCode, byte[] optionInValue, byte[] optionOutValue) { throw null; } + public int IOControl(int ioControlCode, byte[]? optionInValue, byte[]? optionOutValue) { throw null; } + public int IOControl(System.Net.Sockets.IOControlCode ioControlCode, byte[]? optionInValue, byte[]? optionOutValue) { throw null; } public void Listen() { } public void Listen(int backlog) { } public bool Poll(int microSeconds, System.Net.Sockets.SelectMode mode) { throw null; } @@ -335,7 +336,7 @@ public void Listen(int backlog) { } public bool ReceiveFromAsync(System.Net.Sockets.SocketAsyncEventArgs e) { throw null; } public int ReceiveMessageFrom(byte[] buffer, int offset, int size, ref System.Net.Sockets.SocketFlags socketFlags, ref System.Net.EndPoint remoteEP, out System.Net.Sockets.IPPacketInformation ipPacketInformation) { throw null; } public bool ReceiveMessageFromAsync(System.Net.Sockets.SocketAsyncEventArgs e) { throw null; } - public static void Select(System.Collections.IList checkRead, System.Collections.IList checkWrite, System.Collections.IList checkError, int microSeconds) { } + public static void Select(System.Collections.IList? checkRead, System.Collections.IList? checkWrite, System.Collections.IList? checkError, int microSeconds) { } public int Send(byte[] buffer) { throw null; } public int Send(byte[] buffer, int offset, int size, System.Net.Sockets.SocketFlags socketFlags) { throw null; } public int Send(byte[] buffer, int offset, int size, System.Net.Sockets.SocketFlags socketFlags, out System.Net.Sockets.SocketError errorCode) { throw null; } @@ -348,8 +349,8 @@ public static void Select(System.Collections.IList checkRead, System.Collections public int Send(System.ReadOnlySpan buffer, System.Net.Sockets.SocketFlags socketFlags) { throw null; } public int Send(System.ReadOnlySpan buffer, System.Net.Sockets.SocketFlags socketFlags, out System.Net.Sockets.SocketError errorCode) { throw null; } public bool SendAsync(System.Net.Sockets.SocketAsyncEventArgs e) { throw null; } - public void SendFile(string fileName) { } - public void SendFile(string fileName, byte[] preBuffer, byte[] postBuffer, System.Net.Sockets.TransmitFileOptions flags) { } + public void SendFile(string? fileName) { } + public void SendFile(string? fileName, byte[]? preBuffer, byte[]? postBuffer, System.Net.Sockets.TransmitFileOptions flags) { } public bool SendPacketsAsync(System.Net.Sockets.SocketAsyncEventArgs e) { throw null; } public int SendTo(byte[] buffer, int offset, int size, System.Net.Sockets.SocketFlags socketFlags, System.Net.EndPoint remoteEP) { throw null; } public int SendTo(byte[] buffer, int size, System.Net.Sockets.SocketFlags socketFlags, System.Net.EndPoint remoteEP) { throw null; } @@ -367,30 +368,30 @@ public partial class SocketAsyncEventArgs : System.EventArgs, System.IDisposable { public SocketAsyncEventArgs() { } public SocketAsyncEventArgs(bool unsafeSuppressExecutionContextFlow) { } - public System.Net.Sockets.Socket AcceptSocket { get { throw null; } set { } } - public byte[] Buffer { get { throw null; } } - public System.Collections.Generic.IList> BufferList { get { throw null; } set { } } + public System.Net.Sockets.Socket? AcceptSocket { get { throw null; } set { } } + public byte[]? Buffer { get { throw null; } } + public System.Collections.Generic.IList>? BufferList { get { throw null; } set { } } public int BytesTransferred { get { throw null; } } - public System.Exception ConnectByNameError { get { throw null; } } - public System.Net.Sockets.Socket ConnectSocket { get { throw null; } } + public System.Exception? ConnectByNameError { get { throw null; } } + public System.Net.Sockets.Socket? ConnectSocket { get { throw null; } } public int Count { get { throw null; } } public bool DisconnectReuseSocket { get { throw null; } set { } } public System.Net.Sockets.SocketAsyncOperation LastOperation { get { throw null; } } public System.Memory MemoryBuffer { get { throw null; } } public int Offset { get { throw null; } } public System.Net.Sockets.IPPacketInformation ReceiveMessageFromPacketInfo { get { throw null; } } - public System.Net.EndPoint RemoteEndPoint { get { throw null; } set { } } - public System.Net.Sockets.SendPacketsElement[] SendPacketsElements { get { throw null; } set { } } + public System.Net.EndPoint? RemoteEndPoint { get { throw null; } set { } } + public System.Net.Sockets.SendPacketsElement[]? SendPacketsElements { get { throw null; } set { } } public System.Net.Sockets.TransmitFileOptions SendPacketsFlags { get { throw null; } set { } } public int SendPacketsSendSize { get { throw null; } set { } } public System.Net.Sockets.SocketError SocketError { get { throw null; } set { } } public System.Net.Sockets.SocketFlags SocketFlags { get { throw null; } set { } } - public object UserToken { get { throw null; } set { } } - public event System.EventHandler Completed { add { } remove { } } + public object? UserToken { get { throw null; } set { } } + public event System.EventHandler? Completed { add { } remove { } } public void Dispose() { } ~SocketAsyncEventArgs() { } protected virtual void OnCompleted(System.Net.Sockets.SocketAsyncEventArgs e) { } - public void SetBuffer(byte[] buffer, int offset, int count) { } + public void SetBuffer(byte[]? buffer, int offset, int count) { } public void SetBuffer(int offset, int count) { } public void SetBuffer(System.Memory buffer) { } } @@ -516,7 +517,7 @@ public enum SocketShutdown public static partial class SocketTaskExtensions { public static System.Threading.Tasks.Task AcceptAsync(this System.Net.Sockets.Socket socket) { throw null; } - public static System.Threading.Tasks.Task AcceptAsync(this System.Net.Sockets.Socket socket, System.Net.Sockets.Socket acceptSocket) { throw null; } + public static System.Threading.Tasks.Task AcceptAsync(this System.Net.Sockets.Socket socket, System.Net.Sockets.Socket? acceptSocket) { throw null; } public static System.Threading.Tasks.Task ConnectAsync(this System.Net.Sockets.Socket socket, System.Net.EndPoint remoteEP) { throw null; } public static System.Threading.Tasks.Task ConnectAsync(this System.Net.Sockets.Socket socket, System.Net.IPAddress address, int port) { throw null; } public static System.Threading.Tasks.Task ConnectAsync(this System.Net.Sockets.Socket socket, System.Net.IPAddress[] addresses, int port) { throw null; } @@ -551,15 +552,16 @@ public TcpClient(string hostname, int port) { } public System.Net.Sockets.Socket Client { get { throw null; } set { } } public bool Connected { get { throw null; } } public bool ExclusiveAddressUse { get { throw null; } set { } } - public System.Net.Sockets.LingerOption LingerState { get { throw null; } set { } } + [System.Diagnostics.CodeAnalysis.DisallowNullAttribute] + public System.Net.Sockets.LingerOption? LingerState { get { throw null; } set { } } public bool NoDelay { get { throw null; } set { } } public int ReceiveBufferSize { get { throw null; } set { } } public int ReceiveTimeout { get { throw null; } set { } } public int SendBufferSize { get { throw null; } set { } } public int SendTimeout { get { throw null; } set { } } - public System.IAsyncResult BeginConnect(System.Net.IPAddress address, int port, System.AsyncCallback requestCallback, object state) { throw null; } - public System.IAsyncResult BeginConnect(System.Net.IPAddress[] addresses, int port, System.AsyncCallback requestCallback, object state) { throw null; } - public System.IAsyncResult BeginConnect(string host, int port, System.AsyncCallback requestCallback, object state) { throw null; } + public System.IAsyncResult BeginConnect(System.Net.IPAddress address, int port, System.AsyncCallback? requestCallback, object? state) { throw null; } + public System.IAsyncResult BeginConnect(System.Net.IPAddress[] addresses, int port, System.AsyncCallback? requestCallback, object? state) { throw null; } + public System.IAsyncResult BeginConnect(string host, int port, System.AsyncCallback? requestCallback, object? state) { throw null; } public void Close() { } public void Connect(System.Net.IPAddress address, int port) { } public void Connect(System.Net.IPAddress[] ipAddresses, int port) { } @@ -589,8 +591,8 @@ public TcpListener(System.Net.IPEndPoint localEP) { } public System.Net.Sockets.TcpClient AcceptTcpClient() { throw null; } public System.Threading.Tasks.Task AcceptTcpClientAsync() { throw null; } public void AllowNatTraversal(bool allowed) { } - public System.IAsyncResult BeginAcceptSocket(System.AsyncCallback callback, object state) { throw null; } - public System.IAsyncResult BeginAcceptTcpClient(System.AsyncCallback callback, object state) { throw null; } + public System.IAsyncResult BeginAcceptSocket(System.AsyncCallback? callback, object? state) { throw null; } + public System.IAsyncResult BeginAcceptTcpClient(System.AsyncCallback? callback, object? state) { throw null; } public static System.Net.Sockets.TcpListener Create(int port) { throw null; } public System.Net.Sockets.Socket EndAcceptSocket(System.IAsyncResult asyncResult) { throw null; } public System.Net.Sockets.TcpClient EndAcceptTcpClient(System.IAsyncResult asyncResult) { throw null; } @@ -626,10 +628,10 @@ public UdpClient(string hostname, int port) { } public bool MulticastLoopback { get { throw null; } set { } } public short Ttl { get { throw null; } set { } } public void AllowNatTraversal(bool allowed) { } - public System.IAsyncResult BeginReceive(System.AsyncCallback requestCallback, object state) { throw null; } - public System.IAsyncResult BeginSend(byte[] datagram, int bytes, System.AsyncCallback requestCallback, object state) { throw null; } - public System.IAsyncResult BeginSend(byte[] datagram, int bytes, System.Net.IPEndPoint endPoint, System.AsyncCallback requestCallback, object state) { throw null; } - public System.IAsyncResult BeginSend(byte[] datagram, int bytes, string hostname, int port, System.AsyncCallback requestCallback, object state) { throw null; } + public System.IAsyncResult BeginReceive(System.AsyncCallback? requestCallback, object? state) { throw null; } + public System.IAsyncResult BeginSend(byte[] datagram, int bytes, System.AsyncCallback? requestCallback, object? state) { throw null; } + public System.IAsyncResult BeginSend(byte[] datagram, int bytes, System.Net.IPEndPoint? endPoint, System.AsyncCallback? requestCallback, object? state) { throw null; } + public System.IAsyncResult BeginSend(byte[] datagram, int bytes, string? hostname, int port, System.AsyncCallback? requestCallback, object? state) { throw null; } public void Close() { } public void Connect(System.Net.IPAddress addr, int port) { } public void Connect(System.Net.IPEndPoint endPoint) { } @@ -644,14 +646,14 @@ public void JoinMulticastGroup(int ifindex, System.Net.IPAddress multicastAddr) public void JoinMulticastGroup(System.Net.IPAddress multicastAddr) { } public void JoinMulticastGroup(System.Net.IPAddress multicastAddr, int timeToLive) { } public void JoinMulticastGroup(System.Net.IPAddress multicastAddr, System.Net.IPAddress localAddress) { } - public byte[] Receive(ref System.Net.IPEndPoint remoteEP) { throw null; } + public byte[] Receive(ref System.Net.IPEndPoint? remoteEP) { throw null; } public System.Threading.Tasks.Task ReceiveAsync() { throw null; } public int Send(byte[] dgram, int bytes) { throw null; } - public int Send(byte[] dgram, int bytes, System.Net.IPEndPoint endPoint) { throw null; } - public int Send(byte[] dgram, int bytes, string hostname, int port) { throw null; } + public int Send(byte[] dgram, int bytes, System.Net.IPEndPoint? endPoint) { throw null; } + public int Send(byte[] dgram, int bytes, string? hostname, int port) { throw null; } public System.Threading.Tasks.Task SendAsync(byte[] datagram, int bytes) { throw null; } - public System.Threading.Tasks.Task SendAsync(byte[] datagram, int bytes, System.Net.IPEndPoint endPoint) { throw null; } - public System.Threading.Tasks.Task SendAsync(byte[] datagram, int bytes, string hostname, int port) { throw null; } + public System.Threading.Tasks.Task SendAsync(byte[] datagram, int bytes, System.Net.IPEndPoint? endPoint) { throw null; } + public System.Threading.Tasks.Task SendAsync(byte[] datagram, int bytes, string? hostname, int port) { throw null; } } public partial struct UdpReceiveResult : System.IEquatable { diff --git a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/IOControlKeepAlive.Windows.cs b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/IOControlKeepAlive.Windows.cs index b671284b4664a..178ff72cbe29d 100644 --- a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/IOControlKeepAlive.Windows.cs +++ b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/IOControlKeepAlive.Windows.cs @@ -23,7 +23,7 @@ internal sealed class IOControlKeepAlive public static bool IsNeeded => !s_supportsKeepAliveViaSocketOption; - public static SocketError Get(SafeSocketHandle handle, SocketOptionName optionName, byte[]? optionValueSeconds, ref int optionLength) + public static SocketError Get(SafeSocketHandle handle, SocketOptionName optionName, byte[] optionValueSeconds, ref int optionLength) { if (optionValueSeconds == null || !BitConverter.TryWriteBytes(optionValueSeconds.AsSpan(), Get(handle, optionName))) diff --git a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/Socket.Unix.cs b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/Socket.Unix.cs index 3bbb650c7d715..804b9d35343e3 100644 --- a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/Socket.Unix.cs +++ b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/Socket.Unix.cs @@ -138,7 +138,7 @@ private static void CheckTransmitFileOptions(TransmitFileOptions flags) } } - private void SendFileInternal(string fileName, byte[]? preBuffer, byte[]? postBuffer, TransmitFileOptions flags) + private void SendFileInternal(string? fileName, byte[]? preBuffer, byte[]? postBuffer, TransmitFileOptions flags) { CheckTransmitFileOptions(flags); @@ -219,7 +219,7 @@ private async Task SendFileInternalAsync(FileStream? fileStream, byte[]? preBuff } } - private IAsyncResult BeginSendFileInternal(string fileName, byte[]? preBuffer, byte[]? postBuffer, TransmitFileOptions flags, AsyncCallback? callback, object? state) + private IAsyncResult BeginSendFileInternal(string? fileName, byte[]? preBuffer, byte[]? postBuffer, TransmitFileOptions flags, AsyncCallback? callback, object? state) { CheckTransmitFileOptions(flags); diff --git a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/Socket.Windows.cs b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/Socket.Windows.cs index b469a8f54a04b..d6060321e5d27 100644 --- a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/Socket.Windows.cs +++ b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/Socket.Windows.cs @@ -333,7 +333,7 @@ private Socket GetOrCreateAcceptSocket(Socket? acceptSocket, bool checkDisconnec return acceptSocket; } - private void SendFileInternal(string fileName, byte[]? preBuffer, byte[]? postBuffer, TransmitFileOptions flags) + private void SendFileInternal(string? fileName, byte[]? preBuffer, byte[]? postBuffer, TransmitFileOptions flags) { // Open the file, if any FileStream? fileStream = OpenFile(fileName); @@ -363,7 +363,7 @@ private void SendFileInternal(string fileName, byte[]? preBuffer, byte[]? postBu } } - private IAsyncResult BeginSendFileInternal(string fileName, byte[]? preBuffer, byte[]? postBuffer, TransmitFileOptions flags, AsyncCallback? callback, object? state) + private IAsyncResult BeginSendFileInternal(string? fileName, byte[]? preBuffer, byte[]? postBuffer, TransmitFileOptions flags, AsyncCallback? callback, object? state) { FileStream? fileStream = OpenFile(fileName); diff --git a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/Socket.cs b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/Socket.cs index cab50e3235cec..35d7cd0e0dd2e 100644 --- a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/Socket.cs +++ b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/Socket.cs @@ -1217,12 +1217,12 @@ public int Send(ReadOnlySpan buffer, SocketFlags socketFlags, out SocketEr return bytesTransferred; } - public void SendFile(string fileName) + public void SendFile(string? fileName) { SendFile(fileName, null, null, TransmitFileOptions.UseDefaultWorkerThread); } - public void SendFile(string fileName, byte[]? preBuffer, byte[]? postBuffer, TransmitFileOptions flags) + public void SendFile(string? fileName, byte[]? preBuffer, byte[]? postBuffer, TransmitFileOptions flags) { if (NetEventSource.IsEnabled) NetEventSource.Enter(this); @@ -1706,7 +1706,7 @@ public int ReceiveFrom(byte[] buffer, ref EndPoint remoteEP) return ReceiveFrom(buffer, 0, buffer != null ? buffer.Length : 0, SocketFlags.None, ref remoteEP); } - public int IOControl(int ioControlCode, byte[] optionInValue, byte[] optionOutValue) + public int IOControl(int ioControlCode, byte[]? optionInValue, byte[]? optionOutValue) { ThrowIfDisposed(); @@ -1729,7 +1729,7 @@ public int IOControl(int ioControlCode, byte[] optionInValue, byte[] optionOutVa return realOptionLength; } - public int IOControl(IOControlCode ioControlCode, byte[] optionInValue, byte[] optionOutValue) + public int IOControl(IOControlCode ioControlCode, byte[]? optionInValue, byte[]? optionOutValue) { return IOControl(unchecked((int)ioControlCode), optionInValue, optionOutValue); } @@ -1856,7 +1856,7 @@ public void SetSocketOption(SocketOptionLevel optionLevel, SocketOptionName opti return optionValue; } - public void GetSocketOption(SocketOptionLevel optionLevel, SocketOptionName optionName, byte[]? optionValue) + public void GetSocketOption(SocketOptionLevel optionLevel, SocketOptionName optionName, byte[] optionValue) { ThrowIfDisposed(); @@ -1867,7 +1867,7 @@ public void GetSocketOption(SocketOptionLevel optionLevel, SocketOptionName opti _handle, optionLevel, optionName, - optionValue, + optionValue!, ref optionLength); if (NetEventSource.IsEnabled) NetEventSource.Info(this, $"Interop.Winsock.getsockopt returns errorCode:{errorCode}"); @@ -2459,7 +2459,7 @@ private SocketError DoBeginSend(byte[] buffer, int offset, int size, SocketFlags return errorCode; } - public IAsyncResult BeginSend(IList> buffers, SocketFlags socketFlags, AsyncCallback callback, object state) + public IAsyncResult BeginSend(IList> buffers, SocketFlags socketFlags, AsyncCallback? callback, object? state) { SocketError errorCode; IAsyncResult? result = BeginSend(buffers, socketFlags, out errorCode, callback, state); @@ -2470,7 +2470,7 @@ public IAsyncResult BeginSend(IList> buffers, SocketFlags soc return result!; } - public IAsyncResult? BeginSend(IList> buffers, SocketFlags socketFlags, out SocketError errorCode, AsyncCallback callback, object state) + public IAsyncResult? BeginSend(IList> buffers, SocketFlags socketFlags, out SocketError errorCode, AsyncCallback? callback, object? state) { if (NetEventSource.IsEnabled) NetEventSource.Enter(this); ThrowIfDisposed(); @@ -2592,12 +2592,12 @@ public int EndSend(IAsyncResult asyncResult, out SocketError errorCode) return bytesTransferred; } - public IAsyncResult BeginSendFile(string fileName, AsyncCallback callback, object state) + public IAsyncResult BeginSendFile(string? fileName, AsyncCallback? callback, object? state) { return BeginSendFile(fileName, null, null, TransmitFileOptions.UseDefaultWorkerThread, callback, state); } - public IAsyncResult BeginSendFile(string fileName, byte[]? preBuffer, byte[]? postBuffer, TransmitFileOptions flags, AsyncCallback? callback, object? state) + public IAsyncResult BeginSendFile(string? fileName, byte[]? preBuffer, byte[]? postBuffer, TransmitFileOptions flags, AsyncCallback? callback, object? state) { if (NetEventSource.IsEnabled) NetEventSource.Enter(this); @@ -3040,7 +3040,7 @@ public int EndReceive(IAsyncResult asyncResult, out SocketError errorCode) return bytesTransferred; } - public IAsyncResult BeginReceiveMessageFrom(byte[] buffer, int offset, int size, SocketFlags socketFlags, ref EndPoint remoteEP, AsyncCallback callback, object state) + public IAsyncResult BeginReceiveMessageFrom(byte[] buffer, int offset, int size, SocketFlags socketFlags, ref EndPoint remoteEP, AsyncCallback? callback, object? state) { if (NetEventSource.IsEnabled) { @@ -3445,7 +3445,7 @@ public int EndReceiveFrom(IAsyncResult asyncResult, ref EndPoint endPoint) // Return Value: // // IAsyncResult - Async result used to retrieve resultant new socket - public IAsyncResult BeginAccept(AsyncCallback callback, object state) + public IAsyncResult BeginAccept(AsyncCallback? callback, object? state) { if (!_isDisconnected) { @@ -3459,13 +3459,13 @@ public IAsyncResult BeginAccept(AsyncCallback callback, object state) return null; // unreachable } - public IAsyncResult BeginAccept(int receiveSize, AsyncCallback callback, object state) + public IAsyncResult BeginAccept(int receiveSize, AsyncCallback? callback, object? state) { return BeginAccept(null, receiveSize, callback, state); } // This is the truly async version that uses AcceptEx. - public IAsyncResult BeginAccept(Socket? acceptSocket, int receiveSize, AsyncCallback callback, object state) + public IAsyncResult BeginAccept(Socket? acceptSocket, int receiveSize, AsyncCallback? callback, object? state) { if (NetEventSource.IsEnabled) NetEventSource.Enter(this); ThrowIfDisposed(); @@ -3865,6 +3865,11 @@ public bool DisconnectAsync(SocketAsyncEventArgs e) // Throw if socket disposed ThrowIfDisposed(); + if (e == null) + { + throw new ArgumentNullException(nameof(e)); + } + // Prepare for and make the native call. e.StartOperationCommon(this, SocketAsyncOperation.Disconnect); SocketError socketError = SocketError.Success; @@ -5023,7 +5028,7 @@ private void ValidateBlockingMode() partial void ValidateForMultiConnect(bool isMultiEndpoint); // Helper for SendFile implementations - private static FileStream? OpenFile(string name) => string.IsNullOrEmpty(name) ? null : File.OpenRead(name); + private static FileStream? OpenFile(string? name) => string.IsNullOrEmpty(name) ? null : File.OpenRead(name); private void UpdateReceiveSocketErrorForDisposed(ref SocketError socketError, int bytesTransferred) { diff --git a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketAsyncEventArgs.cs b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketAsyncEventArgs.cs index 99bbb5ac3525b..9a38815d8b15b 100644 --- a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketAsyncEventArgs.cs +++ b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketAsyncEventArgs.cs @@ -318,7 +318,7 @@ internal void CopyBufferFrom(SocketAsyncEventArgs source) } } - public void SetBuffer(byte[] buffer, int offset, int count) + public void SetBuffer(byte[]? buffer, int offset, int count) { StartConfiguring(); try diff --git a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketPal.Unix.cs b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketPal.Unix.cs index 6ecf6e0cd6a98..59626a56d999b 100644 --- a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketPal.Unix.cs +++ b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketPal.Unix.cs @@ -1098,7 +1098,7 @@ public static SocketError ReceiveFrom(SafeSocketHandle handle, byte[] buffer, in return completed ? errorCode : SocketError.WouldBlock; } - public static SocketError WindowsIoctl(SafeSocketHandle handle, int ioControlCode, byte[] optionInValue, byte[] optionOutValue, out int optionLength) + public static SocketError WindowsIoctl(SafeSocketHandle handle, int ioControlCode, byte[]? optionInValue, byte[]? optionOutValue, out int optionLength) { // Three codes are called out in the Winsock IOCTLs documentation as "The following Unix IOCTL codes (commands) are supported." They are // also the three codes available for use with ioctlsocket on Windows. Developers should be discouraged from using Socket.IOControl in @@ -1316,7 +1316,7 @@ public static unsafe SocketError GetSockOpt(SafeSocketHandle handle, SocketOptio return err == Interop.Error.SUCCESS ? SocketError.Success : GetSocketErrorForErrorCode(err); } - public static unsafe SocketError GetSockOpt(SafeSocketHandle handle, SocketOptionLevel optionLevel, SocketOptionName optionName, byte[]? optionValue, ref int optionLength) + public static unsafe SocketError GetSockOpt(SafeSocketHandle handle, SocketOptionLevel optionLevel, SocketOptionName optionName, byte[] optionValue, ref int optionLength) { int optLen = optionLength; diff --git a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketPal.Windows.cs b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketPal.Windows.cs index 9871f1a62a7dd..8eab7ef2c9b9a 100644 --- a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketPal.Windows.cs +++ b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketPal.Windows.cs @@ -716,7 +716,7 @@ public static SocketError GetSockOpt(SafeSocketHandle handle, SocketOptionLevel return errorCode == SocketError.SocketError ? GetLastSocketError() : SocketError.Success; } - public static SocketError GetSockOpt(SafeSocketHandle handle, SocketOptionLevel optionLevel, SocketOptionName optionName, byte[]? optionValue, ref int optionLength) + public static SocketError GetSockOpt(SafeSocketHandle handle, SocketOptionLevel optionLevel, SocketOptionName optionName, byte[] optionValue, ref int optionLength) { if (optionLevel == SocketOptionLevel.Tcp && (optionName == SocketOptionName.TcpKeepAliveTime || optionName == SocketOptionName.TcpKeepAliveInterval) && diff --git a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/TCPListener.cs b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/TCPListener.cs index 80bb22935143e..a16e8f1033d40 100644 --- a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/TCPListener.cs +++ b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/TCPListener.cs @@ -224,7 +224,7 @@ public TcpClient AcceptTcpClient() return returnValue; } - public IAsyncResult BeginAcceptSocket(AsyncCallback callback, object state) + public IAsyncResult BeginAcceptSocket(AsyncCallback? callback, object? state) { if (NetEventSource.IsEnabled) NetEventSource.Enter(this); @@ -262,7 +262,7 @@ public Socket EndAcceptSocket(IAsyncResult asyncResult) return socket; } - public IAsyncResult BeginAcceptTcpClient(AsyncCallback callback, object state) + public IAsyncResult BeginAcceptTcpClient(AsyncCallback? callback, object? state) { if (NetEventSource.IsEnabled) NetEventSource.Enter(this);