Imported Upstream version 6.4.0.137

Former-commit-id: 943baa9f16a098c33e129777827f3a9d20da00d6
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2019-07-26 19:53:28 +00:00
parent e9207cf623
commit ef583813eb
2712 changed files with 74169 additions and 40587 deletions

View File

@ -40,6 +40,7 @@ using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using System.Reflection;
using System.IO;
using System.Net.Configuration;
@ -972,7 +973,32 @@ namespace System.Net.Sockets
if (is_listening)
throw new InvalidOperationException ();
return BeginConnect (Dns.GetHostAddresses (host), port, requestCallback, state);
var callback = new AsyncCallback ((result) => {
var resultTask = ((Task<IPAddress[]>)result);
BeginConnect (resultTask.Result, port, requestCallback, resultTask.AsyncState);
});
return ConvertToApm<IPAddress[]> (Dns.GetHostAddressesAsync (host), callback, state);
}
private static IAsyncResult ConvertToApm<T> (Task<T> task, AsyncCallback callback, object state)
{
if (task == null)
throw new ArgumentNullException ("task");
var tcs = new TaskCompletionSource<T> (state);
task.ContinueWith (t =>
{
if (t.IsFaulted)
tcs.TrySetException (t.Exception.InnerExceptions);
else if (t.IsCanceled)
tcs.TrySetCanceled ();
else
tcs.TrySetResult (t.Result);
if (callback != null)
callback (tcs.Task);
}, TaskScheduler.Default);
return tcs.Task;
}
public IAsyncResult BeginConnect (EndPoint remoteEP, AsyncCallback callback, object state)
@ -1383,6 +1409,20 @@ namespace System.Net.Sockets
return ret;
}
public int Receive(Span<byte> buffer, SocketFlags socketFlags, out SocketError errorCode)
{
byte[] tempBuffer = new byte[buffer.Length];
int result = Receive(tempBuffer, 0, tempBuffer.Length, socketFlags, out errorCode);
tempBuffer.CopyTo (buffer);
return result;
}
public int Send(ReadOnlySpan<byte> buffer, SocketFlags socketFlags, out SocketError errorCode)
{
byte[] bufferBytes = buffer.ToArray();
return Send(bufferBytes, 0, bufferBytes.Length, socketFlags, out errorCode);
}
public int Receive (Span<byte> buffer, SocketFlags socketFlags)
{
byte[] tempBuffer = new byte[buffer.Length];