From 94ea54bed60c8a06f9965721ba1680e798afcd02 Mon Sep 17 00:00:00 2001 From: John Hurliman Date: Mon, 15 Dec 2008 21:05:50 +0000 Subject: [PATCH] * Changed EventQueueServer to always obey the KeepAlive setting requested by the client * Added (very slow, O(n)) DoubleDictionary.Remove(TKey1) and DoubleDictionary.Remove(TKey2) functions git-svn-id: http://libopenmetaverse.googlecode.com/svn/libopenmetaverse/trunk@2381 52acb1d6-8a22-11de-b505-999d5b087335 --- .../Capabilities/EventQueueServer.cs | 8 ++-- OpenMetaverse/Types/DoubleDictionary.cs | 46 +++++++++++++++++++ 2 files changed, 50 insertions(+), 4 deletions(-) diff --git a/OpenMetaverse/Capabilities/EventQueueServer.cs b/OpenMetaverse/Capabilities/EventQueueServer.cs index 9ee6c430..911921c1 100644 --- a/OpenMetaverse/Capabilities/EventQueueServer.cs +++ b/OpenMetaverse/Capabilities/EventQueueServer.cs @@ -139,7 +139,7 @@ namespace OpenMetaverse.Capabilities context.Request.Url), Helpers.LogLevel.Info); Stop(); - context.Response.KeepAlive = false; + context.Response.KeepAlive = context.Request.KeepAlive; return true; } } @@ -148,7 +148,7 @@ namespace OpenMetaverse.Capabilities Logger.Log(String.Format("[EventQueue] Received a request with invalid or missing LLSD at {0}, closing the connection", context.Request.Url), Helpers.LogLevel.Warning); - context.Response.KeepAlive = false; + context.Response.KeepAlive = context.Request.KeepAlive; context.Response.StatusCode = (int)HttpStatusCode.BadRequest; return true; } @@ -213,6 +213,8 @@ namespace OpenMetaverse.Capabilities void SendResponse(HttpListenerContext httpContext, List eventsToSend) { + httpContext.Response.KeepAlive = httpContext.Request.KeepAlive; + if (eventsToSend != null) { OSDArray responseArray = new OSDArray(eventsToSend.Count); @@ -235,7 +237,6 @@ namespace OpenMetaverse.Capabilities // Serialize the events and send the response byte[] buffer = OSDParser.SerializeLLSDXmlBytes(responseMap); - httpContext.Response.KeepAlive = true; httpContext.Response.ContentType = "application/xml"; httpContext.Response.ContentLength64 = buffer.Length; httpContext.Response.OutputStream.Write(buffer, 0, buffer.Length); @@ -247,7 +248,6 @@ namespace OpenMetaverse.Capabilities // The 502 response started as a bug in the LL event queue server implementation, // but is now hardcoded into the protocol as the code to use for a timeout httpContext.Response.StatusCode = (int)HttpStatusCode.BadGateway; - httpContext.Response.KeepAlive = true; httpContext.Response.Close(); } } diff --git a/OpenMetaverse/Types/DoubleDictionary.cs b/OpenMetaverse/Types/DoubleDictionary.cs index dcae0d59..8d27642d 100644 --- a/OpenMetaverse/Types/DoubleDictionary.cs +++ b/OpenMetaverse/Types/DoubleDictionary.cs @@ -76,6 +76,52 @@ namespace OpenMetaverse } } + public bool Remove(TKey1 key1) + { + // This is an O(n) operation! + lock (syncObject) + { + TValue value; + if (Dictionary1.TryGetValue(key1, out value)) + { + foreach (KeyValuePair kvp in Dictionary2) + { + if (kvp.Value.Equals(value)) + { + Dictionary1.Remove(key1); + Dictionary2.Remove(kvp.Key); + return true; + } + } + } + } + + return false; + } + + public bool Remove(TKey2 key2) + { + // This is an O(n) operation! + lock (syncObject) + { + TValue value; + if (Dictionary2.TryGetValue(key2, out value)) + { + foreach (KeyValuePair kvp in Dictionary1) + { + if (kvp.Value.Equals(value)) + { + Dictionary2.Remove(key2); + Dictionary1.Remove(kvp.Key); + return true; + } + } + } + } + + return false; + } + public void Clear() { lock (syncObject)