Inheritance: IAsyncResult, IMessageSink, IThreadPoolWorkItem
コード例 #1
0
		internal void InitMessage (MonoMethod method, object [] out_args)
		{
			this.method = method;
			ParameterInfo[] paramInfo = method.GetParametersInternal ();
			int param_count = paramInfo.Length;
			args = new object[param_count];
			arg_types = new byte[param_count];
			asyncResult = null;
			call_type = CallType.Sync;
			names = new string[param_count];
			for (int i = 0; i < param_count; i++) {
				names[i] = paramInfo[i].Name;
			}
			bool hasOutArgs = out_args != null;
			int j = 0;
			for (int i = 0; i < param_count; i++) {
				byte arg_type;
				bool isOut = paramInfo[i].IsOut;
				if (paramInfo[i].ParameterType.IsByRef) {
					if (hasOutArgs)
						args[i] = out_args[j++];
					arg_type = 2; // OUT
					if (!isOut)
						arg_type |= 1; // INOUT
				} else {
					arg_type = 1; // IN
					if (isOut)
						arg_type |= 4; // IN, COPY OUT
				}
				arg_types[i] = arg_type;
			}
		}
コード例 #2
0
ファイル: IISHandler1.cs プロジェクト: xandelima/MVCNorthwind
        public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback cb, object extraData)
        {
            IEnumerable<Customer> customers = repositorio.PesquisarLista();
               IAsyncResult result = new AsyncResult();
               result.AsyncState = customers.Take(Convert.ToInt32(context.Request["total"]));

               return result;
        }
コード例 #3
0
        public Message EndReceive(IAsyncResult result)
        {
            System.Runtime.Remoting.Messaging.AsyncResult aresult = result as System.Runtime.Remoting.Messaging.AsyncResult;
            if (aresult == null)
            {
                throw new ArgumentException("Invalid IAsyncResult type");
            }
            ReceiveDelegate d = aresult.AsyncDelegate as ReceiveDelegate;

            return(d.EndInvoke(result));
        }
コード例 #4
0
ファイル: ConcurrentPreloads.cs プロジェクト: s7loves/pesta
 private static PreloadedData getPreloadedData(AsyncResult future) 
 {
     try
     {
         Preloader.preloadProcessor processor = (Preloader.preloadProcessor)future.AsyncDelegate;
         return processor.EndInvoke(future);
     }
     catch (Exception e)
     {
         return new FailedPreload(e.InnerException);
     }
 }
コード例 #5
0
		public static bool QueueUserWorkItem (WaitCallback callBack, object state)
		{
			if (callBack == null)
				throw new ArgumentNullException ("callBack");

#if MOONLIGHT
			callBack = MoonlightHandler (callBack);
#endif
			if (callBack.IsTransparentProxy ()) {
				IAsyncResult ar = callBack.BeginInvoke (state, null, null);
				if (ar == null)
					return false;
			} else {
				if (!callBack.HasSingleTarget)
					throw new Exception ("The delegate must have only one target");

				AsyncResult ares = new AsyncResult (callBack, state, true);
				pool_queue (ares);
			}
			return true;
		}
コード例 #6
0
ファイル: ThreadPool.cs プロジェクト: psni/mono
		public static bool QueueUserWorkItem (WaitCallback callBack, object state)
		{
			if (Microsoft.ThreadPool.UseMicrosoftThreadPool) {
				return Microsoft.ThreadPool.QueueUserWorkItem (callBack, state);
			} else {
				if (callBack == null)
					throw new ArgumentNullException ("callBack");

				if (callBack.IsTransparentProxy ()) {
					IAsyncResult ar = callBack.BeginInvoke (state, null, null);
					if (ar == null)
						return false;
				} else {
					AsyncResult ares = new AsyncResult (callBack, state, !ExecutionContext.IsFlowSuppressed());
					pool_queue (ares);
				}
				return true;
			}
		}
コード例 #7
0
ファイル: ImapClient.cs プロジェクト: pengyancai/cs-util
            internal void BeginConnect(ConnectParams @params,
                                 AsyncCallback asyncCallback,
                                 object asyncState)
            {
                var proc = (ConnectProc)ImapClient.ConnectCore;

                this.asyncCallback = asyncCallback;
                this.asyncState = asyncState;

                innerAsyncResult = (AsyncResult)proc.BeginInvoke(@params, Callback, null);
            }
コード例 #8
0
ファイル: ThreadPool.cs プロジェクト: KonajuGames/SharpLang
		public static bool QueueUserWorkItem (WaitCallback callBack, object state)
		{
			if (callBack == null)
				throw new ArgumentNullException ("callBack");

			if (callBack.IsTransparentProxy ()) {
				IAsyncResult ar = callBack.BeginInvoke (state, null, null);
				if (ar == null)
					return false;
			} else {
				AsyncResult ares = new AsyncResult (callBack, state, true);
				pool_queue (ares);
			}
			return true;
		}
コード例 #9
0
ファイル: ThreadPool.cs プロジェクト: carrie901/mono
		public static bool UnsafeQueueUserWorkItem (WaitCallback callBack, object state)
		{
			// no stack propagation here (that's why it's unsafe and requires extra security permissions)
			if (!callBack.IsTransparentProxy ()) {
				if (!callBack.HasSingleTarget)
					throw new Exception ("The delegate must have only one target");

				AsyncResult ares = new AsyncResult (callBack, state, false);
				pool_queue (ares);
				return true;
			}
			try {
				if (!ExecutionContext.IsFlowSuppressed ())
					ExecutionContext.SuppressFlow (); // on current thread only
				IAsyncResult ar = callBack.BeginInvoke (state, null, null);
				if (ar == null)
					return false;
			} finally {
				if (ExecutionContext.IsFlowSuppressed ())
					ExecutionContext.RestoreFlow ();
			}
			return true;
		}
コード例 #10
0
        private static void Invoke(object NotUsed, ref MessageData msgData)
        {
            Message reqMcmMsg = new Message();
            reqMcmMsg.InitFields(msgData);
            Delegate thisPtr = reqMcmMsg.GetThisPtr() as Delegate;
            if (thisPtr == null)
            {
                throw new RemotingException(Environment.GetResourceString("Remoting_Default"));
            }
            RemotingProxy realProxy = (RemotingProxy) RemotingServices.GetRealProxy(thisPtr.Target);
            if (realProxy != null)
            {
                realProxy.InternalInvoke(reqMcmMsg, true, reqMcmMsg.GetCallType());
            }
            else
            {
                int callType = reqMcmMsg.GetCallType();
                switch (callType)
                {
                    case 1:
                    case 9:
                    {
                        reqMcmMsg.Properties[Message.CallContextKey] = CallContext.GetLogicalCallContext().Clone();
                        AsyncResult retVal = new AsyncResult(reqMcmMsg);
                        AgileAsyncWorkerItem state = new AgileAsyncWorkerItem(reqMcmMsg, ((callType & 8) != 0) ? null : retVal, thisPtr.Target);
                        ThreadPool.QueueUserWorkItem(new WaitCallback(AgileAsyncWorkerItem.ThreadPoolCallBack), state);
                        if ((callType & 8) != 0)
                        {
                            retVal.SyncProcessMessage(null);
                        }
                        reqMcmMsg.PropagateOutParameters(null, retVal);
                        break;
                    }
                    case 2:
                        RealProxy.EndInvokeHelper(reqMcmMsg, false);
                        return;

                    case 10:
                        break;

                    default:
                        return;
                }
            }
        }
コード例 #11
0
        internal virtual IMessage InternalInvoke(IMethodCallMessage reqMcmMsg, bool useDispatchMessage, int callType)
        {
            Message m = reqMcmMsg as Message;
            if ((m == null) && (callType != 0))
            {
                throw new RemotingException(Environment.GetResourceString("Remoting_Proxy_InvalidCallType"));
            }
            IMessage message2 = null;
            Thread currentThread = Thread.CurrentThread;
            LogicalCallContext logicalCallContext = currentThread.GetLogicalCallContext();
            Identity identityObject = this.IdentityObject;
            ServerIdentity identity2 = identityObject as ServerIdentity;
            if ((identity2 != null) && identityObject.IsFullyDisconnected())
            {
                throw new ArgumentException(Environment.GetResourceString("Remoting_ServerObjectNotFound", new object[] { reqMcmMsg.Uri }));
            }
            MethodBase methodBase = reqMcmMsg.MethodBase;
            if (_getTypeMethod == methodBase)
            {
                return new ReturnMessage(base.GetProxiedType(), null, 0, logicalCallContext, reqMcmMsg);
            }
            if (_getHashCodeMethod == methodBase)
            {
                return new ReturnMessage(identityObject.GetHashCode(), null, 0, logicalCallContext, reqMcmMsg);
            }
            if (identityObject.ChannelSink == null)
            {
                IMessageSink chnlSink = null;
                IMessageSink envoySink = null;
                if (!identityObject.ObjectRef.IsObjRefLite())
                {
                    RemotingServices.CreateEnvoyAndChannelSinks(null, identityObject.ObjectRef, out chnlSink, out envoySink);
                }
                else
                {
                    RemotingServices.CreateEnvoyAndChannelSinks(identityObject.ObjURI, null, out chnlSink, out envoySink);
                }
                RemotingServices.SetEnvoyAndChannelSinks(identityObject, chnlSink, envoySink);
                if (identityObject.ChannelSink == null)
                {
                    throw new RemotingException(Environment.GetResourceString("Remoting_Proxy_NoChannelSink"));
                }
            }
            IInternalMessage message3 = (IInternalMessage) reqMcmMsg;
            message3.IdentityObject = identityObject;
            if (identity2 != null)
            {
                message3.ServerIdentityObject = identity2;
            }
            else
            {
                message3.SetURI(identityObject.URI);
            }
            AsyncResult ar = null;
            switch (callType)
            {
                case 0:
                {
                    bool bSkippingContextChain = false;
                    Context currentContextInternal = currentThread.GetCurrentContextInternal();
                    IMessageSink envoyChain = identityObject.EnvoyChain;
                    if (currentContextInternal.IsDefaultContext && (envoyChain is EnvoyTerminatorSink))
                    {
                        bSkippingContextChain = true;
                        envoyChain = identityObject.ChannelSink;
                    }
                    return CallProcessMessage(envoyChain, reqMcmMsg, identityObject.ProxySideDynamicSinks, currentThread, currentContextInternal, bSkippingContextChain);
                }
                case 1:
                case 9:
                    logicalCallContext = (LogicalCallContext) logicalCallContext.Clone();
                    message3.SetCallContext(logicalCallContext);
                    ar = new AsyncResult(m);
                    this.InternalInvokeAsync(ar, m, useDispatchMessage, callType);
                    return new ReturnMessage(ar, null, 0, null, m);

                case 2:
                    return RealProxy.EndInvokeHelper(m, true);

                case 3:
                case 4:
                case 5:
                case 6:
                case 7:
                    return message2;

                case 8:
                    logicalCallContext = (LogicalCallContext) logicalCallContext.Clone();
                    message3.SetCallContext(logicalCallContext);
                    this.InternalInvokeAsync(null, m, useDispatchMessage, callType);
                    return new ReturnMessage(null, null, 0, null, reqMcmMsg);

                case 10:
                    return new ReturnMessage(null, null, 0, null, reqMcmMsg);
            }
            return message2;
        }
コード例 #12
0
 private void PrivateInvoke(ref MessageData msgData, int type)
 {
     IMessage reqMsg = null;
     CallType type2 = (CallType) type;
     IMessage retMsg = null;
     int msgFlags = -1;
     RemotingProxy proxy = null;
     if (CallType.MethodCall == type2)
     {
         Message message3 = new Message();
         message3.InitFields(msgData);
         reqMsg = message3;
         msgFlags = message3.GetCallType();
     }
     else if (CallType.ConstructorCall == type2)
     {
         msgFlags = 0;
         proxy = this as RemotingProxy;
         ConstructorCallMessage ccm = null;
         bool flag = false;
         if (!this.IsRemotingProxy())
         {
             ccm = new ConstructorCallMessage(null, null, null, (RuntimeType) this.GetProxiedType());
         }
         else
         {
             ccm = proxy.ConstructorMessage;
             Identity identityObject = proxy.IdentityObject;
             if (identityObject != null)
             {
                 flag = identityObject.IsWellKnown();
             }
         }
         if ((ccm == null) || flag)
         {
             ccm = new ConstructorCallMessage(null, null, null, (RuntimeType) this.GetProxiedType());
             ccm.SetFrame(msgData);
             reqMsg = ccm;
             if (flag)
             {
                 proxy.ConstructorMessage = null;
                 if (ccm.ArgCount != 0)
                 {
                     throw new RemotingException(Environment.GetResourceString("Remoting_Activation_WellKnownCTOR"));
                 }
             }
             retMsg = new ConstructorReturnMessage((MarshalByRefObject) this.GetTransparentProxy(), null, 0, null, ccm);
         }
         else
         {
             ccm.SetFrame(msgData);
             reqMsg = ccm;
         }
     }
     ChannelServices.IncrementRemoteCalls();
     if (!this.IsRemotingProxy() && ((msgFlags & 2) == 2))
     {
         Message message5 = reqMsg as Message;
         retMsg = EndInvokeHelper(message5, true);
     }
     if (retMsg == null)
     {
         LogicalCallContext cctx = null;
         Thread currentThread = Thread.CurrentThread;
         cctx = currentThread.GetLogicalCallContext();
         this.SetCallContextInMessage(reqMsg, msgFlags, cctx);
         cctx.PropagateOutgoingHeadersToMessage(reqMsg);
         retMsg = this.Invoke(reqMsg);
         this.ReturnCallContextToThread(currentThread, retMsg, msgFlags, cctx);
         CallContext.GetLogicalCallContext().PropagateIncomingHeadersToCallContext(retMsg);
     }
     if (!this.IsRemotingProxy() && ((msgFlags & 1) == 1))
     {
         Message m = reqMsg as Message;
         AsyncResult ret = new AsyncResult(m);
         ret.SyncProcessMessage(retMsg);
         retMsg = new ReturnMessage(ret, null, 0, null, m);
     }
     HandleReturnMessage(reqMsg, retMsg);
     if (CallType.ConstructorCall == type2)
     {
         MarshalByRefObject obj2 = null;
         IConstructionReturnMessage message7 = retMsg as IConstructionReturnMessage;
         if (message7 == null)
         {
             throw new RemotingException(Environment.GetResourceString("Remoting_Proxy_BadReturnTypeForActivation"));
         }
         ConstructorReturnMessage message8 = message7 as ConstructorReturnMessage;
         if (message8 != null)
         {
             obj2 = (MarshalByRefObject) message8.GetObject();
             if (obj2 == null)
             {
                 throw new RemotingException(Environment.GetResourceString("Remoting_Activation_NullReturnValue"));
             }
         }
         else
         {
             obj2 = (MarshalByRefObject) RemotingServices.InternalUnmarshal((ObjRef) message7.ReturnValue, this.GetTransparentProxy(), true);
             if (obj2 == null)
             {
                 throw new RemotingException(Environment.GetResourceString("Remoting_Activation_NullFromInternalUnmarshal"));
             }
         }
         if (obj2 != ((MarshalByRefObject) this.GetTransparentProxy()))
         {
             throw new RemotingException(Environment.GetResourceString("Remoting_Activation_InconsistentState"));
         }
         if (this.IsRemotingProxy())
         {
             proxy.ConstructorMessage = null;
         }
     }
 }
コード例 #13
0
		static void pool_queue (AsyncResult ares)
		{
			throw new System.NotImplementedException();
		}
コード例 #14
0
ファイル: ThreadPool.cs プロジェクト: psni/mono
		public static bool UnsafeQueueUserWorkItem (WaitCallback callBack, object state)
		{
			if (Microsoft.ThreadPool.UseMicrosoftThreadPool) {
				return Microsoft.ThreadPool.UnsafeQueueUserWorkItem (callBack, state);
			} else {
				if (callBack == null)
					throw new ArgumentNullException ("callBack");

				// no stack propagation here (that's why it's unsafe and requires extra security permissions)
				if (!callBack.IsTransparentProxy ()) {
					AsyncResult ares = new AsyncResult (callBack, state, false);
					pool_queue (ares);
					return true;
				}
				try {
					if (!ExecutionContext.IsFlowSuppressed ())
						ExecutionContext.SuppressFlow (); // on current thread only
					IAsyncResult ar = callBack.BeginInvoke (state, null, null);
					if (ar == null)
						return false;
				} finally {
					if (ExecutionContext.IsFlowSuppressed ())
						ExecutionContext.RestoreFlow ();
				}
				return true;
			}
		}
コード例 #15
0
ファイル: remotingproxy.cs プロジェクト: ArildF/masters
        } // Invoke
        

        // This is called for all remoted calls on a TP except Ctors
        // The method called may be Sync, Async or OneWay(special case of Async)
        // In the Async case we come here for both BeginInvoke & EndInvoke
        internal virtual IMessage InternalInvoke(
            IMethodCallMessage reqMcmMsg, bool useDispatchMessage, int callType)
        {
            Message reqMsg = reqMcmMsg as Message;            
            if ((reqMsg == null) && (callType != Message.Sync))
            {
                // Only the synchronous call type is supported for messages that
                //   aren't of type Message.               
                throw new RemotingException(
                    Environment.GetResourceString("Remoting_Proxy_InvalidCallType"));
            }
        
            IMessage retMsg = null;
            Thread currentThread = Thread.CurrentThread;

            // pick up call context from the thread
            LogicalCallContext cctx = currentThread.GetLogicalCallContext();

            Identity idObj = IdentityObject;
            ServerIdentity serverID = idObj as ServerIdentity;
            if ((null != serverID) && idObj.IsFullyDisconnected())
            {
                throw new ArgumentException(
                   String.Format(Environment.GetResourceString("Remoting_ServerObjectNotFound"), reqMcmMsg.Uri));
            }

            // Short-circuit calls to Object::GetType and Object::GetHashCode
            MethodBase mb = reqMcmMsg.MethodBase;
            if(_getTypeMethod == mb)
            {
                // Time to load the true type of the remote object....
                Type t = GetProxiedType();
                return new ReturnMessage(t, null, 0, null/*cctx*/, reqMcmMsg);
            }

            if (_getHashCodeMethod == mb)
            {
                int hashCode = idObj.GetHashCode();
                return new ReturnMessage(hashCode, null, 0, null/*cctx*/, reqMcmMsg);
            }

            // check for channel sink
            if (idObj.ChannelSink == null)
            {
                throw new RemotingException(
                    Environment.GetResourceString("Remoting_Proxy_NoChannelSink"));
            }

            // Set the identity in the message object
            IInternalMessage iim = (IInternalMessage)reqMcmMsg;
            iim.IdentityObject = idObj;

            if (null != serverID)
            {
                Message.DebugOut("Setting serveridentity on message \n");
                iim.ServerIdentityObject = serverID;
                    
            }
            else
            {
                // We need to set the URI only for identities that 
                // are not the server identities. The uri is used to
                // dispatch methods for objects outside the appdomain.
                // Inside the appdomain (xcontext case) we dispatch 
                // by getting the server object from the server identity.
               iim.SetURI(idObj.URI);
            }       

            Message.DebugOut("InternalInvoke. Dispatching based on class type\n");
            AsyncResult ar = null;
            switch (callType)
            {
            case Message.Sync:
                Message.DebugOut("RemotingProxy.Invoke Call: SyncProcessMsg\n");
                BCLDebug.Assert(!useDispatchMessage,"!useDispatchMessage");                
                bool bSkipContextChain = false;
                Context currentContext = currentThread.GetCurrentContextInternal();
                IMessageSink nextSink = idObj.EnvoyChain;

                // if we are in the default context, there can be no 
                // client context chain, so we can skip the intermediate 
                // calls if there are no envoy sinks

                if (currentContext.IsDefaultContext)
                {
                    if (nextSink is EnvoyTerminatorSink)
                    {
                        bSkipContextChain = true;

                        // jump directly to the channel sink
                        nextSink = idObj.ChannelSink;
                    }
                }

                retMsg = CallProcessMessage(nextSink,
                                            reqMcmMsg, 
                                            idObj.ProxySideDynamicSinks,
                                            currentThread,
                                            currentContext,
                                            bSkipContextChain);

                break;

            case Message.BeginAsync:
            case Message.BeginAsync | Message.OneWay:                
                // For async calls we clone the call context from the thread
                // This is a limited clone (we dont deep copy the user data)
                cctx = (LogicalCallContext) cctx.Clone(); 
                iim.SetCallContext(cctx);  
                
                ar = new AsyncResult(reqMsg);
              
                InternalInvokeAsync(ar, reqMsg, useDispatchMessage, callType);

                Message.DebugOut("Propagate out params for BeginAsync\n");
                retMsg = new ReturnMessage(ar, null, 0, null/*cctx*/, reqMsg);
                break;

            case Message.OneWay:
                // For async calls we clone the call context from the thread
                // This is a limited clone (we dont deep copy the user data)
                cctx = (LogicalCallContext) cctx.Clone();
                iim.SetCallContext(cctx);
                InternalInvokeAsync(null, reqMsg, useDispatchMessage, callType);
                retMsg = new ReturnMessage(null, null, 0, null/*cctx*/, reqMcmMsg);
                break;

            case (Message.EndAsync | Message.OneWay):
                retMsg = new ReturnMessage(null, null, 0, null/*cctx*/, reqMcmMsg);
                break;

            case Message.EndAsync:
                // For endAsync, we merge back the returned callContext
                // into the thread's callContext
                retMsg = RealProxy.EndInvokeHelper(reqMsg, true);
                break;
            }
            
            return retMsg;
        }
コード例 #16
0
ファイル: ThreadPool.cs プロジェクト: carrie901/mono
		static extern void pool_queue (AsyncResult ares);
コード例 #17
0
ファイル: remotingproxy.cs プロジェクト: ArildF/masters
        // Invoke for case where call is in the same context as the server object
        // (This special static method is used for AsyncDelegate-s ... this is called
        // directly from the EE)
        private static void Invoke(Object NotUsed, ref MessageData msgData)
        {
            Message m = new Message();
            m.InitFields(msgData);

            Object thisPtr = m.GetThisPtr();
            Delegate d;
            if ((d = thisPtr as Delegate) != null)
            {
                RemotingProxy rp = (RemotingProxy)
                    RemotingServices.GetRealProxy(d.Target);

                if (rp != null)
                {
                    rp.InternalInvoke(m, true, m.GetCallType());
                }
                else
                {
                    int callType = m.GetCallType();
                    AsyncResult ar;
                    switch (callType)
                    {
                    case Message.BeginAsync:
                    case Message.BeginAsync | Message.OneWay:
                        // pick up call context from the thread
                        m.Properties[Message.CallContextKey] =
                            CallContext.GetLogicalCallContext().Clone();
                        ar = new AsyncResult(m);
                        AgileAsyncWorkerItem  workItem = 
                            new AgileAsyncWorkerItem(
                                    m, 
                                    ((callType & Message.OneWay) != 0) ? 
                                        null : ar, d.Target);

                        ThreadPool.QueueUserWorkItem(
                            new WaitCallback(
                                    AgileAsyncWorkerItem.ThreadPoolCallBack),
                            workItem);

                        if ((callType & Message.OneWay) != 0)
                        {
                            ar.SyncProcessMessage(null);
                        }
                        m.PropagateOutParameters(null, ar);
                        break;

                    case (Message.EndAsync | Message.OneWay):
                        return;

                    case Message.EndAsync:
                        // This will also merge back the call context
                        // onto the thread that called EndAsync
                        RealProxy.EndInvokeHelper(m, false);
                        break;
                    default:
                        BCLDebug.Assert(
                            false, 
                            "Should never be here. Sync delegate code for agile object ended up in remoting");
            break;
                    }
                }
            }
            else
            {
                // Static invoke called with incorrect this pointer ...
                throw new RemotingException(
                    Environment.GetResourceString(
                        "Remoting_Default"));                    
            }
        }
コード例 #18
0
ファイル: realproxy.cs プロジェクト: uQr/referencesource
        [System.Security.SecurityCritical]  // auto-generated
        private void PrivateInvoke(ref MessageData msgData, int type)
        {
            IMessage reqMsg = null;
            CallType callType = (CallType)type;
            IMessage retMsg = null;
            int msgFlags = -1;

            // Used only for Construction case
            RemotingProxy rp = null;
            
            // Create a message object based on the type of call
            if(CallType.MethodCall == callType)
            {
                Message msg = new Message();
                msg.InitFields(msgData);
                reqMsg = msg;
                msgFlags = msg.GetCallType();
            }
            else if (CallType.ConstructorCall == (CallType)callType)
            {
                // We use msgFlags to handle CallContext around 
                // the virtual call to Invoke()
                msgFlags = Message.Sync;
                
                rp = this as RemotingProxy;
                ConstructorCallMessage ctorMsg = null;
                bool bIsWellKnown = false;
                if(!IsRemotingProxy())
                {
                    // Create a new constructor call message
                    // <

                    ctorMsg = new ConstructorCallMessage(null, null, null, (RuntimeType)GetProxiedType());
                }                                
                else
                {
                    // Extract the constructor message set in the first step of activation.
                    ctorMsg = rp.ConstructorMessage;                                         
                    // If the proxy is a wellknown client proxy, we don't 
                    // need to run the c'tor.
                    Identity id = rp.IdentityObject;
                    if (id != null)
                        bIsWellKnown = id.IsWellKnown();
                }
                
                if ((null == ctorMsg) || bIsWellKnown)
                {
                    // This is also used to short-circuit the activation path
                    // when we have a well known proxy that has already been
                    // initialized (there's a race condition if we don't do this).
                    //      
                
                    // This is a special case, where we have a remoting proxy
                    // but the constructormessage hasn't been setup.
                    // so let us just bail out.. 
                    // this is currently used by ServicedComponent's for cross appdomain
                    // pooling: <EMAIL>Microsoft</EMAIL>
                    //                    
                    ctorMsg = new ConstructorCallMessage(null, null, null, (RuntimeType)GetProxiedType());                    
                    // Set the constructor frame info in the CCM
                    ctorMsg.SetFrame(msgData); 
                    reqMsg = ctorMsg;

                    // If this was the default ctor, check that default .ctor was called.
                    if (bIsWellKnown)
                    {
                        Contract.Assert(rp!=null, "RemotingProxy expected here!");
                        // Clear any cached ctorMsg on the RemotingProxy
                        rp.ConstructorMessage = null;               

                        // We did execute a Connect. Throw if the client
                        // code is also trying to use a non-default constructor at
                        // the same time.
                        if (ctorMsg.ArgCount != 0)
                        {
                            throw new RemotingException(
                                Environment.GetResourceString(
                                    "Remoting_Activation_WellKnownCTOR"));
                        }
                    }
                    
                    // Create a constructor return message
                    retMsg = 
                        new ConstructorReturnMessage((MarshalByRefObject)GetTransparentProxy(), 
                            null, 
                            0, 
                            null, 
                            ctorMsg);
                }
                else
                {                
                    // Set the constructor frame info in the CCM
                    ctorMsg.SetFrame(msgData);
                    reqMsg = ctorMsg;
                }
            }
            else
            {
                Contract.Assert(false, "Unknown call type");
            }

            // Make sure that outgoing remote calls are counted.
            ChannelServices.IncrementRemoteCalls();

            // For non-remoting proxies, EndAsync should not call Invoke()
            // because the proxy cannot support Async and the call has already
            // finished executing in BeginAsync
            if (!IsRemotingProxy() 
                && ((msgFlags&Message.EndAsync)==Message.EndAsync))
            {

                Message msg = reqMsg as Message;
                retMsg = EndInvokeHelper(msg, true);
                Contract.Assert(null != retMsg, "null != retMsg");
            }

            // Invoke
            Contract.Assert(null != reqMsg, "null != reqMsg");
            if (null == retMsg)
            {
                // NOTE: there are cases where we setup a return message 
                // and we don't want the activation call to go through
                // refer to the note above for ServicedComponents and Cross Appdomain
                // pooling

                LogicalCallContext cctx = null;
                Thread currentThread = Thread.CurrentThread;
                // Pick up or clone the call context from the thread 
                // and install it in the reqMsg as appropriate
                cctx = currentThread.GetMutableExecutionContext().LogicalCallContext;
                SetCallContextInMessage(reqMsg, msgFlags, cctx);
                
                // Add the outgoing "Header"'s to the message.
                cctx.PropagateOutgoingHeadersToMessage(reqMsg);
                retMsg = Invoke(reqMsg);                

                // Get the call context returned and set it on the thread
                ReturnCallContextToThread(currentThread, retMsg, msgFlags, cctx);

                // Pull response "Header"'s out of the message
                Thread.CurrentThread.GetMutableExecutionContext().LogicalCallContext.PropagateIncomingHeadersToCallContext(retMsg);
            }

            if (!IsRemotingProxy()
                && ((msgFlags&Message.BeginAsync) == Message.BeginAsync))
            {

                // This was a begin-async on a non-Remoting Proxy. For V-1 they 
                // cannot support Async and end up doing a Sync call. We need 
                // to fill up here to make the call look like async to 
                // the caller. 
                // Create the async result to return
                Message msg = reqMsg as Message;
                AsyncResult ar = new AsyncResult(msg);
                // Tell the async result that the call has actually completed 
                // so it can hold on to the return message.
                ar.SyncProcessMessage(retMsg);       
                // create a returnMessage to propagate just the asyncResult back
                // to the caller's stack.
                retMsg = new ReturnMessage(ar, null, 0, null/*cctx*/, msg);
            }
            
            // Propagate out parameters
            HandleReturnMessage(reqMsg, retMsg);

            // For constructor calls do some extra bookkeeping
            if(CallType.ConstructorCall == callType)
            {
                // NOTE: It is the responsiblity of the callee to propagate
                // the out parameters

                // Everything went well, we are ready to return
                // a proxy to the caller
                // Extract the return value
                MarshalByRefObject retObj = null;
                IConstructionReturnMessage ctorRetMsg = retMsg as IConstructionReturnMessage;
                if(null == ctorRetMsg)
                {
                    throw new RemotingException(
                        Environment.GetResourceString("Remoting_Proxy_BadReturnTypeForActivation"));
                }

                ConstructorReturnMessage crm = ctorRetMsg as ConstructorReturnMessage;
                if (null != crm)
                {
                    // If return message is of type ConstructorReturnMessage 
                    // this is an in-appDomain activation. So no unmarshaling
                    // needed.

                    retObj = (MarshalByRefObject)crm.GetObject();
                    if (retObj == null)
                    {
                        throw new RemotingException(
                            Environment.GetResourceString("Remoting_Activation_NullReturnValue"));
                    }
                }
                else
                {
                    // Fetch the objRef out of the returned message and unmarshal it
                    retObj = (MarshalByRefObject)RemotingServices.InternalUnmarshal(
                                (ObjRef)ctorRetMsg.ReturnValue,
                                GetTransparentProxy(),
                                true /*fRefine*/);

                    if (retObj == null)
                    {
                        throw new RemotingException(
                            Environment.GetResourceString("Remoting_Activation_NullFromInternalUnmarshal"));
                    }
                }

                if (retObj != (MarshalByRefObject)GetTransparentProxy())
                {
                    throw new RemotingException(
                        Environment.GetResourceString(
                            "Remoting_Activation_InconsistentState"));
                }
                
                if (IsRemotingProxy())
                {
                    // Clear any cached ctorMsg on the RemotingProxy
                    rp.ConstructorMessage = null;
                }
            }
        }
コード例 #19
0
ファイル: remotingproxy.cs プロジェクト: ArildF/masters
 public AgileAsyncWorkerItem(IMethodCallMessage message, AsyncResult ar, Object target)
 {
     _message = new MethodCall(message, false);
     _ar = ar;
     _target = target;
 }
コード例 #20
0
ファイル: SocketAsyncResult.cs プロジェクト: quarksbar/mono
		public void Init (Socket socket, object state, AsyncCallback callback, SocketOperation operation, SocketAsyncWorker worker)
		{
			this.socket = socket;
			this.is_blocking = socket != null ? socket.is_blocking : true;
			this.handle = socket != null ? socket.Handle : IntPtr.Zero;
			this.state = state;
			this.callback = callback;
			this.operation = operation;

			if (wait_handle != null)
				((ManualResetEvent) wait_handle).Reset ();

			delayed_exception = null;

			EndPoint = null;
			Buffer = null;
			Offset = 0;
			Size = 0;
			SockFlags = SocketFlags.None;
			AcceptSocket = null;
			Addresses = null;
			Port = 0;
			Buffers = null;
			ReuseSocket = false;
			accept_socket = null;
			total = 0;

			completed_synchronously = false;
			completed = false;
			is_blocking = false;
			error = 0;
			async_result = null;
			EndCalled = 0;
			Worker = worker;
		}
 public AgileAsyncWorkerItem(IMethodCallMessage message, AsyncResult ar, object target)
 {
     this._message = new MethodCall(message);
     this._ar = ar;
     this._target = target;
 }