Skip to content

Commit 7ed741e

Browse files
authored
Replace ATP pattern with async/await in SmtpClient (part 2) (dotnet#115722)
* Async/await in SmtpClient * Dead code removal * Remove unused code * Improve cancellation support * Code review feedback * Code review feedback
1 parent 4cb08fc commit 7ed741e

File tree

15 files changed

+388
-1830
lines changed

15 files changed

+388
-1830
lines changed

src/libraries/System.Net.Mail/src/System/Net/Mail/ReadWriteAdapter.cs renamed to src/libraries/Common/src/System/Net/ReadWriteAdapter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using System.Threading;
66
using System.Threading.Tasks;
77

8-
namespace System.Net.Mail
8+
namespace System.Net
99
{
1010
internal interface IReadWriteAdapter
1111
{

src/libraries/System.Net.Mail/src/System.Net.Mail.csproj

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
<Compile Include="System\Net\Mime\MediaTypeNames.cs" />
3333
<Compile Include="System\Net\Mime\MimeBasePart.cs" />
3434
<Compile Include="System\Net\Mime\SmtpDateTime.cs" />
35-
<Compile Include="System\Net\Mime\MultiAsyncResult.cs" />
3635
<Compile Include="System\Net\Mime\ByteEncoder.cs" />
3736
<Compile Include="System\Net\Mime\Base64Encoder.cs" />
3837
<Compile Include="System\Net\Mime\IByteEncoder.cs" />
@@ -47,7 +46,6 @@
4746
<Compile Include="System\Net\Mail\Attachment.cs" />
4847
<Compile Include="System\Net\Mail\AttachmentCollection.cs" />
4948
<Compile Include="System\Net\BufferedReadStream.cs" />
50-
<Compile Include="System\Net\Mail\ReadWriteAdapter.cs" />
5149
<Compile Include="System\Net\Mail\LinkedResource.cs" />
5250
<Compile Include="System\Net\Mail\LinkedResourceCollection.cs" />
5351
<Compile Include="System\Net\Mail\DomainLiteralReader.cs" />
@@ -69,12 +67,12 @@
6967
<Compile Include="System\Net\Mail\SmtpFailedRecipientsException.cs" />
7068
<Compile Include="System\Net\Mail\SmtpStatusCode.cs" />
7169
<Compile Include="System\Net\DelegatedStream.cs" />
70+
<Compile Include="$(CommonPath)\System\Net\ReadWriteAdapter.cs"
71+
Link="Common\System\Net\ReadWriteAdapter.cs" />
7272
<Compile Include="$(CommonPath)System\Text\ValueStringBuilder.cs"
7373
Link="Common\System\Text\ValueStringBuilder.cs" />
7474
<Compile Include="$(CommonPath)DisableRuntimeMarshalling.cs"
7575
Link="Common\DisableRuntimeMarshalling.cs" />
76-
<Compile Include="$(CommonPath)System\Net\LazyAsyncResult.cs"
77-
Link="Common\System\Net\LazyAsyncResult.cs" />
7876
<Compile Include="$(CommonPath)System\Net\Logging\NetEventSource.Common.cs"
7977
Link="Common\System\Net\Logging\NetEventSource.Common.cs" />
8078
<Compile Include="$(CommonPath)System\Net\Logging\NetEventSource.Common.Associate.cs"
@@ -105,37 +103,12 @@
105103
<Compile Include="System\Net\Mail\SmtpNtlmAuthenticationModule.cs" />
106104
<Compile Include="System\Net\Mail\MailWriter.cs" />
107105
<Compile Include="System\Net\Mail\NetEventSource.Mail.cs" />
108-
<Compile Include="$(CommonPath)System\Net\ContextAwareResult.cs"
109-
Link="Common\System\Net\ContextAwareResult.cs" />
110-
<Compile Include="$(CommonPath)System\Net\DebugSafeHandleZeroOrMinusOneIsInvalid.cs"
111-
Link="Common\System\Net\DebugSafeHandleZeroOrMinusOneIsInvalid.cs" />
112-
<Compile Include="$(CommonPath)System\Net\DebugSafeHandle.cs"
113-
Link="Common\System\Net\DebugSafeHandle.cs" />
114-
<Compile Include="$(CommonPath)System\Net\InternalException.cs"
115-
Link="Common\System\Net\InternalException.cs" />
116-
<Compile Include="$(CommonPath)System\Net\ExceptionCheck.cs"
117-
Link="Common\System\Net\ExceptionCheck.cs" />
118-
<Compile Include="$(CommonPath)System\Collections\Generic\BidirectionalDictionary.cs"
119-
Link="Common\System\Collections\Generic\BidirectionalDictionary.cs" />
120106
<Compile Include="$(CommonPath)System\NotImplemented.cs"
121107
Link="Common\System\NotImplemented.cs" />
122108
</ItemGroup>
123109

124-
<!-- Unix specific files -->
125-
<ItemGroup Condition="'$(TargetPlatformIdentifier)' == 'unix'">
126-
<Compile Include="$(CommonPath)System\Net\ContextAwareResult.Unix.cs"
127-
Link="Common\System\Net\ContextAwareResult.Unix.cs" />
128-
</ItemGroup>
129-
130-
<!-- Windows specific files -->
131-
<ItemGroup Condition="'$(TargetPlatformIdentifier)' == 'windows'">
132-
<Compile Include="$(CommonPath)System\Net\ContextAwareResult.Windows.cs"
133-
Link="Common\System\Net\ContextAwareResult.Windows.cs" />
134-
</ItemGroup>
135110
<ItemGroup>
136-
<Reference Include="Microsoft.Win32.Primitives" />
137111
<Reference Include="System.Collections" />
138-
<Reference Include="System.Collections.NonGeneric" />
139112
<Reference Include="System.Collections.Specialized" />
140113
<Reference Include="System.ComponentModel.EventBasedAsync" />
141114
<Reference Include="System.Diagnostics.Tracing" />
@@ -147,9 +120,7 @@
147120
<Reference Include="System.Net.Sockets" />
148121
<Reference Include="System.Runtime" />
149122
<Reference Include="System.Runtime.InteropServices" />
150-
<Reference Include="System.Security.Claims" />
151123
<Reference Include="System.Security.Cryptography" />
152-
<Reference Include="System.Security.Principal.Windows" />
153124
<Reference Include="System.Threading" />
154125
</ItemGroup>
155126

src/libraries/System.Net.Mail/src/System/Net/Mail/MailMessage.cs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
using System;
55
using System.Collections.Specialized;
6-
using System.Diagnostics;
76
using System.Diagnostics.CodeAnalysis;
87
using System.IO;
98
using System.Net.Mime;
@@ -432,23 +431,6 @@ private void SetContent(bool allowUnicode)
432431
}
433432
}
434433

435-
internal void Send(BaseWriter writer, bool sendEnvelope, bool allowUnicode, CancellationToken cancellationToken = default)
436-
{
437-
Task task = SendAsync<SyncReadWriteAdapter>(writer, sendEnvelope, allowUnicode, cancellationToken);
438-
Debug.Assert(task.IsCompleted, "SendAsync should be completed synchronously.");
439-
task.GetAwaiter().GetResult();
440-
}
441-
442-
internal IAsyncResult BeginSend(BaseWriter writer, bool sendEnvelope, bool allowUnicode, AsyncCallback callback, object? state)
443-
{
444-
return TaskToAsyncResult.Begin(SendAsync<AsyncReadWriteAdapter>(writer, sendEnvelope, allowUnicode), callback, state);
445-
}
446-
447-
internal static void EndSend(IAsyncResult asyncResult)
448-
{
449-
TaskToAsyncResult.End(asyncResult);
450-
}
451-
452434
internal async Task SendAsync<TIOAdapter>(BaseWriter writer, bool sendEnvelope, bool allowUnicode, CancellationToken cancellationToken = default)
453435
where TIOAdapter : IReadWriteAdapter
454436
{

0 commit comments

Comments
 (0)