Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / clr / src / ManagedLibraries / Remoting / Channels / IPC / IpcClientManager.cs / 1305376 / IpcClientManager.cs
// ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== //========================================================================== // File: IpcClientManager.cs // // Summary: Class for managing a client pipe connection. // //========================================================================= using System; using System.Collections; using System.IO; using System.Runtime.Remoting.Messaging; using System.Text; using System.Threading; using System.Runtime.Remoting.Channels.Tcp; using System.Globalization; namespace System.Runtime.Remoting.Channels.Ipc { // A client manager instance should encapsulate the port // for the purpose of reading a response internal class IpcClientHandler : IpcServerHandler { private bool _bOneWayRequest = false; // was the request made OneWay? private TcpReadingStream _responseStream = null; private int _contentLength; private bool _bChunked; private IpcClientTransportSink _sink = null; internal IpcClientHandler(IpcPort port, Stream stream, IpcClientTransportSink sink) : base (port, null, stream) { _sink = sink; } internal Stream GetResponseStream() { _responseStream = new TcpFixedLengthReadingStream(this, _contentLength); return _responseStream; } public new BaseTransportHeaders ReadHeaders() { BaseTransportHeaders headers = new BaseTransportHeaders(); UInt16 operation; ReadVersionAndOperation(out operation); // At this point, we're always expecting a Reply, so check for that. if (operation != TcpOperations.Reply) { throw new RemotingException( String.Format( CultureInfo.CurrentCulture, CoreChannel.GetResourceString("Remoting_Tcp_ExpectingReplyOp"), operation.ToString(CultureInfo.CurrentCulture))); } // content length must come next (may be chunked or a specific length) ReadContentLength(out _bChunked, out _contentLength); // read to end of headers ReadToEndOfHeaders(headers); return headers; } // ReadHeaders public override void OnInputStreamClosed() { // make sure we read to the end of the response stream if (_responseStream != null) { _responseStream.ReadToEnd(); _responseStream = null; } // return socket to the cache ReturnToCache(); } // OnInputStreamClosed internal void ReturnToCache() { _sink.Cache.ReleaseConnection(_port); } internal void SendRequest(IMessage msg, ITransportHeaders headers, Stream contentStream) { // Request is written just like a response // we can reuse the same code IMethodCallMessage mcm = (IMethodCallMessage)msg; int contentLength = (int)contentStream.Length; String uri = mcm.Uri; _bOneWayRequest = RemotingServices.IsOneWay(mcm.MethodBase); ChunkedMemoryStream headerStream = new ChunkedMemoryStream(CoreChannel.BufferPool); // output preamble and version WritePreambleAndVersion(headerStream); // output opcode if (!_bOneWayRequest) WriteUInt16(TcpOperations.Request, headerStream); else WriteUInt16(TcpOperations.OneWayRequest, headerStream); // output content delimiter style WriteUInt16(TcpContentDelimiter.ContentLength, headerStream); WriteInt32(contentLength, headerStream); // output request uri WriteUInt16(TcpHeaders.RequestUri, headerStream); WriteByte(TcpHeaderFormat.CountedString, headerStream); WriteCountedString(uri, headerStream); // output rest of headers WriteHeaders(headers, headerStream); headerStream.WriteTo(NetStream); headerStream.Close(); StreamHelper.CopyStream(contentStream, NetStream); contentStream.Close(); } } } // namespace System.Runtime.Remoting.Channels // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== //========================================================================== // File: IpcClientManager.cs // // Summary: Class for managing a client pipe connection. // //========================================================================= using System; using System.Collections; using System.IO; using System.Runtime.Remoting.Messaging; using System.Text; using System.Threading; using System.Runtime.Remoting.Channels.Tcp; using System.Globalization; namespace System.Runtime.Remoting.Channels.Ipc { // A client manager instance should encapsulate the port // for the purpose of reading a response internal class IpcClientHandler : IpcServerHandler { private bool _bOneWayRequest = false; // was the request made OneWay? private TcpReadingStream _responseStream = null; private int _contentLength; private bool _bChunked; private IpcClientTransportSink _sink = null; internal IpcClientHandler(IpcPort port, Stream stream, IpcClientTransportSink sink) : base (port, null, stream) { _sink = sink; } internal Stream GetResponseStream() { _responseStream = new TcpFixedLengthReadingStream(this, _contentLength); return _responseStream; } public new BaseTransportHeaders ReadHeaders() { BaseTransportHeaders headers = new BaseTransportHeaders(); UInt16 operation; ReadVersionAndOperation(out operation); // At this point, we're always expecting a Reply, so check for that. if (operation != TcpOperations.Reply) { throw new RemotingException( String.Format( CultureInfo.CurrentCulture, CoreChannel.GetResourceString("Remoting_Tcp_ExpectingReplyOp"), operation.ToString(CultureInfo.CurrentCulture))); } // content length must come next (may be chunked or a specific length) ReadContentLength(out _bChunked, out _contentLength); // read to end of headers ReadToEndOfHeaders(headers); return headers; } // ReadHeaders public override void OnInputStreamClosed() { // make sure we read to the end of the response stream if (_responseStream != null) { _responseStream.ReadToEnd(); _responseStream = null; } // return socket to the cache ReturnToCache(); } // OnInputStreamClosed internal void ReturnToCache() { _sink.Cache.ReleaseConnection(_port); } internal void SendRequest(IMessage msg, ITransportHeaders headers, Stream contentStream) { // Request is written just like a response // we can reuse the same code IMethodCallMessage mcm = (IMethodCallMessage)msg; int contentLength = (int)contentStream.Length; String uri = mcm.Uri; _bOneWayRequest = RemotingServices.IsOneWay(mcm.MethodBase); ChunkedMemoryStream headerStream = new ChunkedMemoryStream(CoreChannel.BufferPool); // output preamble and version WritePreambleAndVersion(headerStream); // output opcode if (!_bOneWayRequest) WriteUInt16(TcpOperations.Request, headerStream); else WriteUInt16(TcpOperations.OneWayRequest, headerStream); // output content delimiter style WriteUInt16(TcpContentDelimiter.ContentLength, headerStream); WriteInt32(contentLength, headerStream); // output request uri WriteUInt16(TcpHeaders.RequestUri, headerStream); WriteByte(TcpHeaderFormat.CountedString, headerStream); WriteCountedString(uri, headerStream); // output rest of headers WriteHeaders(headers, headerStream); headerStream.WriteTo(NetStream); headerStream.Close(); StreamHelper.CopyStream(contentStream, NetStream); contentStream.Close(); } } } // 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
- PrefixQName.cs
- CodeAssignStatement.cs
- DefaultEvaluationContext.cs
- PackWebResponse.cs
- GridEntryCollection.cs
- MD5CryptoServiceProvider.cs
- CommandConverter.cs
- StaticResourceExtension.cs
- SqlWriter.cs
- DataFormats.cs
- CategoryAttribute.cs
- EventLogPermissionEntry.cs
- RtfControlWordInfo.cs
- QilIterator.cs
- RegexCapture.cs
- WCFServiceClientProxyGenerator.cs
- BCLDebug.cs
- ApplicationDirectory.cs
- ViewBase.cs
- sqlpipe.cs
- QualifiedCellIdBoolean.cs
- DataExpression.cs
- XmlAttributeCache.cs
- WebReference.cs
- CompositeFontFamily.cs
- AliasGenerator.cs
- ByteStorage.cs
- PropertyBuilder.cs
- FixedHyperLink.cs
- GeometryValueSerializer.cs
- TableColumn.cs
- ReadOnlyCollectionBase.cs
- _Rfc2616CacheValidators.cs
- PageThemeCodeDomTreeGenerator.cs
- XPathExpr.cs
- AspProxy.cs
- ButtonRenderer.cs
- SystemWebExtensionsSectionGroup.cs
- SatelliteContractVersionAttribute.cs
- GeometryCollection.cs
- Control.cs
- ProtocolsConfigurationHandler.cs
- PasswordDeriveBytes.cs
- ColorBlend.cs
- StringDictionaryWithComparer.cs
- AsyncCompletedEventArgs.cs
- MouseCaptureWithinProperty.cs
- EventProviderTraceListener.cs
- InternalTypeHelper.cs
- ExecutionProperties.cs
- ChannelFactoryRefCache.cs
- TransformGroup.cs
- ValidatedMobileControlConverter.cs
- GeometryModel3D.cs
- JpegBitmapEncoder.cs
- CodeSnippetTypeMember.cs
- SqlStream.cs
- ResourceDescriptionAttribute.cs
- SerialReceived.cs
- EdmComplexPropertyAttribute.cs
- AxHost.cs
- QilDataSource.cs
- DataSource.cs
- WrappingXamlSchemaContext.cs
- Exception.cs
- DataGridColumnEventArgs.cs
- InfoCardX509Validator.cs
- Task.cs
- WebBodyFormatMessageProperty.cs
- FolderBrowserDialogDesigner.cs
- NewItemsContextMenuStrip.cs
- UnknownBitmapEncoder.cs
- EventDescriptorCollection.cs
- ColumnResizeUndoUnit.cs
- ComponentDispatcher.cs
- ThreadStateException.cs
- UnionExpr.cs
- NamespaceQuery.cs
- CookielessHelper.cs
- PrinterResolution.cs
- _NTAuthentication.cs
- TextParaLineResult.cs
- regiisutil.cs
- ZipIOLocalFileBlock.cs
- CallbackHandler.cs
- TypefaceMap.cs
- EntityDesignerBuildProvider.cs
- RecipientInfo.cs
- QuaternionConverter.cs
- FigureParaClient.cs
- ImageCollectionCodeDomSerializer.cs
- HtmlTableCell.cs
- UInt32.cs
- ApplicationContext.cs
- DataListItemCollection.cs
- RadioButton.cs
- SoapAttributeOverrides.cs
- ClientTargetSection.cs
- TextTreeInsertUndoUnit.cs
- Task.cs