Ejemplo n.º 1
0
 internal ContainerServiceHttpResponseContent(
     ContainerServiceHttpMessageHandler messageHandler,
     BufferedClientStream clientStream)
 {
     this.clientStream   = clientStream;
     this.messageHandler = messageHandler;
 }
 internal override void ReleaseClientStream(BufferedClientStream clientStream)
 {
     if (clientStream != null)
     {
         clientStream.Dispose();
     }
 }
Ejemplo n.º 3
0
 public ChunkedResponseReader(BufferedClientStream clientStream)
 {
     this.clientStream        = clientStream;
     this.chunkBytesRemaining = 0;
     this.isDisposed          = false;
     this.isEndOfResponse     = false;
 }
        internal override async Task <BufferedClientStream> AcquireClientStreamAsync(CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            Socket               socket        = null;
            NetworkStream        networkStream = null;
            BufferedClientStream clientStream  = null;

            try
            {
                socket = new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.Unspecified);
                await socket.ConnectAsync(this.socketEndpoint);

                networkStream = new NetworkStream(socket, true);

                clientStream = new BufferedClientStream(networkStream);
            }
            catch (Exception ex)
            {
                if (networkStream != null)
                {
                    networkStream.Dispose();
                }
                else if (socket != null)
                {
                    socket.Dispose();
                }

                var errMsg = this.GetConnectionFailedErrorMessage(ex);
                AppTrace.TraceSource.WriteWarning(TraceType, errMsg);
                throw new FabricException(errMsg, FabricErrorCode.InvalidOperation);
            }

            return(clientStream);
        }
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         lock (this.disposeLock)
         {
             this.messageHandler.ReleaseClientStream(this.clientStream);
             this.clientStream = null;
         }
     }
 }
        private async Task <HttpResponseMessage> SendPrivateAsync(CancellationToken cancellationToken)
        {
            this.clientStream = await this.messageHandler.AcquireClientStreamAsync(cancellationToken);

            await this.SendRequestHeaderAsync(cancellationToken);

            await this.SendRequestContentAsync(cancellationToken);

            // Receive headers
            var responseLines = await this.ReadResponseLinesAsync(cancellationToken);

            // Determine response type (Chunked, Content-Length, opaque, none...)
            // Receive body
            return(this.CreateResponseMessage(responseLines));
        }
        internal override Task <BufferedClientStream> AcquireClientStreamAsync(CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            NamedPipeClientStream pipeClientStream = null;
            BufferedClientStream  clientStream     = null;

            try
            {
                pipeClientStream = new NamedPipeClientStream(this.serverName, this.pipeName);
                pipeClientStream.Connect(ClientConnectionTimeoutMilliSeconds);

                clientStream = new BufferedClientStream(pipeClientStream);
            }
            catch (ArgumentOutOfRangeException ex)
            {
                ReleaseAssert.Failfast($"Connecting to pipe encountered: {ex}.");
            }
            catch (InvalidOperationException ex)
            {
                ReleaseAssert.Failfast($"Connecting to pipe encountered: {ex}.");
            }
            catch (Exception ex)
            {
                if (pipeClientStream != null)
                {
                    pipeClientStream.Dispose();
                }

                var errMsg = this.GetConnectionFailedErrorMessage(ex);
                AppTrace.TraceSource.WriteWarning(TraceType, errMsg);
                throw new FabricException(errMsg, FabricErrorCode.OperationTimedOut);
            }

            return(Task.FromResult(clientStream));
        }
 internal abstract void ReleaseClientStream(BufferedClientStream clientStream);