Code:
/ 4.0 / 4.0 / untmp / 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.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- Configuration.cs
- X509Utils.cs
- Int32Rect.cs
- ReadingWritingEntityEventArgs.cs
- UdpUtility.cs
- SafePEFileHandle.cs
- ParameterRefs.cs
- DataQuery.cs
- SqlSelectStatement.cs
- AnnotationResource.cs
- SimpleWebHandlerParser.cs
- SignatureToken.cs
- SettingsPropertyValue.cs
- DbParameterCollectionHelper.cs
- ThreadPool.cs
- InheritanceContextHelper.cs
- ExpandSegment.cs
- StringToken.cs
- SamlAuthorizationDecisionStatement.cs
- AccessDataSourceDesigner.cs
- VerticalAlignConverter.cs
- NetCodeGroup.cs
- _ContextAwareResult.cs
- DataControlCommands.cs
- Range.cs
- ProxyWebPart.cs
- IndexerNameAttribute.cs
- HttpProfileGroupBase.cs
- WebPartEventArgs.cs
- TextContainerChangedEventArgs.cs
- PrincipalPermission.cs
- AutomationPatternInfo.cs
- AutoFocusStyle.xaml.cs
- Int32AnimationBase.cs
- CollectionView.cs
- PositiveTimeSpanValidatorAttribute.cs
- PageContentAsyncResult.cs
- AutomationPatternInfo.cs
- MessageQueueEnumerator.cs
- _FtpDataStream.cs
- SafeThemeHandle.cs
- TransactionManager.cs
- EditorZone.cs
- SimpleExpression.cs
- HandleRef.cs
- Wildcard.cs
- MissingMemberException.cs
- WebRequest.cs
- WebPartPersonalization.cs
- DataGridLength.cs
- MasterPage.cs
- DataBoundControl.cs
- DefaultMemberAttribute.cs
- SystemInformation.cs
- System.Data_BID.cs
- LogicalMethodInfo.cs
- SchemaObjectWriter.cs
- HealthMonitoringSectionHelper.cs
- TriggerCollection.cs
- ProcessRequestAsyncResult.cs
- OdbcErrorCollection.cs
- LinqMaximalSubtreeNominator.cs
- Connector.cs
- MethodToken.cs
- CreateUserWizardStep.cs
- StrongNameHelpers.cs
- WindowsNonControl.cs
- DictionaryCustomTypeDescriptor.cs
- MatrixTransform3D.cs
- HtmlContainerControl.cs
- GeneralTransform3DTo2D.cs
- ToolStripDropDownClosedEventArgs.cs
- TokenBasedSet.cs
- WCFModelStrings.Designer.cs
- CodeNamespaceImport.cs
- ZipIOCentralDirectoryBlock.cs
- XmlILStorageConverter.cs
- SafeEventLogWriteHandle.cs
- OledbConnectionStringbuilder.cs
- LinkedList.cs
- GACIdentityPermission.cs
- RequestCache.cs
- StringStorage.cs
- WindowsScrollBarBits.cs
- Html32TextWriter.cs
- SqlFactory.cs
- HandlerFactoryCache.cs
- WindowsFormsSynchronizationContext.cs
- PathData.cs
- DataGridViewBindingCompleteEventArgs.cs
- SynchronizedInputHelper.cs
- SimpleHandlerBuildProvider.cs
- RegistryKey.cs
- CngKey.cs
- SessionSymmetricTransportSecurityProtocolFactory.cs
- SrgsGrammarCompiler.cs
- Executor.cs
- Debugger.cs
- BamlVersionHeader.cs
- Span.cs