Code:
/ 4.0 / 4.0 / untmp / 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.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- EmbeddedMailObjectsCollection.cs
- DataGridViewDataConnection.cs
- LongTypeConverter.cs
- Helper.cs
- __Filters.cs
- SchemaMapping.cs
- OrderedDictionary.cs
- ConfigurationFileMap.cs
- ThemeDictionaryExtension.cs
- TouchesOverProperty.cs
- KeyValueInternalCollection.cs
- TextContainer.cs
- Relationship.cs
- PriorityBinding.cs
- SQLUtility.cs
- Certificate.cs
- Win32KeyboardDevice.cs
- DispatcherOperation.cs
- XsltOutput.cs
- BaseParagraph.cs
- TableRow.cs
- RequestTimeoutManager.cs
- TreeNodeEventArgs.cs
- SafeNativeMethodsMilCoreApi.cs
- CuspData.cs
- DataGridPagerStyle.cs
- QueryLifecycle.cs
- WebPartDescription.cs
- CatalogZone.cs
- Label.cs
- RecordManager.cs
- TransactedReceiveData.cs
- CallbackValidatorAttribute.cs
- HttpResponseHeader.cs
- HttpServerUtilityWrapper.cs
- CommandManager.cs
- LabelEditEvent.cs
- IRCollection.cs
- FileUpload.cs
- XmlNode.cs
- Timeline.cs
- HostedTransportConfigurationBase.cs
- ScriptReferenceEventArgs.cs
- SafeProcessHandle.cs
- List.cs
- IdnElement.cs
- Tile.cs
- PeerCollaborationPermission.cs
- BooleanToVisibilityConverter.cs
- SystemNetworkInterface.cs
- WebHttpBindingElement.cs
- RemoteWebConfigurationHostStream.cs
- GrammarBuilderRuleRef.cs
- XmlWellformedWriter.cs
- StatusBar.cs
- X509RecipientCertificateClientElement.cs
- SettingsProperty.cs
- WebControl.cs
- FormattedText.cs
- SpecularMaterial.cs
- DbModificationCommandTree.cs
- RuntimeConfigurationRecord.cs
- SR.cs
- EventHandlerList.cs
- dbdatarecord.cs
- ImageAutomationPeer.cs
- HttpServerVarsCollection.cs
- LinqDataSourceSelectEventArgs.cs
- RuleSetBrowserDialog.cs
- SelectedGridItemChangedEvent.cs
- Path.cs
- InputManager.cs
- PrimaryKeyTypeConverter.cs
- Queue.cs
- DataServiceConfiguration.cs
- HttpChannelBindingToken.cs
- FrameworkTemplate.cs
- DataGridViewColumnDividerDoubleClickEventArgs.cs
- PathGeometry.cs
- UnsafeNativeMethodsCLR.cs
- ReadWriteObjectLock.cs
- CriticalFinalizerObject.cs
- MatcherBuilder.cs
- WebServiceResponseDesigner.cs
- ToolboxSnapDragDropEventArgs.cs
- ObjectReaderCompiler.cs
- TdsParserStateObject.cs
- HMACSHA1.cs
- ConfigurationSection.cs
- DataGridViewBand.cs
- Int64KeyFrameCollection.cs
- safemediahandle.cs
- OleDbPermission.cs
- DataPagerFieldItem.cs
- StylusSystemGestureEventArgs.cs
- XsdBuildProvider.cs
- FormsAuthenticationEventArgs.cs
- XmlSchemaSequence.cs
- ScrollableControl.cs
- DefaultBinder.cs