Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions api_list.include.md
Original file line number Diff line number Diff line change
Expand Up @@ -1112,6 +1112,9 @@
#### UdpClient

* `ValueTask<UdpReceiveResult> ReceiveAsync(CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.net.sockets.udpclient.receiveasync?view=net-11.0#system-net-sockets-udpclient-receiveasync(system-threading-cancellationtoken))
* `int Send(ReadOnlySpan<byte>, IPEndPoint?)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.net.sockets.udpclient.send?view=net-11.0#system-net-sockets-udpclient-send(system-readonlyspan((system-byte))-system-net-ipendpoint))
* `int Send(ReadOnlySpan<byte>, string?, int)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.net.sockets.udpclient.send?view=net-11.0#system-net-sockets-udpclient-send(system-readonlyspan((system-byte))-system-string-system-int32))
* `int Send(ReadOnlySpan<byte>)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.net.sockets.udpclient.send?view=net-11.0#system-net-sockets-udpclient-send(system-readonlyspan((system-byte))))
* `ValueTask<int> SendAsync(ReadOnlyMemory<byte>, CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.net.sockets.udpclient.sendasync?view=net-11.0#system-net-sockets-udpclient-sendasync(system-readonlymemory((system-byte))-system-threading-cancellationtoken))
* `ValueTask<int> SendAsync(ReadOnlyMemory<byte>, IPEndPoint?, CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.net.sockets.udpclient.sendasync?view=net-11.0#system-net-sockets-udpclient-sendasync(system-readonlymemory((system-byte))-system-net-ipendpoint-system-threading-cancellationtoken))
* `ValueTask<int> SendAsync(ReadOnlyMemory<byte>, string?, int, CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.net.sockets.udpclient.sendasync?view=net-11.0#system-net-sockets-udpclient-sendasync(system-readonlymemory((system-byte))-system-string-system-int32-system-threading-cancellationtoken))
Expand Down
12 changes: 12 additions & 0 deletions src/Consume/Consume.cs
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,18 @@ async Task UdpClient_Methods()
}
#endif

#if FeatureMemory
void UdpClient_SyncMethods()
{
using var client = new UdpClient(0);
var data = new ReadOnlySpan<byte>([1, 2, 3]);
using var connectedClient = new UdpClient("localhost", 12345);
connectedClient.Send(data);
client.Send(data, new IPEndPoint(IPAddress.Loopback, 12345));
client.Send(data, "localhost", 12345);
}
#endif

void IDictionary_Methods()
{
IDictionary<int, int> idictionary = new Dictionary<int, int>();
Expand Down
78 changes: 77 additions & 1 deletion src/Polyfill/Polyfill_UdpClient.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
#if !NET6_0_OR_GREATER && FeatureValueTask
#if !NET6_0_OR_GREATER

namespace Polyfills;

using System;
// ReSharper disable RedundantUsingDirective
#if FeatureMemory
using System.Buffers;
#endif
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Threading.Tasks;
// ReSharper restore RedundantUsingDirective

static partial class Polyfill
{
#if FeatureValueTask

/// <summary>
/// Returns a UDP datagram asynchronously that was sent by a remote host.
/// </summary>
Expand Down Expand Up @@ -167,6 +174,75 @@ static async Task<int> SendWithCancellationAsync(
}
}

#endif

#endif

#if FeatureMemory

/// <summary>
/// Sends a UDP datagram to a remote host.
/// </summary>
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.net.sockets.udpclient.send?view=net-11.0#system-net-sockets-udpclient-send(system-readonlyspan((system-byte)))
public static int Send(
this UdpClient target,
ReadOnlySpan<byte> datagram)
{
var rented = ArrayPool<byte>.Shared.Rent(datagram.Length);
try
{
datagram.CopyTo(rented);
return target.Send(rented, datagram.Length);
}
finally
{
ArrayPool<byte>.Shared.Return(rented);
}
}

/// <summary>
/// Sends a UDP datagram to the host at the specified remote endpoint.
/// </summary>
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.net.sockets.udpclient.send?view=net-11.0#system-net-sockets-udpclient-send(system-readonlyspan((system-byte))-system-net-ipendpoint)
public static int Send(
this UdpClient target,
ReadOnlySpan<byte> datagram,
IPEndPoint? endPoint)
{
var rented = ArrayPool<byte>.Shared.Rent(datagram.Length);
try
{
datagram.CopyTo(rented);
return target.Send(rented, datagram.Length, endPoint);
}
finally
{
ArrayPool<byte>.Shared.Return(rented);
}
}

/// <summary>
/// Sends a UDP datagram to a specified port on a specified remote host.
/// </summary>
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.net.sockets.udpclient.send?view=net-11.0#system-net-sockets-udpclient-send(system-readonlyspan((system-byte))-system-string-system-int32)
public static int Send(
this UdpClient target,
ReadOnlySpan<byte> datagram,
string? hostname,
int port)
{
var rented = ArrayPool<byte>.Shared.Rent(datagram.Length);
try
{
datagram.CopyTo(rented);
return target.Send(rented, datagram.Length, hostname, port);
}
finally
{
ArrayPool<byte>.Shared.Return(rented);
}
}

#endif
}
#endif
66 changes: 64 additions & 2 deletions src/Split/net461/Polyfill_UdpClient.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
// <auto-generated />
#pragma warning disable
#if FeatureValueTask
namespace Polyfills;
using System;
#if FeatureMemory
using System.Buffers;
#endif
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Threading.Tasks;
static partial class Polyfill
{
#if FeatureValueTask
/// <summary>
/// Returns a UDP datagram asynchronously that was sent by a remote host.
/// </summary>
Expand Down Expand Up @@ -150,5 +153,64 @@ static async Task<int> SendWithCancellationAsync(
}
}
#endif
}
#endif
#if FeatureMemory
/// <summary>
/// Sends a UDP datagram to a remote host.
/// </summary>
public static int Send(
this UdpClient target,
ReadOnlySpan<byte> datagram)
{
var rented = ArrayPool<byte>.Shared.Rent(datagram.Length);
try
{
datagram.CopyTo(rented);
return target.Send(rented, datagram.Length);
}
finally
{
ArrayPool<byte>.Shared.Return(rented);
}
}
/// <summary>
/// Sends a UDP datagram to the host at the specified remote endpoint.
/// </summary>
public static int Send(
this UdpClient target,
ReadOnlySpan<byte> datagram,
IPEndPoint? endPoint)
{
var rented = ArrayPool<byte>.Shared.Rent(datagram.Length);
try
{
datagram.CopyTo(rented);
return target.Send(rented, datagram.Length, endPoint);
}
finally
{
ArrayPool<byte>.Shared.Return(rented);
}
}
/// <summary>
/// Sends a UDP datagram to a specified port on a specified remote host.
/// </summary>
public static int Send(
this UdpClient target,
ReadOnlySpan<byte> datagram,
string? hostname,
int port)
{
var rented = ArrayPool<byte>.Shared.Rent(datagram.Length);
try
{
datagram.CopyTo(rented);
return target.Send(rented, datagram.Length, hostname, port);
}
finally
{
ArrayPool<byte>.Shared.Return(rented);
}
}
#endif
}
66 changes: 64 additions & 2 deletions src/Split/net462/Polyfill_UdpClient.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
// <auto-generated />
#pragma warning disable
#if FeatureValueTask
namespace Polyfills;
using System;
#if FeatureMemory
using System.Buffers;
#endif
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Threading.Tasks;
static partial class Polyfill
{
#if FeatureValueTask
/// <summary>
/// Returns a UDP datagram asynchronously that was sent by a remote host.
/// </summary>
Expand Down Expand Up @@ -150,5 +153,64 @@ static async Task<int> SendWithCancellationAsync(
}
}
#endif
}
#endif
#if FeatureMemory
/// <summary>
/// Sends a UDP datagram to a remote host.
/// </summary>
public static int Send(
this UdpClient target,
ReadOnlySpan<byte> datagram)
{
var rented = ArrayPool<byte>.Shared.Rent(datagram.Length);
try
{
datagram.CopyTo(rented);
return target.Send(rented, datagram.Length);
}
finally
{
ArrayPool<byte>.Shared.Return(rented);
}
}
/// <summary>
/// Sends a UDP datagram to the host at the specified remote endpoint.
/// </summary>
public static int Send(
this UdpClient target,
ReadOnlySpan<byte> datagram,
IPEndPoint? endPoint)
{
var rented = ArrayPool<byte>.Shared.Rent(datagram.Length);
try
{
datagram.CopyTo(rented);
return target.Send(rented, datagram.Length, endPoint);
}
finally
{
ArrayPool<byte>.Shared.Return(rented);
}
}
/// <summary>
/// Sends a UDP datagram to a specified port on a specified remote host.
/// </summary>
public static int Send(
this UdpClient target,
ReadOnlySpan<byte> datagram,
string? hostname,
int port)
{
var rented = ArrayPool<byte>.Shared.Rent(datagram.Length);
try
{
datagram.CopyTo(rented);
return target.Send(rented, datagram.Length, hostname, port);
}
finally
{
ArrayPool<byte>.Shared.Return(rented);
}
}
#endif
}
66 changes: 64 additions & 2 deletions src/Split/net47/Polyfill_UdpClient.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
// <auto-generated />
#pragma warning disable
#if FeatureValueTask
namespace Polyfills;
using System;
#if FeatureMemory
using System.Buffers;
#endif
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Threading.Tasks;
static partial class Polyfill
{
#if FeatureValueTask
/// <summary>
/// Returns a UDP datagram asynchronously that was sent by a remote host.
/// </summary>
Expand Down Expand Up @@ -150,5 +153,64 @@ static async Task<int> SendWithCancellationAsync(
}
}
#endif
}
#endif
#if FeatureMemory
/// <summary>
/// Sends a UDP datagram to a remote host.
/// </summary>
public static int Send(
this UdpClient target,
ReadOnlySpan<byte> datagram)
{
var rented = ArrayPool<byte>.Shared.Rent(datagram.Length);
try
{
datagram.CopyTo(rented);
return target.Send(rented, datagram.Length);
}
finally
{
ArrayPool<byte>.Shared.Return(rented);
}
}
/// <summary>
/// Sends a UDP datagram to the host at the specified remote endpoint.
/// </summary>
public static int Send(
this UdpClient target,
ReadOnlySpan<byte> datagram,
IPEndPoint? endPoint)
{
var rented = ArrayPool<byte>.Shared.Rent(datagram.Length);
try
{
datagram.CopyTo(rented);
return target.Send(rented, datagram.Length, endPoint);
}
finally
{
ArrayPool<byte>.Shared.Return(rented);
}
}
/// <summary>
/// Sends a UDP datagram to a specified port on a specified remote host.
/// </summary>
public static int Send(
this UdpClient target,
ReadOnlySpan<byte> datagram,
string? hostname,
int port)
{
var rented = ArrayPool<byte>.Shared.Rent(datagram.Length);
try
{
datagram.CopyTo(rented);
return target.Send(rented, datagram.Length, hostname, port);
}
finally
{
ArrayPool<byte>.Shared.Return(rented);
}
}
#endif
}
Loading
Loading