[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Dotgnu-pnet-commits] pnetlib/runtime/System/Runtime/Remoting/Messaging
From: |
Rhys Weatherley <address@hidden> |
Subject: |
[Dotgnu-pnet-commits] pnetlib/runtime/System/Runtime/Remoting/Messaging NullMessage.cs, NONE, 1.1 AsyncResult.cs, 1.5, 1.6 |
Date: |
Tue, 30 Sep 2003 00:38:20 +0000 |
Update of /cvsroot/dotgnu-pnet/pnetlib/runtime/System/Runtime/Remoting/Messaging
In directory
subversions:/tmp/cvs-serv1394/runtime/System/Runtime/Remoting/Messaging
Modified Files:
AsyncResult.cs
Added Files:
NullMessage.cs
Log Message:
Finish off the "AsyncResult" implementation.
Index: AsyncResult.cs
===================================================================
RCS file:
/cvsroot/dotgnu-pnet/pnetlib/runtime/System/Runtime/Remoting/Messaging/AsyncResult.cs,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** AsyncResult.cs 25 Apr 2003 04:45:13 -0000 1.5
--- AsyncResult.cs 30 Sep 2003 00:38:18 -0000 1.6
***************
*** 27,30 ****
--- 27,31 ----
using System;
using System.Threading;
+ using System.Runtime.CompilerServices;
// This class is not ECMA-compatible, strictly speaking. But it
***************
*** 37,41 ****
{
// Internal state.
! private Object del;
private Object[] args;
private AsyncCallback callback;
--- 38,42 ----
{
// Internal state.
! private Delegate del;
private Object[] args;
private AsyncCallback callback;
***************
*** 46,53 ****
private bool completed;
private bool endInvokeCalled;
// Construct a new asynchronous result object and begin invocation.
! [TODO]
! internal AsyncResult(Object del, Object[] args,
AsyncCallback callback, Object
state)
{
--- 47,58 ----
private bool completed;
private bool endInvokeCalled;
+ private ManualResetEvent waitHandle;
+ #if CONFIG_REMOTING
+ private IMessage replyMessage;
+ private IMessageCtrl messageControl;
+ #endif
// Construct a new asynchronous result object and begin invocation.
! internal AsyncResult(Delegate del, Object[] args,
AsyncCallback callback, Object
state)
{
***************
*** 63,67 ****
this.endInvokeCalled = false;
! // TODO: create a new thread to perform the
async call.
// We don't have threads, so call the delegate
synchronously.
--- 68,79 ----
this.endInvokeCalled = false;
! // If we have threads, then queue the delegate
to run
! // on the thread pool's completion worker
thread.
! if(Thread.CanStartThreads())
! {
! ThreadPool.QueueCompletionItem
! (new WaitCallback(Run), null);
! return;
! }
// We don't have threads, so call the delegate
synchronously.
***************
*** 69,73 ****
try
{
! this.result =
((Delegate)del).DynamicInvoke(args);
}
catch(Exception e)
--- 81,85 ----
try
{
! this.result = del.DynamicInvoke(args);
}
catch(Exception e)
***************
*** 102,112 ****
// Get a wait handle that can be used to wait for the
// asynchronous delegate call to complete.
- [TODO]
public virtual WaitHandle AsyncWaitHandle
{
get
{
! // TODO
! return null;
}
}
--- 114,129 ----
// Get a wait handle that can be used to wait for the
// asynchronous delegate call to complete.
public virtual WaitHandle AsyncWaitHandle
{
get
{
! lock(this)
! {
! if(waitHandle == null)
! {
! waitHandle = new
ManualResetEvent(false);
! }
! return waitHandle;
! }
}
}
***************
*** 137,141 ****
set
{
! // Not implemented - use "EndInvoke"
instead.
}
}
--- 154,161 ----
set
{
! lock(this)
! {
! endInvokeCalled = value;
! }
}
}
***************
*** 153,160 ****
}
// End invocation on the delegate in this object.
! [TODO]
! internal Object EndInvoke()
{
lock(this)
{
--- 173,204 ----
}
+ // Run the delegate on the completion worker thread.
+ private void Run(Object state)
+ {
+ try
+ {
+ result = del.DynamicInvoke(args);
+ }
+ catch(Exception e)
+ {
+ resultException = e;
+ }
+ completed = true;
+ ((ISignal)AsyncWaitHandle).Signal();
+ if(callback != null)
+ {
+ callback(this);
+ }
+ }
+
+ // Set the output parameters for an "EndInvoke" request.
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ extern private static void SetOutParams
+ (Delegate del, Object[] args, Object[]
outParams);
+
// End invocation on the delegate in this object.
! internal Object EndInvoke(Object[] outParams)
{
+ // Check for synchronous returns first.
lock(this)
{
***************
*** 168,197 ****
else
{
return result;
}
}
else
{
! if(endInvokeCalled)
! {
! if(resultException !=
null)
! {
! throw
resultException;
! }
! else
! {
! return result;
! }
! }
! // TODO: wait for the async
call to complete.
! endInvokeCalled = true;
! if(resultException != null)
! {
! throw resultException;
! }
! else
! {
! return result;
! }
}
}
--- 212,236 ----
else
{
+ SetOutParams(del, args,
outParams);
return result;
}
}
+ }
+
+ // Wait for the worker thread to signal us.
+ AsyncWaitHandle.WaitOne();
+
+ // Process the return values.
+ lock(this)
+ {
+ endInvokeCalled = true;
+ if(resultException != null)
+ {
+ throw resultException;
+ }
else
{
! SetOutParams(del, args,
outParams);
! return result;
}
}
***************
*** 201,240 ****
// Implement the IMessageSink interface.
- [TODO]
public IMessageSink NextSink
{
get
{
- // TODO
return null;
}
}
- [TODO]
public virtual IMessageCtrl AsyncProcessMessage
(IMessage msg, IMessageSink replySink)
{
! // TODO
! return null;
}
- [TODO]
public virtual IMessage SyncProcessMessage(IMessage msg)
{
! // TODO
return null;
}
// Get the reply message.
- [TODO]
public virtual IMessage GetReplyMessage()
{
! // TODO
! return null;
}
// Set the message control information for this result.
- [TODO]
public virtual void SetMessageCtrl(IMessageCtrl mc)
{
! // TODO
}
--- 240,294 ----
// Implement the IMessageSink interface.
public IMessageSink NextSink
{
get
{
return null;
}
}
public virtual IMessageCtrl AsyncProcessMessage
(IMessage msg, IMessageSink replySink)
{
! throw new NotSupportedException
! (_("NotSupp_DelAsyncProcMsg"));
}
public virtual IMessage SyncProcessMessage(IMessage msg)
{
! if(msg != null)
! {
! if(msg is IMethodReturnMessage)
! {
! replyMessage = msg;
! }
! else
! {
! replyMessage = new ReturnMessage
! (new
RemotingException(), new NullMessage());
! }
! }
! else
! {
! replyMessage = new ReturnMessage
! (new RemotingException(), new
NullMessage());
! }
! completed = true;
! ((ISignal)AsyncWaitHandle).Signal();
! if(callback != null)
! {
! callback(this);
! }
return null;
}
// Get the reply message.
public virtual IMessage GetReplyMessage()
{
! return replyMessage;
}
// Set the message control information for this result.
public virtual void SetMessageCtrl(IMessageCtrl mc)
{
! messageControl = mc;
}
--- NEW FILE: NullMessage.cs ---
/*
* NullMessage.cs - Implementation of the
* "System.Runtime.Remoting.Messaging.NullMessage" class.
*
* Copyright (C) 2003 Southern Storm Software, Pty Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
namespace System.Runtime.Remoting.Messaging
{
#if CONFIG_SERIALIZATION
using System.Collections;
using System.Reflection;
internal class NullMessage : IMessage, IMethodMessage, IMethodCallMessage
{
// Constructor.
public NullMessage() {}
// Implement the IMessage interface.
public IDictionary Properties
{
get
{
return null;
}
}
// Implement the IMethodMessage interface.
public int ArgCount
{
get
{
return 0;
}
}
public Object[] Args
{
get
{
return null;
}
}
public bool HasVarArgs
{
get
{
return false;
}
}
public LogicalCallContext LogicalCallContext
{
get
{
return null;
}
}
public MethodBase MethodBase
{
get
{
return null;
}
}
public String MethodName
{
get
{
return "Unknown";
}
}
public Object MethodSignature
{
get
{
return null;
}
}
public String TypeName
{
get
{
return "Unknown";
}
}
public String Uri
{
get
{
return "Exception";
}
}
public Object GetArg(int argNum)
{
return null;
}
public String GetArgName(int index)
{
return null;
}
// Implement the IMethodCallMessage interface.
public int InArgCount
{
get
{
return 0;
}
}
public Object[] InArgs
{
get
{
return null;
}
}
public Object GetInArg(int argNum)
{
return null;
}
public String GetInArgName(int index)
{
return "Unknown";
}
}; // class NullMessage
#endif // CONFIG_SERIALIZATION
}; // namespace System.Runtime.Remoting.Messaging
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Dotgnu-pnet-commits] pnetlib/runtime/System/Runtime/Remoting/Messaging NullMessage.cs, NONE, 1.1 AsyncResult.cs, 1.5, 1.6,
Rhys Weatherley <address@hidden> <=
- Prev by Date:
[Dotgnu-pnet-commits] pnet/engine int_proto.h, 1.85, 1.86 int_table.c, 1.88, 1.89 lib_delegate.c, 1.4, 1.5
- Next by Date:
[Dotgnu-pnet-commits] pnet/engine cvm_except.c, 1.24, 1.25 cvmc_gen.h, 1.9, 1.10
- Previous by thread:
[Dotgnu-pnet-commits] pnet/engine int_proto.h, 1.85, 1.86 int_table.c, 1.88, 1.89 lib_delegate.c, 1.4, 1.5
- Next by thread:
[Dotgnu-pnet-commits] pnet/engine cvm_except.c, 1.24, 1.25 cvmc_gen.h, 1.9, 1.10
- Index(es):