aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorDr Scofield2008-06-25 13:10:12 +0000
committerDr Scofield2008-06-25 13:10:12 +0000
commitdaca971bf6de2020be00c6f0641494bd481bd091 (patch)
tree463c4f1f00907c6d83217b99397a0e1db763bb69 /OpenSim
parenttaking another look at mantis #1502: adding necessary locks, checking for emp... (diff)
downloadopensim-SC_OLD-daca971bf6de2020be00c6f0641494bd481bd091.zip
opensim-SC_OLD-daca971bf6de2020be00c6f0641494bd481bd091.tar.gz
opensim-SC_OLD-daca971bf6de2020be00c6f0641494bd481bd091.tar.bz2
opensim-SC_OLD-daca971bf6de2020be00c6f0641494bd481bd091.tar.xz
further work on the HttpServer stuff. not functional yet. just sharing
what crimes i'm committing.
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/Framework/Servers/OSHttpRequest.cs13
-rw-r--r--OpenSim/Framework/Servers/OSHttpRequestPump.cs17
-rw-r--r--OpenSim/Framework/Servers/OSHttpRequestQueue.cs66
-rw-r--r--OpenSim/Framework/Servers/OSHttpServer.cs41
4 files changed, 126 insertions, 11 deletions
diff --git a/OpenSim/Framework/Servers/OSHttpRequest.cs b/OpenSim/Framework/Servers/OSHttpRequest.cs
index d733f3d..530c91a 100644
--- a/OpenSim/Framework/Servers/OSHttpRequest.cs
+++ b/OpenSim/Framework/Servers/OSHttpRequest.cs
@@ -30,11 +30,15 @@ using System.Collections.Specialized;
30using System.Net; 30using System.Net;
31using System.IO; 31using System.IO;
32using System.Text; 32using System.Text;
33using HttpServer;
33 34
34namespace OpenSim.Framework.Servers 35namespace OpenSim.Framework.Servers
35{ 36{
36 public class OSHttpRequest 37 public class OSHttpRequest
37 { 38 {
39 /// <remarks>
40 /// soon to be deprecated
41 /// </remarks>
38 private string[] _acceptTypes; 42 private string[] _acceptTypes;
39 private Encoding _contentEncoding; 43 private Encoding _contentEncoding;
40 private long _contentLength64; 44 private long _contentLength64;
@@ -52,6 +56,9 @@ namespace OpenSim.Framework.Servers
52 private NameValueCollection _queryString; 56 private NameValueCollection _queryString;
53 private string _userAgent; 57 private string _userAgent;
54 58
59 private HttpRequest _request;
60 private HttpClientContext _context;
61
55 public string[] AcceptTypes 62 public string[] AcceptTypes
56 { 63 {
57 get { return _acceptTypes; } 64 get { return _acceptTypes; }
@@ -160,5 +167,11 @@ namespace OpenSim.Framework.Servers
160 _queryString = req.QueryString; 167 _queryString = req.QueryString;
161 _userAgent = req.UserAgent; 168 _userAgent = req.UserAgent;
162 } 169 }
170
171 public OSHttpRequest(HttpClientContext context, HttpRequest req)
172 {
173 _context = context;
174 _request = req;
175 }
163 } 176 }
164} 177}
diff --git a/OpenSim/Framework/Servers/OSHttpRequestPump.cs b/OpenSim/Framework/Servers/OSHttpRequestPump.cs
index 8a3e73f..06e41e4 100644
--- a/OpenSim/Framework/Servers/OSHttpRequestPump.cs
+++ b/OpenSim/Framework/Servers/OSHttpRequestPump.cs
@@ -31,25 +31,28 @@ using HttpServer;
31namespace OpenSim.Framework.Servers 31namespace OpenSim.Framework.Servers
32{ 32{
33 /// <summary> 33 /// <summary>
34 /// OSHttpServer provides an HTTP server bound to a specific 34 /// An OSHttpRequestPump fetches incoming OSHttpRequest objects
35 /// port. When instantiated with just address and port it uses 35 /// from the OSHttpRequestQueue and feeds them to all subscribed
36 /// normal HTTP, when instantiated with address, port, and X509 36 /// parties. Each OSHttpRequestPump encapsulates one thread to do
37 /// certificate, it uses HTTPS. 37 /// the work and there is a fixed number of pumps for each
38 /// OSHttpServer object.
38 /// </summary> 39 /// </summary>
39 public class OSHttpRequestPump 40 public class OSHttpRequestPump
40 { 41 {
41 protected OSHttpServer _httpServer; 42 protected OSHttpServer _server;
43 protected OSHttpRequestQueue _queue;
42 44
43 public OSHttpRequestPump() 45 public OSHttpRequestPump()
44 { 46 {
45 } 47 }
46 48
47 public static OSHttpRequestPump[] Pumps(OSHttpServer server, int poolSize) 49 public static OSHttpRequestPump[] Pumps(OSHttpServer server, OSHttpRequestQueue queue, int poolSize)
48 { 50 {
49 OSHttpRequestPump[] pumps = new OSHttpRequestPump[poolSize]; 51 OSHttpRequestPump[] pumps = new OSHttpRequestPump[poolSize];
50 for (int i = 0; i < pumps.Length; i++) 52 for (int i = 0; i < pumps.Length; i++)
51 { 53 {
52 pumps[i]._httpServer = server; 54 pumps[i]._server = server;
55 pumps[i]._queue = queue;
53 } 56 }
54 57
55 return pumps; 58 return pumps;
diff --git a/OpenSim/Framework/Servers/OSHttpRequestQueue.cs b/OpenSim/Framework/Servers/OSHttpRequestQueue.cs
new file mode 100644
index 0000000..f3dfda4
--- /dev/null
+++ b/OpenSim/Framework/Servers/OSHttpRequestQueue.cs
@@ -0,0 +1,66 @@
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 OpenSim 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
28using System;
29using System.Collections.Generic;
30using System.Threading;
31using HttpServer;
32
33namespace OpenSim.Framework.Servers
34{
35 /// <summary>
36 /// OSHttpRequestQueues are used to hand over incoming HTTP
37 /// requests to OSHttpRequestPump objects.
38 /// </summary>
39 public class OSHttpRequestQueue : Queue<OSHttpRequest>
40 {
41 new public void Enqueue(OSHttpRequest req)
42 {
43 lock (this)
44 {
45 base.Enqueue(req);
46 Monitor.Pulse(this);
47 }
48 }
49
50 new public OSHttpRequest Dequeue()
51 {
52 OSHttpRequest req = null;
53
54 lock (this)
55 {
56 while (null == req)
57 {
58 Monitor.Wait(this);
59 if (0 != this.Count) req = base.Dequeue();
60 }
61 }
62
63 return req;
64 }
65 }
66} \ No newline at end of file
diff --git a/OpenSim/Framework/Servers/OSHttpServer.cs b/OpenSim/Framework/Servers/OSHttpServer.cs
index 3aa8042..296f853 100644
--- a/OpenSim/Framework/Servers/OSHttpServer.cs
+++ b/OpenSim/Framework/Servers/OSHttpServer.cs
@@ -50,8 +50,12 @@ namespace OpenSim.Framework.Servers
50 50
51 // underlying HttpServer.HttpListener 51 // underlying HttpServer.HttpListener
52 protected HttpListener _listener; 52 protected HttpListener _listener;
53 // underlying core/engine thread
53 protected Thread _engine; 54 protected Thread _engine;
54 55
56 // Queue containing (OS)HttpRequests
57 protected OSHttpRequestQueue _queue;
58
55 // OSHttpRequestPumps "pumping" incoming OSHttpRequests 59 // OSHttpRequestPumps "pumping" incoming OSHttpRequests
56 // upwards 60 // upwards
57 protected OSHttpRequestPump[] _pumps; 61 protected OSHttpRequestPump[] _pumps;
@@ -72,6 +76,11 @@ namespace OpenSim.Framework.Servers
72 get { return _isSecure; } 76 get { return _isSecure; }
73 } 77 }
74 78
79 public int QueueSize
80 {
81 get { return _pumps.Length; }
82 }
83
75 /// <summary> 84 /// <summary>
76 /// Instantiate an HTTP server. 85 /// Instantiate an HTTP server.
77 /// </summary> 86 /// </summary>
@@ -80,17 +89,37 @@ namespace OpenSim.Framework.Servers
80 _engineId = String.Format("OSHttpServer [HTTP:{0}/ps:{1}]", port, poolSize); 89 _engineId = String.Format("OSHttpServer [HTTP:{0}/ps:{1}]", port, poolSize);
81 _isSecure = false; 90 _isSecure = false;
82 91
83 _pumps = OSHttpRequestPump.Pumps(this, poolSize); 92 _listener = new HttpListener(address, port);
93 _queue = new OSHttpRequestQueue();
94 _pumps = OSHttpRequestPump.Pumps(this, _queue, poolSize);
84 } 95 }
85 96
86 /// <summary> 97 /// <summary>
87 /// Instantiate an HTTPS server. 98 /// Instantiate an HTTPS server.
88 /// </summary> 99 /// </summary>
89 public OSHttpServer(IPAddress address, int port, X509Certificate certificate, int poolSize) : 100 public OSHttpServer(IPAddress address, int port, X509Certificate certificate, int poolSize)
90 this(address, port, poolSize)
91 { 101 {
92 _engineId = String.Format("OSHttpServer [HTTPS:{0}/ps:{1}]", port, poolSize); 102 _engineId = String.Format("OSHttpServer [HTTPS:{0}/ps:{1}]", port, poolSize);
93 _isSecure = true; 103 _isSecure = true;
104
105 _listener = new HttpListener(address, port, certificate);
106 _queue = new OSHttpRequestQueue();
107 _pumps = OSHttpRequestPump.Pumps(this, _queue, poolSize);
108 }
109
110 /// <summary>
111 /// Turn an HttpRequest into an OSHttpRequestItem and place it
112 /// in the queue. The OSHttpRequestQueue object will pulse the
113 /// next available idle pump.
114 /// </summary>
115 protected void OnHttpRequest(HttpClientContext client, HttpRequest request)
116 {
117 // turn request into OSHttpRequest
118 OSHttpRequest req = new OSHttpRequest(client, request);
119
120 // place OSHttpRequest into _httpRequestQueue, will
121 // trigger Pulse to idle waiting pumps
122 _queue.Enqueue(req);
94 } 123 }
95 124
96 /// <summary> 125 /// <summary>
@@ -102,6 +131,7 @@ namespace OpenSim.Framework.Servers
102 _engine.Name = _engineId; 131 _engine.Name = _engineId;
103 _engine.IsBackground = true; 132 _engine.IsBackground = true;
104 _engine.Start(); 133 _engine.Start();
134
105 ThreadTracker.Add(_engine); 135 ThreadTracker.Add(_engine);
106 } 136 }
107 137
@@ -111,9 +141,12 @@ namespace OpenSim.Framework.Servers
111 { 141 {
112 while (true) 142 while (true)
113 { 143 {
114 // do stuff 144 _listener.RequestHandler += OnHttpRequest;
145 _listener.Start(QueueSize);
115 } 146 }
116 } 147 }
117 148
149
150
118 } 151 }
119} 152}