From e6ddb5de7de4ed61fa19b3805cd77104328eb20a Mon Sep 17 00:00:00 2001 From: Tedd Hansen Date: Wed, 26 Nov 2008 11:12:57 +0000 Subject: Attempt to give script objects a proper lease time (DNE and xengine). Relies on GC. Also removed lease for LSL_Api as it strictly speaking should not be MarshalByRef. Or should it? If so I broke scripting! :) --- .../ScriptEngine/Shared/Api/Implementation/LSL_Api.cs | 14 +++----------- .../ScriptEngine/Shared/Api/Runtime/ScriptBase.cs | 13 ++++++++----- .../ScriptEngine/Shared/Api/Runtime/ScriptSponsor.cs | 17 +++++++++++++++++ 3 files changed, 28 insertions(+), 16 deletions(-) create mode 100644 OpenSim/Region/ScriptEngine/Shared/Api/Runtime/ScriptSponsor.cs (limited to 'OpenSim/Region/ScriptEngine/Shared/Api') diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index 17dca98..cbd99bb 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -29,6 +29,7 @@ using System; using System.Collections; using System.Collections.Generic; using System.Runtime.Remoting.Lifetime; +using System.Security.Permissions; using System.Text; using System.Threading; using Nini.Config; @@ -64,7 +65,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api /// /// Contains all LSL ll-functions. This class will be in Default AppDomain. /// - public class LSL_Api : MarshalByRefObject, ILSL_Api, IScriptApi + public class LSL_Api : ILSL_Api, IScriptApi { protected IScriptEngine m_ScriptEngine; protected SceneObjectPart m_host; @@ -98,17 +99,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api AsyncCommands = new AsyncCommandManager(ScriptEngine); } - // Object never expires - public override Object InitializeLifetimeService() - { - ILease lease = (ILease)base.InitializeLifetimeService(); - if (lease.CurrentState == LeaseState.Initial) - { - lease.InitialLeaseTime = TimeSpan.Zero; - } - return lease; - } + protected void ScriptSleep(int delay) { diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/ScriptBase.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/ScriptBase.cs index 25c823d..06307bb 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/ScriptBase.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/ScriptBase.cs @@ -27,6 +27,7 @@ using System; using System.Runtime.Remoting.Lifetime; +using System.Security.Permissions; using System.Threading; using System.Reflection; using System.Collections; @@ -40,16 +41,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase { private Dictionary inits = new Dictionary(); - // - // Never expire this object - // + // Object expires if we don't keep it alive + // sponsor will be added on object load + [SecurityPermissionAttribute(SecurityAction.Demand, + Flags = SecurityPermissionFlag.Infrastructure)] public override Object InitializeLifetimeService() { ILease lease = (ILease)base.InitializeLifetimeService(); - if (lease.CurrentState == LeaseState.Initial) { - lease.InitialLeaseTime = TimeSpan.Zero; + lease.InitialLeaseTime = TimeSpan.FromMinutes(1); + lease.SponsorshipTimeout = TimeSpan.FromMinutes(2); + lease.RenewOnCallTime = TimeSpan.FromSeconds(2); } return lease; } diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/ScriptSponsor.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/ScriptSponsor.cs new file mode 100644 index 0000000..87401bb --- /dev/null +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/ScriptSponsor.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Runtime.Remoting.Lifetime; +using System.Text; + +namespace OpenSim.Region.ScriptEngine.Shared.Api.Runtime +{ + public class ScriptSponsor: ISponsor + { + // In theory: I execute, therefore I am. + // If GC collects this class then sponsorship will expire + public TimeSpan Renewal(ILease lease) + { + return TimeSpan.FromMinutes(2); + } + } +} -- cgit v1.1