From 98632ee594670625fbebc0faa49795fdccb9218a Mon Sep 17 00:00:00 2001 From: Teravus Ovares Date: Sat, 27 Sep 2008 22:05:36 +0000 Subject: * Event queue is now polling.. * returns FAKEEVENT instead of the connection returning a 502. It doesn't like our 502's for some reason.. so, in leau of this.. send it a fake event. * Once again, this is still 'really early' code, so please don't blame us if you have no more threads left. --- OpenSim/Framework/Servers/BaseHttpServer.cs | 6 +- .../Region/ClientStack/LindenUDP/LLClientView.cs | 3 +- .../Modules/Framework/EventQueueGetModule.cs | 65 +++++++++++++++++++--- .../Modules/Framework/EventQueueHelper.cs | 9 +++ 4 files changed, 73 insertions(+), 10 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Framework/Servers/BaseHttpServer.cs b/OpenSim/Framework/Servers/BaseHttpServer.cs index 24bba2b..504ca8b 100644 --- a/OpenSim/Framework/Servers/BaseHttpServer.cs +++ b/OpenSim/Framework/Servers/BaseHttpServer.cs @@ -991,6 +991,7 @@ namespace OpenSim.Framework.Servers string responseString = (string)responsedata["str_response_string"]; string contentType = (string)responsedata["content_type"]; + if (responsedata.ContainsKey("keepalive")) response.KeepAlive = true; @@ -1003,7 +1004,7 @@ namespace OpenSim.Framework.Servers } // The client ignores anything but 200 here for web login, so ensure that this is 200 for that - + response.StatusCode = responsecode; if (responsecode == (int)OSHttpStatusCode.RedirectMovedPermanently) @@ -1028,7 +1029,7 @@ namespace OpenSim.Framework.Servers response.SendChunked = false; response.ContentLength64 = buffer.Length; response.ContentEncoding = Encoding.UTF8; - + try { @@ -1042,6 +1043,7 @@ namespace OpenSim.Framework.Servers { response.OutputStream.Close(); } + } public void SendHTML404(OSHttpResponse response, string host) diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs index 5a48c90..46d03fb 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs @@ -783,7 +783,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP ClientLoop(); } } - catch (System.Exception e) + //Todo set as Generic Exception again. + catch (System.BadImageFormatException e) { if (e is ThreadAbortException) throw e; diff --git a/OpenSim/Region/Environment/Modules/Framework/EventQueueGetModule.cs b/OpenSim/Region/Environment/Modules/Framework/EventQueueGetModule.cs index d60e15a..ebaa406 100644 --- a/OpenSim/Region/Environment/Modules/Framework/EventQueueGetModule.cs +++ b/OpenSim/Region/Environment/Modules/Framework/EventQueueGetModule.cs @@ -52,11 +52,19 @@ using BlockingLLSDQueue = OpenSim.Framework.BlockingQueue m_ids = new Dictionary(); private Dictionary queues = new Dictionary(); @@ -83,6 +91,7 @@ namespace OpenSim.Region.Environment.Modules.Framework private void ReadConfigAndPopulate(Scene scene, IConfig startupConfig, string p) { + } public void PostInitialise() @@ -147,6 +156,7 @@ namespace OpenSim.Region.Environment.Modules.Framework { m_log.DebugFormat("[EVENTQUEUE]: Avatar {0} entering parcel {1} in region {2}.", avatar.UUID, localLandID, regionID); + } private void MakeChildAgent(ScenePresence avatar) @@ -164,29 +174,64 @@ namespace OpenSim.Region.Environment.Modules.Framework { return ProcessQueue(m_dhttpMethod,agentID, caps); })); + Random rnd = new Random(System.Environment.TickCount); + lock (m_ids) + { + if (!m_ids.ContainsKey(agentID)) + m_ids.Add(agentID, rnd.Next(30000000)); + } + + + } public Hashtable ProcessQueue(Hashtable request,UUID agentID, Caps caps) { // TODO: this has to be redone to not busy-wait (and block the thread), // TODO: as soon as we have a non-blocking way to handle HTTP-requests. + BlockingLLSDQueue queue = GetQueue(agentID); LLSD element = queue.Dequeue(15000); // 15s timeout + String debug = "[EVENTQUEUE]: Got request for agent {0}: [ "; foreach(object key in request.Keys) { debug += key.ToString() + "=" + request[key].ToString() + " "; } - m_log.DebugFormat(debug, agentID); - + //m_log.DebugFormat(debug, agentID); + if (element == null) // didn't have an event in 15s { + // Send it a fake event to keep the client polling! It doesn't like 502s like the proxys say! + element = EventQueueHelper.KeepAliveEvent(); + + ScenePresence avatar; + m_scene.TryGetAvatar(agentID, out avatar); + + LLSDArray array = new LLSDArray(); + array.Add(element); + int thisID = m_ids[agentID]; + while (queue.Count() > 0) + { + array.Add(queue.Dequeue(1)); + thisID++; + } + LLSDMap events = new LLSDMap(); + events.Add("events", array); + + events.Add("id", new LLSDInteger(thisID)); + lock (m_ids) + { + m_ids[agentID] = thisID + 1; + } Hashtable responsedata = new Hashtable(); - responsedata["int_response_code"] = 502; - responsedata["str_response_string"] = "Upstream error:"; - responsedata["content_type"] = "text/plain"; + responsedata["int_response_code"] = 200; + responsedata["content_type"] = "application/llsd+xml"; responsedata["keepalive"] = true; + responsedata["str_response_string"] = LLSDParser.SerializeXmlString(events); + //m_log.DebugFormat("[EVENTQUEUE]: sending fake response for {0}: {1}", agentID, responsedata["str_response_string"]); + return responsedata; } else @@ -196,14 +241,20 @@ namespace OpenSim.Region.Environment.Modules.Framework LLSDArray array = new LLSDArray(); array.Add(element); + int thisID = m_ids[agentID]; while (queue.Count() > 0) { array.Add(queue.Dequeue(1)); + thisID++; } LLSDMap events = new LLSDMap(); events.Add("events", array); - events.Add("id", new LLSDInteger(1)); // TODO: this seems to be a event sequence-numeber to be ack'd by the client? - + + events.Add("id", new LLSDInteger(thisID)); + lock (m_ids) + { + m_ids[agentID] = thisID + 1; + } Hashtable responsedata = new Hashtable(); responsedata["int_response_code"] = 200; responsedata["content_type"] = "application/llsd+xml"; diff --git a/OpenSim/Region/Environment/Modules/Framework/EventQueueHelper.cs b/OpenSim/Region/Environment/Modules/Framework/EventQueueHelper.cs index 7241cb3..46f7a3f 100644 --- a/OpenSim/Region/Environment/Modules/Framework/EventQueueHelper.cs +++ b/OpenSim/Region/Environment/Modules/Framework/EventQueueHelper.cs @@ -54,6 +54,15 @@ namespace OpenSim.Region.Environment llsdMessage.Add("body", llsdBody); return llsdMessage; + } + public static LLSD KeepAliveEvent() + { + LLSDMap llsdSimInfo = new LLSDMap(); + LLSDMap llsdMessage = new LLSDMap(2); + llsdMessage.Add("message", new LLSDString("FAKEEVENT")); + llsdMessage.Add("body", llsdSimInfo); + + return llsdMessage; } } } -- cgit v1.1