diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Framework/Servers/HttpServer/PollServiceWorkerThread.cs | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceWorkerThread.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceWorkerThread.cs new file mode 100644 index 0000000..4c0be78 --- /dev/null +++ b/OpenSim/Framework/Servers/HttpServer/PollServiceWorkerThread.cs | |||
@@ -0,0 +1,100 @@ | |||
1 | using System; | ||
2 | using System.Collections; | ||
3 | using System.Collections.Generic; | ||
4 | /* | ||
5 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
6 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions are met: | ||
10 | * * Redistributions of source code must retain the above copyright | ||
11 | * notice, this list of conditions and the following disclaimer. | ||
12 | * * Redistributions in binary form must reproduce the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer in the | ||
14 | * documentation and/or other materials provided with the distribution. | ||
15 | * * Neither the name of the OpenSimulator Project nor the | ||
16 | * names of its contributors may be used to endorse or promote products | ||
17 | * derived from this software without specific prior written permission. | ||
18 | * | ||
19 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
20 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
22 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
29 | */ | ||
30 | |||
31 | using System.IO; | ||
32 | using System.Text; | ||
33 | using HttpServer; | ||
34 | using OpenMetaverse; | ||
35 | |||
36 | namespace OpenSim.Framework.Servers.HttpServer | ||
37 | { | ||
38 | public delegate void ReQueuePollServiceItem(PollServiceHttpRequest req); | ||
39 | |||
40 | public class PollServiceWorkerThread | ||
41 | { | ||
42 | public event ReQueuePollServiceItem ReQueue; | ||
43 | |||
44 | private readonly BaseHttpServer m_server; | ||
45 | private BlockingQueue<PollServiceHttpRequest> m_request; | ||
46 | private bool m_running = true; | ||
47 | private int m_timeout = 25000; | ||
48 | |||
49 | |||
50 | |||
51 | public PollServiceWorkerThread(BaseHttpServer pSrv, int pTimeout) | ||
52 | { | ||
53 | m_request = new BlockingQueue<PollServiceHttpRequest>(); | ||
54 | m_server = pSrv; | ||
55 | m_timeout = pTimeout; | ||
56 | } | ||
57 | |||
58 | public void ThreadStart(object o) | ||
59 | { | ||
60 | Run(); | ||
61 | } | ||
62 | |||
63 | public void Run() | ||
64 | { | ||
65 | while (m_running) | ||
66 | { | ||
67 | PollServiceHttpRequest req = m_request.Dequeue(); | ||
68 | if (req.PollServiceArgs.HasEvents(req.PollServiceArgs.Id)) | ||
69 | { | ||
70 | StreamReader str = new StreamReader(req.Request.Body); | ||
71 | |||
72 | Hashtable responsedata = req.PollServiceArgs.GetEvents(req.PollServiceArgs.Id, str.ReadToEnd()); | ||
73 | m_server.DoHTTPGruntWork(responsedata, | ||
74 | new OSHttpResponse(new HttpResponse(req.HttpContext, req.Request))); | ||
75 | } | ||
76 | else | ||
77 | { | ||
78 | if ((Environment.TickCount - req.RequestTime) > m_timeout) | ||
79 | { | ||
80 | m_server.DoHTTPGruntWork(req.PollServiceArgs.NoEvents(), | ||
81 | new OSHttpResponse(new HttpResponse(req.HttpContext, req.Request))); | ||
82 | } | ||
83 | else | ||
84 | { | ||
85 | ReQueuePollServiceItem reQueueItem = ReQueue; | ||
86 | if (reQueueItem != null) | ||
87 | reQueueItem(req); | ||
88 | } | ||
89 | } | ||
90 | } | ||
91 | |||
92 | |||
93 | } | ||
94 | |||
95 | internal void Enqueue(PollServiceHttpRequest pPollServiceHttpRequest) | ||
96 | { | ||
97 | m_request.Enqueue(pPollServiceHttpRequest); | ||
98 | } | ||
99 | } | ||
100 | } | ||