C# Class GitSharp.Core.Util.TimeoutStream

A normal Stream might provide a timeout on a specific read opreation. However, using StreamReader.ReadToEnd() on it can still get stuck for a long time. This class offers a timeout from the moment of it's construction to the read. Every read past the timeout from the stream's construction will fail. If the timeout elapsed while a read is in progress TimeoutStream is not responsible for aborting the read (there is no known good way in .NET to do it) See http://www.dotnet247.com/247reference/msgs/36/182553.aspx and http://www.google.co.il/search?q=cancel+async+Stream+read+.net Stream originalStream = GetStream(); StreamReader reader = new StreamReader(new TimeoutStream(originalStream, 5000)); // assuming the originalStream has a per-operation timeout, then ReadToEnd() // will return in (5000 + THAT_TIMEOUT) string foo = reader.ReadToEnd();
Inheritance: Stream
Show file Open project: jagregory/GitSharp Class Usage Examples

Public Methods

Method Description
Flush ( ) : void
Read ( byte buffer, int offset, int count ) : int
Seek ( long offset, SeekOrigin origin ) : long
SetLength ( long value ) : void
TimeoutStream ( Stream stream, int timeoutMillis ) : System
Write ( byte buffer, int offset, int count ) : void

Private Methods

Method Description
CheckTimeout ( ) : void

Method Details

Flush() public method

public Flush ( ) : void
return void

Read() public method

public Read ( byte buffer, int offset, int count ) : int
buffer byte
offset int
count int
return int

Seek() public method

public Seek ( long offset, SeekOrigin origin ) : long
offset long
origin SeekOrigin
return long

SetLength() public method

public SetLength ( long value ) : void
value long
return void

TimeoutStream() public method

public TimeoutStream ( Stream stream, int timeoutMillis ) : System
stream Stream
timeoutMillis int
return System

Write() public method

public Write ( byte buffer, int offset, int count ) : void
buffer byte
offset int
count int
return void