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

@@ -64,6 +64,23 @@ namespace System.Net
return await InnerStream.ReadAsync (
buffer, offset, size, cancellationToken).ConfigureAwait (false);
}
internal bool TryReadFromBuffer (byte[] buffer, int offset, int size, out int result)
{
var remaining = readBuffer?.Size ?? 0;
if (remaining <= 0) {
result = 0;
return InnerStream == null;
}
int copy = (remaining > size) ? size : remaining;
Buffer.BlockCopy (readBuffer.Buffer, readBuffer.Offset, buffer, offset, copy);
readBuffer.Offset += copy;
readBuffer.Size -= copy;
offset += copy;
size -= copy;
result = copy;
return true;
}
}
}

View File

@@ -61,6 +61,8 @@ namespace System.Net
bool disposed;
Stream stream;
public HttpWebResponse() { } // Added for NS2.1, it's empty in CoreFX too
// Constructors
internal HttpWebResponse (Uri uri, string method, HttpStatusCode status, WebHeaderCollection headers)

View File

@@ -35,6 +35,8 @@ namespace System.Net
public class HttpWebResponse : WebResponse, ISerializable, IDisposable
{
const string EXCEPTION_MESSAGE = "System.Net.HttpWebResponse is not supported on the current platform.";
public HttpWebResponse() { } // Added for NS2.1, it's empty in CoreFX too
[Obsolete ("Serialization is obsoleted for this type", false)]
protected HttpWebResponse (SerializationInfo serializationInfo, StreamingContext streamingContext)

View File

@@ -199,7 +199,7 @@ namespace System.Net {
/*
SocketPermission s = new SocketPermission (NetworkAccess.Connect, TransportType.Tcp, "www.google.com", 80);
SocketPermission s = new SocketPermission (NetworkAccess.Connect, TransportType.Tcp, "www.example.com", 80);
s.AddPermission (NetworkAccess.Accept, TransportType.All, "localhost", 8080);
s.AddPermission (NetworkAccess.Accept, TransportType.All, "localhost", SocketPermission.AllPorts);
// s = new SocketPermission (PermissionState.None);
@@ -211,7 +211,7 @@ namespace System.Net {
<IPermission class="System.Net.SocketPermission, System, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1">
<ConnectAccess>
<ENDPOINT host="www.google.com"
<ENDPOINT host="www.example.com"
transport="Tcp"
port="80"/>
</ConnectAccess>

View File

@@ -110,11 +110,12 @@ namespace System.Net
return e;
}
protected abstract bool TryReadFromBufferedContent (byte[] buffer, int offset, int count, out int result);
public override int Read (byte[] buffer, int offset, int count)
{
if (!CanRead)
throw new NotSupportedException (SR.net_writeonlystream);
Operation.ThrowIfClosedOrDisposed ();
if (buffer == null)
throw new ArgumentNullException (nameof (buffer));
@@ -125,7 +126,13 @@ namespace System.Net
if (count < 0 || (length - offset) < count)
throw new ArgumentOutOfRangeException (nameof (count));
try {
if (TryReadFromBufferedContent (buffer, offset, count, out var result))
return result;
Operation.ThrowIfClosedOrDisposed ();
try
{
return ReadAsync (buffer, offset, count, CancellationToken.None).Result;
} catch (Exception e) {
throw GetException (e);

View File

@@ -406,6 +406,8 @@ namespace System.Net
return Task.FromException<int> (new NotSupportedException (SR.net_writeonlystream));
}
protected override bool TryReadFromBufferedContent (byte[] buffer, int offset, int count, out int result) => throw new InvalidOperationException ();
protected override void Close_internal (ref bool disposed)
{
WebConnection.Debug ($"{ME} CLOSE: {disposed} {requestWritten} {allowBuffering}");

View File

@@ -184,6 +184,15 @@ namespace System.Net
}, () => Operation.Aborted, cancellationToken);
}
protected override bool TryReadFromBufferedContent (byte[] buffer, int offset, int count, out int result)
{
if (bufferedEntireContent && innerStream is BufferedReadStream bufferedStream)
return bufferedStream.TryReadFromBuffer (buffer, offset, count, out result);
result = 0;
return false;
}
bool CheckAuthHeader (string headerName)
{
var authHeader = Headers[headerName];
@@ -372,6 +381,7 @@ namespace System.Net
var buffer = await ReadAllAsyncInner (cancellationToken).ConfigureAwait (false);
var bos = new BufferOffsetSize (buffer, 0, buffer.Length, false);
innerStream = new BufferedReadStream (Operation, null, bos);
bufferedEntireContent = true;
nextReadCalled = true;
completion.TrySetCompleted ();