Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / clr / src / ManagedLibraries / Remoting / Channels / IPC / PipeStream.cs / 1305376 / PipeStream.cs
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
//==========================================================================
// File: PipeStream.cs
//
// Summary: Stream used for reading from a named pipe
// Author: [....]@microsoft.com
//=========================================================================
using System;
using System.IO;
using System.Runtime.Remoting;
namespace System.Runtime.Remoting.Channels.Ipc
{
// Basically the same as NetworkStream, but adds support for timeouts.
internal sealed class PipeStream : Stream
{
private IpcPort _port;
private int _timeout = 0; // throw timout exception if a read takes longer than this many milliseconds
public PipeStream(IpcPort port)
{
if (port == null)
throw new ArgumentNullException("port");
_port = port;
} // SocketStream
// Stream implementation
public override bool CanRead { get { return true; } }
public override bool CanSeek { get { return false; } }
public override bool CanWrite { get { return true; } }
public override long Length { get { throw new NotSupportedException(); } }
public override long Position
{
get { throw new NotSupportedException(); }
set { throw new NotSupportedException(); }
} // Position
public override long Seek(long offset, SeekOrigin origin)
{
throw new NotSupportedException();
}
public override int Read(byte[] buffer, int offset, int size)
{
if (_timeout <= 0)
{
return _port.Read(buffer, offset, size);
}
else
{
IAsyncResult ar = _port.BeginRead(buffer, offset, size, null, null);
if (_timeout>0 && !ar.IsCompleted)
{
ar.AsyncWaitHandle.WaitOne(_timeout, false);
if (!ar.IsCompleted)
throw new RemotingTimeoutException();
}
return _port.EndRead(ar);
}
} // Read
public override void Write(byte[] buffer, int offset, int count)
{
_port.Write(buffer, offset, count);
} // Write
protected override void Dispose(bool disposing)
{
try {
if (disposing)
_port.Dispose();
}
finally {
base.Dispose(disposing);
}
}
public override void Flush() { }
public override IAsyncResult BeginRead(
byte[] buffer,
int offset,
int size,
AsyncCallback callback,
Object state)
{
IAsyncResult asyncResult =
_port.BeginRead(
buffer,
offset,
size,
callback,
state);
return asyncResult;
} // BeginRead
public override int EndRead(IAsyncResult asyncResult)
{
return _port.EndRead(asyncResult);
} // EndRead
public override IAsyncResult BeginWrite(
byte[] buffer,
int offset,
int size,
AsyncCallback callback,
Object state)
{
throw new NotSupportedException();
} // BeginWrite
public override void EndWrite(IAsyncResult asyncResult)
{
throw new NotSupportedException();
} // EndWrite
public override void SetLength(long value) { throw new NotSupportedException(); }
} // class SocketStream
} // namespace System.Runtime.Remoting.Channels
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
//==========================================================================
// File: PipeStream.cs
//
// Summary: Stream used for reading from a named pipe
// Author: [....]@microsoft.com
//=========================================================================
using System;
using System.IO;
using System.Runtime.Remoting;
namespace System.Runtime.Remoting.Channels.Ipc
{
// Basically the same as NetworkStream, but adds support for timeouts.
internal sealed class PipeStream : Stream
{
private IpcPort _port;
private int _timeout = 0; // throw timout exception if a read takes longer than this many milliseconds
public PipeStream(IpcPort port)
{
if (port == null)
throw new ArgumentNullException("port");
_port = port;
} // SocketStream
// Stream implementation
public override bool CanRead { get { return true; } }
public override bool CanSeek { get { return false; } }
public override bool CanWrite { get { return true; } }
public override long Length { get { throw new NotSupportedException(); } }
public override long Position
{
get { throw new NotSupportedException(); }
set { throw new NotSupportedException(); }
} // Position
public override long Seek(long offset, SeekOrigin origin)
{
throw new NotSupportedException();
}
public override int Read(byte[] buffer, int offset, int size)
{
if (_timeout <= 0)
{
return _port.Read(buffer, offset, size);
}
else
{
IAsyncResult ar = _port.BeginRead(buffer, offset, size, null, null);
if (_timeout>0 && !ar.IsCompleted)
{
ar.AsyncWaitHandle.WaitOne(_timeout, false);
if (!ar.IsCompleted)
throw new RemotingTimeoutException();
}
return _port.EndRead(ar);
}
} // Read
public override void Write(byte[] buffer, int offset, int count)
{
_port.Write(buffer, offset, count);
} // Write
protected override void Dispose(bool disposing)
{
try {
if (disposing)
_port.Dispose();
}
finally {
base.Dispose(disposing);
}
}
public override void Flush() { }
public override IAsyncResult BeginRead(
byte[] buffer,
int offset,
int size,
AsyncCallback callback,
Object state)
{
IAsyncResult asyncResult =
_port.BeginRead(
buffer,
offset,
size,
callback,
state);
return asyncResult;
} // BeginRead
public override int EndRead(IAsyncResult asyncResult)
{
return _port.EndRead(asyncResult);
} // EndRead
public override IAsyncResult BeginWrite(
byte[] buffer,
int offset,
int size,
AsyncCallback callback,
Object state)
{
throw new NotSupportedException();
} // BeginWrite
public override void EndWrite(IAsyncResult asyncResult)
{
throw new NotSupportedException();
} // EndWrite
public override void SetLength(long value) { throw new NotSupportedException(); }
} // class SocketStream
} // namespace System.Runtime.Remoting.Channels
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- grammarelement.cs
- CurrentTimeZone.cs
- ObjectParameter.cs
- NamespaceList.cs
- PreviewPageInfo.cs
- safemediahandle.cs
- WebControlAdapter.cs
- DaylightTime.cs
- DomainConstraint.cs
- ObjectDataProvider.cs
- AtomServiceDocumentSerializer.cs
- HyperLinkField.cs
- LogLogRecordHeader.cs
- ScrollViewer.cs
- elementinformation.cs
- WindowsEditBoxRange.cs
- DatagridviewDisplayedBandsData.cs
- ThemeDirectoryCompiler.cs
- Setter.cs
- AttributedMetaModel.cs
- Int32Animation.cs
- UnsafeCollabNativeMethods.cs
- CompositeScriptReference.cs
- MetadataItemEmitter.cs
- OuterGlowBitmapEffect.cs
- GetReadStreamResult.cs
- WebBaseEventKeyComparer.cs
- MessageContractExporter.cs
- DataGridViewCellConverter.cs
- AnnotationHighlightLayer.cs
- GridViewDeleteEventArgs.cs
- StaticSiteMapProvider.cs
- OdbcUtils.cs
- DocumentStream.cs
- Atom10FormatterFactory.cs
- NameScopePropertyAttribute.cs
- Validator.cs
- WsiProfilesElement.cs
- SqlServer2KCompatibilityAnnotation.cs
- SerializationInfoEnumerator.cs
- CompensatableTransactionScopeActivityDesigner.cs
- SAPICategories.cs
- embossbitmapeffect.cs
- Freezable.cs
- CompilerScope.Storage.cs
- SiteOfOriginPart.cs
- LambdaCompiler.ControlFlow.cs
- ColorBlend.cs
- FloatMinMaxAggregationOperator.cs
- SoapIncludeAttribute.cs
- WebUtil.cs
- DefaultValidator.cs
- SimpleBitVector32.cs
- SecuritySessionSecurityTokenProvider.cs
- PointAnimationBase.cs
- BrowserTree.cs
- SequentialUshortCollection.cs
- HMAC.cs
- HostingEnvironmentWrapper.cs
- MatrixTransform3D.cs
- RtfToken.cs
- DataGridColumnCollection.cs
- SqlBulkCopyColumnMappingCollection.cs
- HttpCacheParams.cs
- DeploymentSection.cs
- MenuStrip.cs
- XmlStreamStore.cs
- Simplifier.cs
- HtmlLink.cs
- PathHelper.cs
- UnicastIPAddressInformationCollection.cs
- TypeConverterHelper.cs
- CommandPlan.cs
- QilStrConcat.cs
- EncodingDataItem.cs
- ListenerConnectionDemuxer.cs
- templategroup.cs
- ResXResourceSet.cs
- CollectionBase.cs
- HttpServerVarsCollection.cs
- UniqueCodeIdentifierScope.cs
- FlowDocumentPaginator.cs
- KeyedHashAlgorithm.cs
- SessionState.cs
- NavigatingCancelEventArgs.cs
- FontStyleConverter.cs
- WebCategoryAttribute.cs
- ObfuscateAssemblyAttribute.cs
- ListControlConvertEventArgs.cs
- TextDocumentView.cs
- HtmlTableCell.cs
- SmiEventSink_Default.cs
- RegisteredArrayDeclaration.cs
- OverlappedAsyncResult.cs
- ApplyTemplatesAction.cs
- ToolboxComponentsCreatedEventArgs.cs
- ObjectRef.cs
- BuildResult.cs
- ExpressionQuoter.cs
- DesignerVerbCollection.cs