TimeoutStream.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Channels / TimeoutStream.cs / 1 / TimeoutStream.cs

                            //------------------------------------------------------------ 
// Copyright (c) Microsoft Corporation.  All rights reserved.
//-----------------------------------------------------------
namespace System.ServiceModel.Channels
{ 
    using System.IO;
 
    // Enforces an overall timeout based on the TimeoutHelper passed in 
    class TimeoutStream : DelegatingStream
    { 
        TimeoutHelper timeoutHelper;
        public TimeoutStream(Stream stream, ref TimeoutHelper timeoutHelper)
            : base(stream)
        { 
            if (!stream.CanTimeout)
            { 
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("stream", SR.GetString(SR.StreamDoesNotSupportTimeout)); 
            }
 
            this.timeoutHelper = timeoutHelper;
        }

        void UpdateReadTimeout() 
        {
            this.ReadTimeout = TimeoutHelper.ToMilliseconds(this.timeoutHelper.RemainingTime()); 
        } 

        void UpdateWriteTimeout() 
        {
            this.WriteTimeout = TimeoutHelper.ToMilliseconds(this.timeoutHelper.RemainingTime());
        }
 
        public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
        { 
            UpdateReadTimeout(); 
            return base.BeginRead(buffer, offset, count, callback, state);
        } 

        public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
        {
            UpdateWriteTimeout(); 
            return base.BeginWrite(buffer, offset, count, callback, state);
        } 
 
        public override int Read(byte[] buffer, int offset, int count)
        { 
            UpdateReadTimeout();
            return base.Read(buffer, offset, count);
        }
 
        public override int ReadByte()
        { 
            UpdateReadTimeout(); 
            return base.ReadByte();
        } 

        public override void Write(byte[] buffer, int offset, int count)
        {
            UpdateWriteTimeout(); 
            base.Write(buffer, offset, count);
        } 
 
        public override void WriteByte(byte value)
        { 
            UpdateWriteTimeout();
            base.WriteByte(value);
        }
    } 
}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK