aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Servers/HttpServer/PollServiceWorkerThread.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Framework/Servers/HttpServer/PollServiceWorkerThread.cs175
1 files changed, 0 insertions, 175 deletions
diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceWorkerThread.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceWorkerThread.cs
deleted file mode 100644
index 1c529b6..0000000
--- a/OpenSim/Framework/Servers/HttpServer/PollServiceWorkerThread.cs
+++ /dev/null
@@ -1,175 +0,0 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28/* Ubit work moved to PollServiceRequestManager
29
30using System;
31using System.Collections;
32using System.Collections.Generic;
33using System.IO;
34using System.Text;
35using HttpServer;
36using OpenMetaverse;
37using System.Reflection;
38using log4net;
39using OpenSim.Framework.Monitoring;
40
41namespace OpenSim.Framework.Servers.HttpServer
42{
43 public delegate void ReQueuePollServiceItem(PollServiceHttpRequest req);
44
45 public class PollServiceWorkerThread
46 {
47 private static readonly ILog m_log =
48 LogManager.GetLogger(
49 MethodBase.GetCurrentMethod().DeclaringType);
50
51 public event ReQueuePollServiceItem ReQueue;
52
53 private readonly BaseHttpServer m_server;
54 private BlockingQueue<PollServiceHttpRequest> m_request;
55 private bool m_running = true;
56 private int m_timeout = 250;
57
58 public PollServiceWorkerThread(BaseHttpServer pSrv, int pTimeout)
59 {
60 m_request = new BlockingQueue<PollServiceHttpRequest>();
61 m_server = pSrv;
62 m_timeout = pTimeout;
63 }
64
65 public void ThreadStart()
66 {
67 Run();
68 }
69
70 public void Run()
71 {
72 while (m_running)
73 {
74 PollServiceHttpRequest req = m_request.Dequeue();
75
76 Watchdog.UpdateThread();
77
78 try
79 {
80 if (req.PollServiceArgs.HasEvents(req.RequestID, req.PollServiceArgs.Id))
81 {
82 StreamReader str;
83 try
84 {
85 str = new StreamReader(req.Request.Body);
86 }
87 catch (System.ArgumentException)
88 {
89 // Stream was not readable means a child agent
90 // was closed due to logout, leaving the
91 // Event Queue request orphaned.
92 continue;
93 }
94
95 try
96 {
97 Hashtable responsedata = req.PollServiceArgs.GetEvents(req.RequestID, req.PollServiceArgs.Id, str.ReadToEnd());
98 DoHTTPGruntWork(m_server, req, responsedata);
99 }
100 catch (ObjectDisposedException) // Browser aborted before we could read body, server closed the stream
101 {
102 // Ignore it, no need to reply
103 }
104 }
105 else
106 {
107 if ((Environment.TickCount - req.RequestTime) > m_timeout)
108 {
109 DoHTTPGruntWork(
110 m_server,
111 req,
112 req.PollServiceArgs.NoEvents(req.RequestID, req.PollServiceArgs.Id));
113 }
114 else
115 {
116 ReQueuePollServiceItem reQueueItem = ReQueue;
117 if (reQueueItem != null)
118 reQueueItem(req);
119 }
120 }
121 }
122 catch (Exception e)
123 {
124 m_log.ErrorFormat("Exception in poll service thread: " + e.ToString());
125 }
126 }
127 }
128
129 internal void Enqueue(PollServiceHttpRequest pPollServiceHttpRequest)
130 {
131 m_request.Enqueue(pPollServiceHttpRequest);
132 }
133
134 /// <summary>
135 /// FIXME: This should be part of BaseHttpServer
136 /// </summary>
137 internal static void DoHTTPGruntWork(BaseHttpServer server, PollServiceHttpRequest req, Hashtable responsedata)
138 {
139 OSHttpResponse response
140 = new OSHttpResponse(new HttpResponse(req.HttpContext, req.Request), req.HttpContext);
141
142 byte[] buffer = server.DoHTTPGruntWork(responsedata, response);
143
144 response.SendChunked = false;
145 response.ContentLength64 = buffer.Length;
146 response.ContentEncoding = Encoding.UTF8;
147
148 try
149 {
150 response.OutputStream.Write(buffer, 0, buffer.Length);
151 }
152 catch (Exception ex)
153 {
154 m_log.Warn(string.Format("[POLL SERVICE WORKER THREAD]: Error ", ex));
155 }
156 finally
157 {
158 //response.OutputStream.Close();
159 try
160 {
161 response.OutputStream.Flush();
162 response.Send();
163
164 //if (!response.KeepAlive && response.ReuseContext)
165 // response.FreeContext();
166 }
167 catch (Exception e)
168 {
169 m_log.Warn(String.Format("[POLL SERVICE WORKER THREAD]: Error ", e));
170 }
171 }
172 }
173 }
174}
175*/ \ No newline at end of file