We need you! We're working hard on the next version of Developer Fusion -
Let us know what you think we should be up to!
- using System;
- using System.Collections;
- using System.IO;
- using System.Reflection;
- using System.Runtime.Remoting;
- using System.Runtime.Remoting.Messaging;
- using System.Runtime.Remoting.Metadata;
- using System.Security.Permissions;
- namespace System.Runtime.Remoting.Channels
- {
-
-
-
-
-
- [System.Runtime.InteropServices.ComVisible(true)]
- public interface IClientChannelSinkStack : IClientResponseChannelSinkStack
- {
-
-
- [SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.Infrastructure)]
- void Push(IClientChannelSink sink, object state);
-
-
- [SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.Infrastructure)]
- object Pop(IClientChannelSink sink);
-
- }
-
- [System.Runtime.InteropServices.ComVisible(true)]
- public interface IClientResponseChannelSinkStack
- {
-
- [SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.Infrastructure)]
- void AsyncProcessResponse(ITransportHeaders headers, Stream stream);
-
-
-
- [SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.Infrastructure)]
- void DispatchReplyMessage(IMessage msg);
-
-
-
- [SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.Infrastructure)]
- void DispatchException(Exception e);
-
- }
-
-
- [SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.Infrastructure)]
- [System.Runtime.InteropServices.ComVisible(true)]
- public class ClientChannelSinkStack : IClientChannelSinkStack
- {
- private class SinkStack
- {
- public SinkStack PrevStack;
-
- public IClientChannelSink Sink;
- public object State;
- }
-
- private SinkStack _stack = null;
-
- private IMessageSink _replySink = null;
-
-
- public ClientChannelSinkStack()
- {
- }
-
-
- public ClientChannelSinkStack(IMessageSink replySink)
- {
- _replySink = replySink;
- }
-
-
-
- public void Push(IClientChannelSink sink, object state)
- {
- SinkStack newStack = new SinkStack();
- newStack.PrevStack = _stack;
- newStack.Sink = sink;
- newStack.State = state;
- _stack = newStack;
- }
-
-
-
- public object Pop(IClientChannelSink sink)
- {
- if (_stack == null) {
- throw new RemotingException(Environment.GetResourceString("Remoting_Channel_PopOnEmptySinkStack"));
- }
-
-
- do {
- if (_stack.Sink == sink)
- break;
-
- _stack = _stack.PrevStack;
- }
- while (_stack != null);
-
- if (_stack.Sink == null) {
- throw new RemotingException(Environment.GetResourceString("Remoting_Channel_PopFromSinkStackWithoutPush"));
- }
-
- object state = _stack.State;
- _stack = _stack.PrevStack;
-
- return state;
- }
-
-
- public void AsyncProcessResponse(ITransportHeaders headers, Stream stream)
- {
-
-
- if (_replySink != null) {
- if (_stack == null) {
- throw new RemotingException(Environment.GetResourceString("Remoting_Channel_CantCallAPRWhenStackEmpty"));
- }
-
- IClientChannelSink sink = _stack.Sink;
- object state = _stack.State;
- _stack = _stack.PrevStack;
-
- sink.AsyncProcessResponse(this, state, headers, stream);
- }
- }
-
-
-
-
- public void DispatchReplyMessage(IMessage msg)
- {
- if (_replySink != null)
- _replySink.SyncProcessMessage(msg);
- }
-
-
- public void DispatchException(Exception e)
- {
- DispatchReplyMessage(new ReturnMessage(e, null));
- }
-
- }
-
-
-
-
-
-
-
-
- [System.Runtime.InteropServices.ComVisible(true)]
- public interface IServerChannelSinkStack : IServerResponseChannelSinkStack
- {
-
-
- [SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.Infrastructure)]
- void Push(IServerChannelSink sink, object state);
-
-
- [SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.Infrastructure)]
- object Pop(IServerChannelSink sink);
-
- /// <internalonly/>
-
-
-
-
-
-
- [SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.Infrastructure)]
- void Store(IServerChannelSink sink, object state);
-
- /// <internalonly/>
-
-
-
- [SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.Infrastructure)]
- void StoreAndDispatch(IServerChannelSink sink, object state);
-
- /// <internalonly/>
-
-
- [SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.Infrastructure)]
- void ServerCallback(IAsyncResult ar);
-
- }
-
- [System.Runtime.InteropServices.ComVisible(true)]
- public interface IServerResponseChannelSinkStack
- {
- /// <internalonly/>
-
- [SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.Infrastructure)]
- void AsyncProcessResponse(IMessage msg, ITransportHeaders headers, Stream stream);
-
-
- [SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.Infrastructure)]
- Stream GetResponseStream(IMessage msg, ITransportHeaders headers);
- }
-
-
- [SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.Infrastructure)]
- [System.Runtime.InteropServices.ComVisible(true)]
- public class ServerChannelSinkStack : IServerChannelSinkStack
- {
- private class SinkStack
- {
- public SinkStack PrevStack;
-
- public IServerChannelSink Sink;
- public object State;
- }
-
- private SinkStack _stack = null;
- private SinkStack _rememberedStack = null;
-
-
- private IMessage _asyncMsg = null;
- private MethodInfo _asyncEnd = null;
- private object _serverObject = null;
- private IMethodCallMessage _msg = null;
-
-
- public void Push(IServerChannelSink sink, object state)
- {
- SinkStack newStack = new SinkStack();
- newStack.PrevStack = _stack;
- newStack.Sink = sink;
- newStack.State = state;
- _stack = newStack;
- }
-
-
- public object Pop(IServerChannelSink sink)
- {
- if (_stack == null) {
- throw new RemotingException(Environment.GetResourceString("Remoting_Channel_PopOnEmptySinkStack"));
- }
-
-
- do {
- if (_stack.Sink == sink)
- break;
-
- _stack = _stack.PrevStack;
- }
- while (_stack != null);
-
- if (_stack.Sink == null) {
- throw new RemotingException(Environment.GetResourceString("Remoting_Channel_PopFromSinkStackWithoutPush"));
- }
-
- object state = _stack.State;
- _stack = _stack.PrevStack;
-
- return state;
- }
-
-
- public void Store(IServerChannelSink sink, object state)
- {
- if (_stack == null) {
- throw new RemotingException(Environment.GetResourceString("Remoting_Channel_StoreOnEmptySinkStack"));
- }
-
-
- do {
- if (_stack.Sink == sink)
- break;
-
- _stack = _stack.PrevStack;
- }
- while (_stack != null);
-
- if (_stack.Sink == null) {
- throw new RemotingException(Environment.GetResourceString("Remoting_Channel_StoreOnSinkStackWithoutPush"));
- }
-
- SinkStack remStack = new SinkStack();
- remStack.PrevStack = _rememberedStack;
- remStack.Sink = sink;
- remStack.State = state;
- _rememberedStack = remStack;
-
- Pop(sink);
- }
-
- public void StoreAndDispatch(IServerChannelSink sink, object state)
- {
- Store(sink, state);
- FlipRememberedStack();
-
- CrossContextChannel.DoAsyncDispatch(_asyncMsg, null);
- }
-
-
- private void FlipRememberedStack()
- {
- if (_stack != null)
- throw new RemotingException(Environment.GetResourceString("Remoting_Channel_CantCallFRSWhenStackEmtpy"));
-
- while (_rememberedStack != null) {
- SinkStack newStack = new SinkStack();
- newStack.PrevStack = _stack;
- newStack.Sink = _rememberedStack.Sink;
- newStack.State = _rememberedStack.State;
- _stack = newStack;
- _rememberedStack = _rememberedStack.PrevStack;
- }
- }
-
-
- public void AsyncProcessResponse(IMessage msg, ITransportHeaders headers, Stream stream)
- {
- if (_stack == null) {
- throw new RemotingException(Environment.GetResourceString("Remoting_Channel_CantCallAPRWhenStackEmpty"));
- }
-
- IServerChannelSink sink = _stack.Sink;
- object state = _stack.State;
- _stack = _stack.PrevStack;
-
- sink.AsyncProcessResponse(this, state, msg, headers, stream);
- }
-
-
- public Stream GetResponseStream(IMessage msg, ITransportHeaders headers)
- {
- if (_stack == null) {
- throw new RemotingException(Environment.GetResourceString("Remoting_Channel_CantCallGetResponseStreamWhenStackEmpty"));
- }
-
-
- IServerChannelSink savedSink = _stack.Sink;
- object savedState = _stack.State;
-
- _stack = _stack.PrevStack;
- Stream stream = savedSink.GetResponseStream(this, savedState, msg, headers);
-
-
- Push(savedSink, savedState);
-
- return stream;
- }
-
-
- internal object ServerObject {
- set { _serverObject = value; }
- }
-
- public void ServerCallback(IAsyncResult ar)
- {
- if (_asyncEnd != null) {
- RemotingMethodCachedData asyncEndCache = (RemotingMethodCachedData)InternalRemotingServices.GetReflectionCachedData(_asyncEnd);
-
- MethodInfo syncMI = (MethodInfo)_msg.MethodBase;
- RemotingMethodCachedData syncCache = (RemotingMethodCachedData)InternalRemotingServices.GetReflectionCachedData(syncMI);
-
- ParameterInfo[] paramList = asyncEndCache.Parameters;
-
-
- object[] parameters = new object[paramList.Length];
- parameters[paramList.Length - 1] = ar;
-
- object[] syncMsgArgs = _msg.Args;
-
-
- AsyncMessageHelper.GetOutArgs(syncCache.Parameters, syncMsgArgs, parameters);
-
- object[] outArgs;
-
- StackBuilderSink s = new StackBuilderSink(_serverObject);
- object returnValue = s.PrivateProcessMessage(_asyncEnd.MethodHandle, System.Runtime.Remoting.Messaging.Message.CoerceArgs(_asyncEnd, parameters, paramList), _serverObject, 0, false, out outArgs);
-
-
-
- if (outArgs != null)
- outArgs = ArgMapper.ExpandAsyncEndArgsToSyncArgs(syncCache, outArgs);
-
- s.CopyNonByrefOutArgsFromOriginalArgs(syncCache, syncMsgArgs, ref outArgs);
-
- IMessage retMessage = new ReturnMessage(returnValue, outArgs, _msg.ArgCount, CallContext.GetLogicalCallContext(), _msg);
-
- AsyncProcessResponse(retMessage, null, null);
- }
- }
-
- }
-
-
-
- static internal class AsyncMessageHelper
- {
- static internal void GetOutArgs(ParameterInfo[] syncParams, object[] syncArgs, object[] endArgs)
- {
- int outCount = 0;
-
- for (int co = 0; co < syncParams.Length; co++) {
- if (syncParams[co].IsOut || syncParams[co].ParameterType.IsByRef) {
- endArgs[outCount++] = syncArgs[co];
- }
- }
-
- }
-
- }
-
- }