public BufferedReadStream(WebOperation operation, Stream innerStream, BufferOffsetSize readBuffer) : base(operation, innerStream) { this.readBuffer = readBuffer; }
public WebReadStream(WebOperation operation, Stream innerStream) { Operation = operation; InnerStream = innerStream; }
async Task Connect(WebOperation operation, CancellationToken cancellationToken) { IPHostEntry hostEntry = ServicePoint.HostEntry; if (hostEntry == null || hostEntry.AddressList.Length == 0) { #if MONOTOUCH && !MONOTOUCH_TV && !MONOTOUCH_WATCH xamarin_start_wwan(ServicePoint.Address.ToString()); hostEntry = ServicePoint.HostEntry; if (hostEntry == null) { #endif throw GetException(ServicePoint.UsesProxy ? WebExceptionStatus.ProxyNameResolutionFailure : WebExceptionStatus.NameResolutionFailure, null); #if MONOTOUCH && !MONOTOUCH_TV && !MONOTOUCH_WATCH } #endif } Exception connectException = null; foreach (IPAddress address in hostEntry.AddressList) { operation.ThrowIfDisposed(cancellationToken); try { socket = new Socket(address.AddressFamily, SocketType.Stream, ProtocolType.Tcp); } catch (Exception se) { // The Socket ctor can throw if we run out of FD's throw GetException(WebExceptionStatus.ConnectFailure, se); } IPEndPoint remote = new IPEndPoint(address, ServicePoint.Address.Port); socket.NoDelay = !ServicePoint.UseNagleAlgorithm; try { ServicePoint.KeepAliveSetup(socket); } catch { // Ignore. Not supported in all platforms. } if (!ServicePoint.CallEndPointDelegate(socket, remote)) { Interlocked.Exchange(ref socket, null)?.Close(); continue; } else { try { operation.ThrowIfDisposed(cancellationToken); await socket.ConnectAsync(remote).ConfigureAwait(false); } catch (ObjectDisposedException) { throw; } catch (Exception exc) { Interlocked.Exchange(ref socket, null)?.Close(); // Something went wrong, but we might have multiple IP Addresses // and need to probe them all. connectException = GetException(WebExceptionStatus.ConnectFailure, exc); continue; } } if (socket != null) { return; } } if (connectException == null) { connectException = GetException(WebExceptionStatus.ConnectFailure, null); } throw connectException; }
async Task Connect(WebOperation operation, CancellationToken cancellationToken) { IPHostEntry hostEntry = ServicePoint.HostEntry; if (hostEntry == null || hostEntry.AddressList.Length == 0) { #if MONOTOUCH && !MONOTOUCH_TV && !MONOTOUCH_WATCH xamarin_start_wwan(ServicePoint.Address.ToString()); hostEntry = ServicePoint.HostEntry; if (hostEntry == null) { #endif throw GetException(ServicePoint.UsesProxy ? WebExceptionStatus.ProxyNameResolutionFailure : WebExceptionStatus.NameResolutionFailure, null); #if MONOTOUCH && !MONOTOUCH_TV && !MONOTOUCH_WATCH } #endif } Exception connectException = null; foreach (IPAddress address in hostEntry.AddressList) { operation.ThrowIfDisposed(cancellationToken); try { socket = new Socket(address.AddressFamily, SocketType.Stream, ProtocolType.Tcp); } catch (Exception se) { // The Socket ctor can throw if we run out of FD's throw GetException(WebExceptionStatus.ConnectFailure, se); } IPEndPoint remote = new IPEndPoint(address, ServicePoint.Address.Port); socket.NoDelay = !ServicePoint.UseNagleAlgorithm; try { ServicePoint.KeepAliveSetup(socket); } catch { // Ignore. Not supported in all platforms. } if (!ServicePoint.CallEndPointDelegate(socket, remote)) { Interlocked.Exchange(ref socket, null)?.Close(); continue; } else { try { operation.ThrowIfDisposed(cancellationToken); /* * Socket.Tasks.cs from CoreFX introduces a new internal * BeginConnect(EndPoint) overload, which will replace * the one we're using from SocketTaskExtensions.cs. * * Our implementation of Socket.BeginConnect() does not * invoke the callback when the request failed synchronously. * * Explicitly use our implementation from SocketTaskExtensions.cs here. */ await Task.Factory.FromAsync( (targetEndPoint, callback, state) => ((Socket)state).BeginConnect (targetEndPoint, callback, state), asyncResult => ((Socket)asyncResult.AsyncState).EndConnect(asyncResult), remote, socket).ConfigureAwait(false); } catch (ObjectDisposedException) { throw; } catch (Exception exc) { Interlocked.Exchange(ref socket, null)?.Close(); // Something went wrong, but we might have multiple IP Addresses // and need to probe them all. connectException = GetException(WebExceptionStatus.ConnectFailure, exc); continue; } } if (socket != null) { return; } } if (connectException == null) { connectException = GetException(WebExceptionStatus.ConnectFailure, null); } throw connectException; }