public void SendEvents(int batchWaitMS) { if (Response == null) { return; } LLEventQueueEvent eventQueueEvent = null; if (EventQueue.Dequeue(batchWaitMS, ref eventQueueEvent)) { // An event was dequeued List <LLEventQueueEvent> eventsToSend = null; if (eventQueueEvent != null) { eventsToSend = new List <LLEventQueueEvent>(); eventsToSend.Add(eventQueueEvent); int start = Util.TickCount(); int batchMsPassed = 0; // Wait batchWaitMS milliseconds looking for more events, // or until the size of the current batch equals MAX_EVENTS_PER_RESPONSE while (batchMsPassed < batchWaitMS && eventsToSend.Count < MAX_EVENTS_PER_RESPONSE) { if (EventQueue.Dequeue(batchWaitMS - batchMsPassed, ref eventQueueEvent) && eventQueueEvent != null) { eventsToSend.Add(eventQueueEvent); } batchMsPassed = Util.TickCount() - start; } } // Make sure we can actually send the events right now if (Response != null && !Response.Sent) { SendResponse(eventsToSend); } else { m_log.Info("Connection is closed, requeuing events and closing the handler thread"); if (eventsToSend != null) { for (int i = 0; i < eventsToSend.Count; i++) { EventQueue.Enqueue(eventsToSend[i]); } } } } }
public void SendResponse(List <LLEventQueueEvent> eventsToSend) { if (Request == null || Response == null) { ConnectionOpen = false; m_log.Warn("Cannot send response, connection is closed"); return; } Response.Connection = Request.Connection; if (eventsToSend != null) { OSDArray responseArray = new OSDArray(eventsToSend.Count); // Put all of the events in an array for (int i = 0; i < eventsToSend.Count; i++) { LLEventQueueEvent currentEvent = eventsToSend[i]; OSDMap eventMap = new OSDMap(2); eventMap.Add("message", OSD.FromString(currentEvent.Name)); eventMap.Add("body", currentEvent.Body); responseArray.Add(eventMap); } // Create a map containing the events array and the id of this response OSDMap responseMap = new OSDMap(2); responseMap.Add("events", responseArray); responseMap.Add("id", OSD.FromInteger(CurrentID++)); // Serialize the events and send the response string responseBody = OSDParser.SerializeLLSDXmlString(responseMap); m_log.Debug("Sending " + responseArray.Count + " events over the event queue"); Context.Respond(HttpHelper.HTTP11, HttpStatusCode.OK, "OK", responseBody, "application/xml"); } else { //m_log.Debug("Sending a timeout response over the event queue"); // 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 Context.Respond(HttpHelper.HTTP10, HttpStatusCode.BadGateway, "Upstream error:", "Upstream error:", null); } ConnectionOpen = false; }