Skip to content

Commit

Permalink
Annotate all public methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
eerhardt committed Feb 22, 2020
1 parent b9f7936 commit d69b15a
Show file tree
Hide file tree
Showing 10 changed files with 92 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
118 changes: 60 additions & 58 deletions src/libraries/System.Net.Sockets/ref/System.Net.Sockets.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down
35 changes: 20 additions & 15 deletions src/libraries/System.Net.Sockets/src/System/Net/Sockets/Socket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1217,12 +1217,12 @@ public int Send(ReadOnlySpan<byte> 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);

Expand Down Expand Up @@ -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();

Expand All @@ -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);
}
Expand Down Expand Up @@ -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();

Expand All @@ -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}");
Expand Down Expand Up @@ -2459,7 +2459,7 @@ private SocketError DoBeginSend(byte[] buffer, int offset, int size, SocketFlags
return errorCode;
}

public IAsyncResult BeginSend(IList<ArraySegment<byte>> buffers, SocketFlags socketFlags, AsyncCallback callback, object state)
public IAsyncResult BeginSend(IList<ArraySegment<byte>> buffers, SocketFlags socketFlags, AsyncCallback? callback, object? state)
{
SocketError errorCode;
IAsyncResult? result = BeginSend(buffers, socketFlags, out errorCode, callback, state);
Expand All @@ -2470,7 +2470,7 @@ public IAsyncResult BeginSend(IList<ArraySegment<byte>> buffers, SocketFlags soc
return result!;
}

public IAsyncResult? BeginSend(IList<ArraySegment<byte>> buffers, SocketFlags socketFlags, out SocketError errorCode, AsyncCallback callback, object state)
public IAsyncResult? BeginSend(IList<ArraySegment<byte>> buffers, SocketFlags socketFlags, out SocketError errorCode, AsyncCallback? callback, object? state)
{
if (NetEventSource.IsEnabled) NetEventSource.Enter(this);
ThrowIfDisposed();
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand All @@ -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();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit d69b15a

Please sign in to comment.