Skip to content

Commit

Permalink
Sync up to latest code and cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
eerhardt committed Feb 22, 2020
1 parent d69b15a commit 37bdb46
Show file tree
Hide file tree
Showing 10 changed files with 13 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable enable
using System;
using System.Net.Sockets;
using System.Runtime.InteropServices;
Expand Down
4 changes: 2 additions & 2 deletions src/libraries/Common/src/System/Net/ContextAwareResult.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable enable
using System.Diagnostics.CodeAnalysis;
using System.Threading;

namespace System.Net
Expand Down Expand Up @@ -159,7 +159,7 @@ internal ExecutionContext? ContextCopy
{
NetEventSource.Fail(this, "Must lock (StartPostingAsyncOp()) { ... FinishPostingAsyncOp(); } when calling ContextCopy (unless it's only called after FinishPostingAsyncOp).");
}
lock (_lock) { }
lock (_lock!) { }
}

if (InternalPeekCompleted)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable

#nullable enable
using Microsoft.Win32.SafeHandles;

namespace System.Net
Expand All @@ -14,16 +14,16 @@ namespace System.Net
//
internal abstract class DebugSafeHandleMinusOneIsInvalid : SafeHandleMinusOneIsInvalid
{
private string _trace;
private string _trace = null!; // initialized by helper called from ctor

protected DebugSafeHandleMinusOneIsInvalid(bool ownsHandle) : base(ownsHandle)
{
_trace = "WARNING! GC-ed >>" + this.GetType().FullName + "<< (should be explicitly closed) \r\n";
Trace();
}

private void Trace()
{
_trace = "WARNING! GC-ed >>" + this.GetType().FullName + "<< (should be explicitly closed) \r\n";
if (NetEventSource.IsEnabled) NetEventSource.Info(this, "Creating SafeHandle");
#if TRACE_VERBOSE
string stacktrace = Environment.StackTrace;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#nullable enable
using System.Collections;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Diagnostics.Tracing;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
Expand Down Expand Up @@ -279,7 +278,6 @@ public static void Fail(object? thisOrContextObject, FormattableString formattab
/// <param name="message">The message to be logged.</param>
/// <param name="memberName">The calling member.</param>
[NonEvent]
[DoesNotReturn]
public static void Fail(object? thisOrContextObject, object message, [CallerMemberName] string? memberName = null)
{
// Don't call DebugValidateArg on args, as we expect Fail to be used in assert/failure situations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal DisconnectOverlappedAsyncResult(Socket socket, object? asyncState, Asyn
{
Socket socket = (Socket)AsyncObject;
socket.SetToDisconnected();
socket._remoteEndPoint = null!;//TODO:eerhardt
socket._remoteEndPoint = null;
}
return base.PostCompletion(numBytes);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ private void InternalConnectCallback(object? sender, SocketAsyncEventArgs args)
NetEventSource.Fail(null, "attemptSocket is null!");
}

bool pending = attemptSocket.ConnectAsync(args);
bool pending = attemptSocket!.ConnectAsync(args);
if (!pending)
{
InternalConnectCallback(null, args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@ public void Connect(string host, int port)
// No need to call ValidateForMultiConnect(), as the validation
// will be handled by the delegated Connect overloads.

IPAddress parsedAddress;
IPAddress? parsedAddress;
if (IPAddress.TryParse(host, out parsedAddress))
{
Connect(parsedAddress, port);
Expand Down Expand Up @@ -2089,7 +2089,7 @@ public IAsyncResult BeginConnect(string host, int port, AsyncCallback? requestCa
throw new SocketException((int)SocketError.IsConnected);
}

IPAddress parsedAddress;
IPAddress? parsedAddress;
if (IPAddress.TryParse(host, out parsedAddress))
{
IAsyncResult r = BeginConnect(parsedAddress, port, requestCallback, state);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ private static void AllocateToken(SocketAsyncContext context, out SocketAsyncEng
// We minimize the number of engines on applications that have a low number of concurrent sockets.
for (int i = 0; i < s_allocateFromEngine; i++)
{
SocketAsyncEngine? previousEngine = s_currentEngines[i];
var previousEngine = s_currentEngines[i];
if (previousEngine == null || previousEngine.HasLowNumberOfSockets)
{
s_allocateFromEngine = i;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ internal void CancelConnectAsync()
{
NetEventSource.Fail(this, "CurrentSocket and MultipleConnect both null!");
}
_currentSocket.Dispose();
_currentSocket!.Dispose();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ public static TcpListener Create(int port)
}

private void SetIPProtectionLevel(bool allowed)
=> _serverSocket.SetIPProtectionLevel(allowed ? IPProtectionLevel.Unrestricted : IPProtectionLevel.EdgeRestricted);
=> _serverSocket!.SetIPProtectionLevel(allowed ? IPProtectionLevel.Unrestricted : IPProtectionLevel.EdgeRestricted);

private void CreateNewSocketIfNeeded()
{
Expand Down

0 comments on commit 37bdb46

Please sign in to comment.