-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Unified to throw NotSupportedException when SendFile() for connectionless sockets #87108
Changes from 1 commit
cb8c786
aaf4917
a171986
7bd5d7c
3954c40
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1254,6 +1254,11 @@ public void SendFile(string? fileName, byte[]? preBuffer, byte[]? postBuffer, Tr | |
/// <exception cref="SocketException">An error occurred when attempting to access the socket.</exception> | ||
public void SendFile(string? fileName, ReadOnlySpan<byte> preBuffer, ReadOnlySpan<byte> postBuffer, TransmitFileOptions flags) | ||
{ | ||
if (_protocolType == ProtocolType.Udp) | ||
{ | ||
throw new NotSupportedException(SR.net_notconnected); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The async variant checks for |
||
|
||
ThrowIfDisposed(); | ||
|
||
if (!Connected) | ||
|
@@ -2333,6 +2338,11 @@ public IAsyncResult BeginSendFile(string? fileName, AsyncCallback? callback, obj | |
|
||
public IAsyncResult BeginSendFile(string? fileName, byte[]? preBuffer, byte[]? postBuffer, TransmitFileOptions flags, AsyncCallback? callback, object? state) | ||
{ | ||
if (_protocolType == ProtocolType.Udp) | ||
{ | ||
throw new NotSupportedException(SR.net_notconnected); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Given that |
||
|
||
ThrowIfDisposed(); | ||
|
||
if (!Connected) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,16 +77,14 @@ public async Task UdpConnection_ThrowsException(bool usePreAndPostbufferOverload | |
|
||
client.Connect(listener.LocalEndPoint); | ||
|
||
SocketException ex; | ||
if (usePreAndPostbufferOverload) | ||
{ | ||
ex = await Assert.ThrowsAsync<SocketException>(() => SendFileAsync(client, tempFile.Path, Array.Empty<byte>(), Array.Empty<byte>(), TransmitFileOptions.UseDefaultWorkerThread)); | ||
await Assert.ThrowsAsync<NotSupportedException>(() => SendFileAsync(client, tempFile.Path, Array.Empty<byte>(), Array.Empty<byte>(), TransmitFileOptions.UseDefaultWorkerThread)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test case should not be |
||
} | ||
else | ||
{ | ||
ex = await Assert.ThrowsAsync<SocketException>(() => SendFileAsync(client, tempFile.Path)); | ||
await Assert.ThrowsAsync<NotSupportedException>(() => SendFileAsync(client, tempFile.Path)); | ||
} | ||
Assert.Equal(SocketError.NotConnected, ex.SocketErrorCode); | ||
} | ||
|
||
public static IEnumerable<object[]> SendFile_MemberData() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't the check
if (!IsConnectionOriented)
do the job already? In #47472 I only tested the sync overload.