aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Servers
diff options
context:
space:
mode:
authorUbitUmarov2015-09-01 14:54:35 +0100
committerUbitUmarov2015-09-01 14:54:35 +0100
commit371c9dd2af01a2e7422ec901ee1f80757284a78c (patch)
tree058d2a513cacb12efcce0c0df0ae14ad135dbfe2 /OpenSim/Framework/Servers
parentremove lixo (diff)
parentdont change camera on crossings (diff)
downloadopensim-SC_OLD-371c9dd2af01a2e7422ec901ee1f80757284a78c.zip
opensim-SC_OLD-371c9dd2af01a2e7422ec901ee1f80757284a78c.tar.gz
opensim-SC_OLD-371c9dd2af01a2e7422ec901ee1f80757284a78c.tar.bz2
opensim-SC_OLD-371c9dd2af01a2e7422ec901ee1f80757284a78c.tar.xz
bad merge?
Diffstat (limited to 'OpenSim/Framework/Servers')
-rw-r--r--OpenSim/Framework/Servers/BaseOpenSimServer.cs29
-rw-r--r--OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs107
-rw-r--r--OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs4
-rw-r--r--OpenSim/Framework/Servers/HttpServer/PollServiceHttpRequest.cs60
-rw-r--r--OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs215
-rw-r--r--OpenSim/Framework/Servers/ServerBase.cs4
-rw-r--r--OpenSim/Framework/Servers/Tests/OSHttpTests.cs326
7 files changed, 695 insertions, 50 deletions
diff --git a/OpenSim/Framework/Servers/BaseOpenSimServer.cs b/OpenSim/Framework/Servers/BaseOpenSimServer.cs
index 828a852..60702d4 100644
--- a/OpenSim/Framework/Servers/BaseOpenSimServer.cs
+++ b/OpenSim/Framework/Servers/BaseOpenSimServer.cs
@@ -65,8 +65,12 @@ namespace OpenSim.Framework.Servers
65 /// This will control a periodic log printout of the current 'show stats' (if they are active) for this 65 /// This will control a periodic log printout of the current 'show stats' (if they are active) for this
66 /// server. 66 /// server.
67 /// </summary> 67 /// </summary>
68<<<<<<< HEAD
68 private int m_periodDiagnosticTimerMS = 60 * 60 * 1000; 69 private int m_periodDiagnosticTimerMS = 60 * 60 * 1000;
69 private Timer m_periodicDiagnosticsTimer = new Timer(60 * 60 * 1000); 70 private Timer m_periodicDiagnosticsTimer = new Timer(60 * 60 * 1000);
71=======
72// private Timer m_periodicDiagnosticsTimer = new Timer(60 * 60 * 1000);
73>>>>>>> avn/ubitvar
70 74
71 /// <summary> 75 /// <summary>
72 /// Random uuid for private data 76 /// Random uuid for private data
@@ -84,6 +88,11 @@ namespace OpenSim.Framework.Servers
84 // Random uuid for private data 88 // Random uuid for private data
85 m_osSecret = UUID.Random().ToString(); 89 m_osSecret = UUID.Random().ToString();
86 90
91<<<<<<< HEAD
92=======
93// m_periodicDiagnosticsTimer.Elapsed += new ElapsedEventHandler(LogDiagnostics);
94// m_periodicDiagnosticsTimer.Enabled = true;
95>>>>>>> avn/ubitvar
87 } 96 }
88 97
89 /// <summary> 98 /// <summary>
@@ -146,14 +155,24 @@ namespace OpenSim.Framework.Servers
146 /// Performs initialisation of the scene, such as loading configuration from disk. 155 /// Performs initialisation of the scene, such as loading configuration from disk.
147 /// </summary> 156 /// </summary>
148 public virtual void Startup() 157 public virtual void Startup()
149 { 158 {
159 m_log.Info("[STARTUP]: Beginning startup processing");
160
161 m_log.Info("[STARTUP]: Careminster version: " + m_version + Environment.NewLine);
162 // clr version potentially is more confusing than helpful, since it doesn't tell us if we're running under Mono/MS .NET and
163 // the clr version number doesn't match the project version number under Mono.
164 //m_log.Info("[STARTUP]: Virtual machine runtime version: " + Environment.Version + Environment.NewLine);
165 m_log.InfoFormat(
166 "[STARTUP]: Operating system version: {0}, .NET platform {1}, {2}-bit\n",
167 Environment.OSVersion, Environment.OSVersion.Platform, Util.Is64BitProcess() ? "64" : "32");
168
150 StartupSpecific(); 169 StartupSpecific();
151 170
152 TimeSpan timeTaken = DateTime.Now - m_startuptime; 171 TimeSpan timeTaken = DateTime.Now - m_startuptime;
153 172
154 MainConsole.Instance.OutputFormat( 173// MainConsole.Instance.OutputFormat(
155 "PLEASE WAIT FOR LOGINS TO BE ENABLED ON REGIONS ONCE SCRIPTS HAVE STARTED. Non-script portion of startup took {0}m {1}s.", 174// "PLEASE WAIT FOR LOGINS TO BE ENABLED ON REGIONS ONCE SCRIPTS HAVE STARTED. Non-script portion of startup took {0}m {1}s.",
156 timeTaken.Minutes, timeTaken.Seconds); 175// timeTaken.Minutes, timeTaken.Seconds);
157 } 176 }
158 177
159 public string osSecret 178 public string osSecret
@@ -175,4 +194,4 @@ namespace OpenSim.Framework.Servers
175 } 194 }
176 } 195 }
177 } 196 }
178} \ No newline at end of file 197}
diff --git a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs
index f252bd5..616c673 100644
--- a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs
+++ b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs
@@ -403,6 +403,7 @@ namespace OpenSim.Framework.Servers.HttpServer
403 StreamReader reader = new StreamReader(requestStream, encoding); 403 StreamReader reader = new StreamReader(requestStream, encoding);
404 404
405 string requestBody = reader.ReadToEnd(); 405 string requestBody = reader.ReadToEnd();
406 reader.Close();
406 407
407 Hashtable keysvals = new Hashtable(); 408 Hashtable keysvals = new Hashtable();
408 Hashtable headervals = new Hashtable(); 409 Hashtable headervals = new Hashtable();
@@ -460,7 +461,7 @@ namespace OpenSim.Framework.Servers.HttpServer
460 } 461 }
461 462
462 OSHttpResponse resp = new OSHttpResponse(new HttpResponse(context, request),context); 463 OSHttpResponse resp = new OSHttpResponse(new HttpResponse(context, request),context);
463 resp.ReuseContext = true; 464 resp.ReuseContext = false;
464 HandleRequest(req, resp); 465 HandleRequest(req, resp);
465 466
466 // !!!HACK ALERT!!! 467 // !!!HACK ALERT!!!
@@ -759,7 +760,7 @@ namespace OpenSim.Framework.Servers.HttpServer
759 // Every month or so this will wrap and give bad numbers, not really a problem 760 // Every month or so this will wrap and give bad numbers, not really a problem
760 // since its just for reporting 761 // since its just for reporting
761 int tickdiff = requestEndTick - requestStartTick; 762 int tickdiff = requestEndTick - requestStartTick;
762 if (tickdiff > 3000 && requestHandler != null && requestHandler.Name != "GetTexture") 763 if (tickdiff > 3000 && (requestHandler == null || requestHandler.Name == null || requestHandler.Name != "GetTexture"))
763 { 764 {
764 m_log.InfoFormat( 765 m_log.InfoFormat(
765 "[LOGHTTP] Slow handling of {0} {1} {2} {3} {4} from {5} took {6}ms", 766 "[LOGHTTP] Slow handling of {0} {1} {2} {3} {4} from {5} took {6}ms",
@@ -1024,6 +1025,19 @@ namespace OpenSim.Framework.Servers.HttpServer
1024 string responseString = String.Empty; 1025 string responseString = String.Empty;
1025 XmlRpcRequest xmlRprcRequest = null; 1026 XmlRpcRequest xmlRprcRequest = null;
1026 1027
1028 bool gridproxy = false;
1029 if (requestBody.Contains("encoding=\"utf-8"))
1030 {
1031 int channelindx = -1;
1032 int optionsindx = requestBody.IndexOf(">options<");
1033 if(optionsindx >0)
1034 {
1035 channelindx = requestBody.IndexOf(">channel<");
1036 if (optionsindx < channelindx)
1037 gridproxy = true;
1038 }
1039 }
1040
1027 try 1041 try
1028 { 1042 {
1029 xmlRprcRequest = (XmlRpcRequest) (new XmlRpcRequestDeserializer()).Deserialize(requestBody); 1043 xmlRprcRequest = (XmlRpcRequest) (new XmlRpcRequestDeserializer()).Deserialize(requestBody);
@@ -1081,6 +1095,8 @@ namespace OpenSim.Framework.Servers.HttpServer
1081 } 1095 }
1082 xmlRprcRequest.Params.Add(request.Headers.Get(xff)); // Param[3] 1096 xmlRprcRequest.Params.Add(request.Headers.Get(xff)); // Param[3]
1083 1097
1098 if (gridproxy)
1099 xmlRprcRequest.Params.Add("gridproxy"); // Param[4]
1084 try 1100 try
1085 { 1101 {
1086 xmlRpcResponse = method(xmlRprcRequest, request.RemoteIPEndPoint); 1102 xmlRpcResponse = method(xmlRprcRequest, request.RemoteIPEndPoint);
@@ -1732,10 +1748,40 @@ namespace OpenSim.Framework.Servers.HttpServer
1732 1748
1733 internal byte[] DoHTTPGruntWork(Hashtable responsedata, OSHttpResponse response) 1749 internal byte[] DoHTTPGruntWork(Hashtable responsedata, OSHttpResponse response)
1734 { 1750 {
1735 //m_log.Info("[BASE HTTP SERVER]: Doing HTTP Grunt work with response"); 1751 int responsecode;
1736 int responsecode = (int)responsedata["int_response_code"]; 1752 string responseString = String.Empty;
1737 string responseString = (string)responsedata["str_response_string"]; 1753 byte[] responseData = null;
1738 string contentType = (string)responsedata["content_type"]; 1754 string contentType;
1755
1756 if (responsedata == null)
1757 {
1758 responsecode = 500;
1759 responseString = "No response could be obtained";
1760 contentType = "text/plain";
1761 responsedata = new Hashtable();
1762 }
1763 else
1764 {
1765 try
1766 {
1767 //m_log.Info("[BASE HTTP SERVER]: Doing HTTP Grunt work with response");
1768 responsecode = (int)responsedata["int_response_code"];
1769 if (responsedata["bin_response_data"] != null)
1770 responseData = (byte[])responsedata["bin_response_data"];
1771 else
1772 responseString = (string)responsedata["str_response_string"];
1773 contentType = (string)responsedata["content_type"];
1774 if (responseString == null)
1775 responseString = String.Empty;
1776 }
1777 catch
1778 {
1779 responsecode = 500;
1780 responseString = "No response could be obtained";
1781 contentType = "text/plain";
1782 responsedata = new Hashtable();
1783 }
1784 }
1739 1785
1740 if (responsedata.ContainsKey("error_status_text")) 1786 if (responsedata.ContainsKey("error_status_text"))
1741 { 1787 {
@@ -1780,25 +1826,40 @@ namespace OpenSim.Framework.Servers.HttpServer
1780 1826
1781 response.AddHeader("Content-Type", contentType); 1827 response.AddHeader("Content-Type", contentType);
1782 1828
1829 if (responsedata.ContainsKey("headers"))
1830 {
1831 Hashtable headerdata = (Hashtable)responsedata["headers"];
1832
1833 foreach (string header in headerdata.Keys)
1834 response.AddHeader(header, (string)headerdata[header]);
1835 }
1836
1783 byte[] buffer; 1837 byte[] buffer;
1784 1838
1785 if (!(contentType.Contains("image") 1839 if (responseData != null)
1786 || contentType.Contains("x-shockwave-flash")
1787 || contentType.Contains("application/x-oar")
1788 || contentType.Contains("application/vnd.ll.mesh")))
1789 { 1840 {
1790 // Text 1841 buffer = responseData;
1791 buffer = Encoding.UTF8.GetBytes(responseString);
1792 } 1842 }
1793 else 1843 else
1794 { 1844 {
1795 // Binary! 1845 if (!(contentType.Contains("image")
1796 buffer = Convert.FromBase64String(responseString); 1846 || contentType.Contains("x-shockwave-flash")
1797 } 1847 || contentType.Contains("application/x-oar")
1848 || contentType.Contains("application/vnd.ll.mesh")))
1849 {
1850 // Text
1851 buffer = Encoding.UTF8.GetBytes(responseString);
1852 }
1853 else
1854 {
1855 // Binary!
1856 buffer = Convert.FromBase64String(responseString);
1857 }
1798 1858
1799 response.SendChunked = false; 1859 response.SendChunked = false;
1800 response.ContentLength64 = buffer.Length; 1860 response.ContentLength64 = buffer.Length;
1801 response.ContentEncoding = Encoding.UTF8; 1861 response.ContentEncoding = Encoding.UTF8;
1862 }
1802 1863
1803 return buffer; 1864 return buffer;
1804 } 1865 }
@@ -1886,9 +1947,14 @@ namespace OpenSim.Framework.Servers.HttpServer
1886 m_httpListener2.Start(64); 1947 m_httpListener2.Start(64);
1887 1948
1888 // Long Poll Service Manager with 3 worker threads a 25 second timeout for no events 1949 // Long Poll Service Manager with 3 worker threads a 25 second timeout for no events
1950<<<<<<< HEAD
1889 PollServiceRequestManager = new PollServiceRequestManager(this, performPollResponsesAsync, 3, 25000); 1951 PollServiceRequestManager = new PollServiceRequestManager(this, performPollResponsesAsync, 3, 25000);
1890 PollServiceRequestManager.Start(); 1952 PollServiceRequestManager.Start();
1891 1953
1954=======
1955 m_PollServiceManager = new PollServiceRequestManager(this, 4, 25000);
1956 m_PollServiceManager.Start();
1957>>>>>>> avn/ubitvar
1892 HTTPDRunning = true; 1958 HTTPDRunning = true;
1893 1959
1894 //HttpListenerContext context; 1960 //HttpListenerContext context;
@@ -1937,7 +2003,9 @@ namespace OpenSim.Framework.Servers.HttpServer
1937 2003
1938 public void httpServerException(object source, Exception exception) 2004 public void httpServerException(object source, Exception exception)
1939 { 2005 {
1940 m_log.Error(String.Format("[BASE HTTP SERVER]: {0} had an exception: {1} ", source.ToString(), exception.Message), exception); 2006 if (source.ToString() == "HttpServer.HttpListener" && exception.ToString().StartsWith("Mono.Security.Protocol.Tls.TlsException"))
2007 return;
2008 m_log.ErrorFormat("[BASE HTTP SERVER]: {0} had an exception {1}", source.ToString(), exception.ToString());
1941 /* 2009 /*
1942 if (HTTPDRunning)// && NotSocketErrors > 5) 2010 if (HTTPDRunning)// && NotSocketErrors > 5)
1943 { 2011 {
@@ -1984,6 +2052,7 @@ namespace OpenSim.Framework.Servers.HttpServer
1984 2052
1985 public void RemoveHTTPHandler(string httpMethod, string path) 2053 public void RemoveHTTPHandler(string httpMethod, string path)
1986 { 2054 {
2055 if (path == null) return; // Caps module isn't loaded, tries to remove handler where path = null
1987 lock (m_HTTPHandlers) 2056 lock (m_HTTPHandlers)
1988 { 2057 {
1989 if (httpMethod != null && httpMethod.Length == 0) 2058 if (httpMethod != null && httpMethod.Length == 0)
diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs
index 9477100..3fd3bf7 100644
--- a/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs
+++ b/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs
@@ -52,7 +52,9 @@ namespace OpenSim.Framework.Servers.HttpServer
52 { 52 {
53 LongPoll = 0, 53 LongPoll = 0,
54 LslHttp = 1, 54 LslHttp = 1,
55 Inventory = 2 55 Inventory = 2,
56 Texture = 3,
57 Mesh = 4
56 } 58 }
57 59
58 public string Url { get; set; } 60 public string Url { get; set; }
diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceHttpRequest.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceHttpRequest.cs
index caf0e98..49cd110 100644
--- a/OpenSim/Framework/Servers/HttpServer/PollServiceHttpRequest.cs
+++ b/OpenSim/Framework/Servers/HttpServer/PollServiceHttpRequest.cs
@@ -27,6 +27,7 @@
27 27
28using System; 28using System;
29using System.Collections; 29using System.Collections;
30using System.Collections.Generic;
30using System.Reflection; 31using System.Reflection;
31using System.Text; 32using System.Text;
32using HttpServer; 33using HttpServer;
@@ -44,6 +45,24 @@ namespace OpenSim.Framework.Servers.HttpServer
44 public readonly IHttpRequest Request; 45 public readonly IHttpRequest Request;
45 public readonly int RequestTime; 46 public readonly int RequestTime;
46 public readonly UUID RequestID; 47 public readonly UUID RequestID;
48 public int contextHash;
49
50 private void GenContextHash()
51 {
52 Random rnd = new Random();
53 contextHash = 0;
54 if (Request.Headers["remote_addr"] != null)
55 contextHash = (Request.Headers["remote_addr"]).GetHashCode() << 16;
56 else
57 contextHash = rnd.Next() << 16;
58 if (Request.Headers["remote_port"] != null)
59 {
60 string[] strPorts = Request.Headers["remote_port"].Split(new char[] { ',' });
61 contextHash += Int32.Parse(strPorts[0]);
62 }
63 else
64 contextHash += rnd.Next() & 0xffff;
65 }
47 66
48 public PollServiceHttpRequest( 67 public PollServiceHttpRequest(
49 PollServiceEventArgs pPollServiceArgs, IHttpClientContext pHttpContext, IHttpRequest pRequest) 68 PollServiceEventArgs pPollServiceArgs, IHttpClientContext pHttpContext, IHttpRequest pRequest)
@@ -53,6 +72,7 @@ namespace OpenSim.Framework.Servers.HttpServer
53 Request = pRequest; 72 Request = pRequest;
54 RequestTime = System.Environment.TickCount; 73 RequestTime = System.Environment.TickCount;
55 RequestID = UUID.Random(); 74 RequestID = UUID.Random();
75 GenContextHash();
56 } 76 }
57 77
58 internal void DoHTTPGruntWork(BaseHttpServer server, Hashtable responsedata) 78 internal void DoHTTPGruntWork(BaseHttpServer server, Hashtable responsedata)
@@ -65,6 +85,7 @@ namespace OpenSim.Framework.Servers.HttpServer
65 response.SendChunked = false; 85 response.SendChunked = false;
66 response.ContentLength64 = buffer.Length; 86 response.ContentLength64 = buffer.Length;
67 response.ContentEncoding = Encoding.UTF8; 87 response.ContentEncoding = Encoding.UTF8;
88 response.ReuseContext = false;
68 89
69 try 90 try
70 { 91 {
@@ -93,5 +114,44 @@ namespace OpenSim.Framework.Servers.HttpServer
93 PollServiceArgs.RequestsHandled++; 114 PollServiceArgs.RequestsHandled++;
94 } 115 }
95 } 116 }
117
118 internal void DoHTTPstop(BaseHttpServer server)
119 {
120 OSHttpResponse response
121 = new OSHttpResponse(new HttpResponse(HttpContext, Request), HttpContext);
122
123 response.SendChunked = false;
124 response.ContentLength64 = 0;
125 response.ContentEncoding = Encoding.UTF8;
126 response.ReuseContext = false;
127 response.KeepAlive = false;
128 response.SendChunked = false;
129 response.StatusCode = 503;
130
131 try
132 {
133 response.OutputStream.Flush();
134 response.Send();
135 }
136 catch (Exception e)
137 {
138 }
139 }
140 }
141
142 class PollServiceHttpRequestComparer : IEqualityComparer<PollServiceHttpRequest>
143 {
144 public bool Equals(PollServiceHttpRequest b1, PollServiceHttpRequest b2)
145 {
146 if (b1.contextHash != b2.contextHash)
147 return false;
148 bool b = Object.ReferenceEquals(b1.HttpContext, b2.HttpContext);
149 return b;
150 }
151
152 public int GetHashCode(PollServiceHttpRequest b2)
153 {
154 return (int)b2.contextHash;
155 }
96 } 156 }
97} \ No newline at end of file 157} \ No newline at end of file
diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs
index 28bba70..4ffe6e5 100644
--- a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs
+++ b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs
@@ -65,15 +65,25 @@ namespace OpenSim.Framework.Servers.HttpServer
65 65
66 private readonly BaseHttpServer m_server; 66 private readonly BaseHttpServer m_server;
67 67
68 private Dictionary<PollServiceHttpRequest, Queue<PollServiceHttpRequest>> m_bycontext;
68 private BlockingQueue<PollServiceHttpRequest> m_requests = new BlockingQueue<PollServiceHttpRequest>(); 69 private BlockingQueue<PollServiceHttpRequest> m_requests = new BlockingQueue<PollServiceHttpRequest>();
69 private static List<PollServiceHttpRequest> m_longPollRequests = new List<PollServiceHttpRequest>(); 70 private static Queue<PollServiceHttpRequest> m_slowRequests = new Queue<PollServiceHttpRequest>();
71 private static Queue<PollServiceHttpRequest> m_retryRequests = new Queue<PollServiceHttpRequest>();
70 72
71 private uint m_WorkerThreadCount = 0; 73 private uint m_WorkerThreadCount = 0;
72 private Thread[] m_workerThreads; 74 private Thread[] m_workerThreads;
75 private Thread m_retrysThread;
73 76
77<<<<<<< HEAD
74 private SmartThreadPool m_threadPool = new SmartThreadPool(20000, 12, 2); 78 private SmartThreadPool m_threadPool = new SmartThreadPool(20000, 12, 2);
75 79
76// private int m_timeout = 1000; // increase timeout 250; now use the event one 80// private int m_timeout = 1000; // increase timeout 250; now use the event one
81=======
82 private bool m_running = true;
83 private int slowCount = 0;
84
85 private SmartThreadPool m_threadPool;
86>>>>>>> avn/ubitvar
77 87
78 public PollServiceRequestManager( 88 public PollServiceRequestManager(
79 BaseHttpServer pSrv, bool performResponsesAsync, uint pWorkerThreadCount, int pTimeout) 89 BaseHttpServer pSrv, bool performResponsesAsync, uint pWorkerThreadCount, int pTimeout)
@@ -83,6 +93,7 @@ namespace OpenSim.Framework.Servers.HttpServer
83 m_WorkerThreadCount = pWorkerThreadCount; 93 m_WorkerThreadCount = pWorkerThreadCount;
84 m_workerThreads = new Thread[m_WorkerThreadCount]; 94 m_workerThreads = new Thread[m_WorkerThreadCount];
85 95
96<<<<<<< HEAD
86 StatsManager.RegisterStat( 97 StatsManager.RegisterStat(
87 new Stat( 98 new Stat(
88 "QueuedPollResponses", 99 "QueuedPollResponses",
@@ -108,10 +119,25 @@ namespace OpenSim.Framework.Servers.HttpServer
108 MeasuresOfInterest.AverageChangeOverTime, 119 MeasuresOfInterest.AverageChangeOverTime,
109 stat => stat.Value = ResponsesProcessed, 120 stat => stat.Value = ResponsesProcessed,
110 StatVerbosity.Debug)); 121 StatVerbosity.Debug));
122=======
123 PollServiceHttpRequestComparer preqCp = new PollServiceHttpRequestComparer();
124 m_bycontext = new Dictionary<PollServiceHttpRequest, Queue<PollServiceHttpRequest>>(preqCp);
125
126 STPStartInfo startInfo = new STPStartInfo();
127 startInfo.IdleTimeout = 30000;
128 startInfo.MaxWorkerThreads = 15;
129 startInfo.MinWorkerThreads = 1;
130 startInfo.ThreadPriority = ThreadPriority.Normal;
131 startInfo.StartSuspended = true;
132 startInfo.ThreadPoolName = "PoolService";
133
134 m_threadPool = new SmartThreadPool(startInfo);
135>>>>>>> avn/ubitvar
111 } 136 }
112 137
113 public void Start() 138 public void Start()
114 { 139 {
140<<<<<<< HEAD
115 IsRunning = true; 141 IsRunning = true;
116 142
117 if (PerformResponsesAsync) 143 if (PerformResponsesAsync)
@@ -139,40 +165,100 @@ namespace OpenSim.Framework.Servers.HttpServer
139 null, 165 null,
140 1000 * 60 * 10); 166 1000 * 60 * 10);
141 } 167 }
168=======
169 m_threadPool.Start();
170 //startup worker threads
171 for (uint i = 0; i < m_WorkerThreadCount; i++)
172 {
173 m_workerThreads[i]
174 = Watchdog.StartThread(
175 PoolWorkerJob,
176 string.Format("PollServiceWorkerThread {0}:{1}", i, m_server.Port),
177 ThreadPriority.Normal,
178 false,
179 false,
180 null,
181 int.MaxValue);
182 }
183
184 m_retrysThread = Watchdog.StartThread(
185 this.CheckRetries,
186 string.Format("PollServiceWatcherThread:{0}", m_server.Port),
187 ThreadPriority.Normal,
188 false,
189 true,
190 null,
191 1000 * 60 * 10);
192>>>>>>> avn/ubitvar
142 } 193 }
143 194
144 private void ReQueueEvent(PollServiceHttpRequest req) 195 private void ReQueueEvent(PollServiceHttpRequest req)
145 { 196 {
146 if (IsRunning) 197 if (IsRunning)
147 { 198 {
148 // delay the enqueueing for 100ms. There's no need to have the event 199 lock (m_retryRequests)
149 // actively on the queue 200 m_retryRequests.Enqueue(req);
150 Timer t = new Timer(self => { 201 }
151 ((Timer)self).Dispose(); 202 }
152 m_requests.Enqueue(req);
153 });
154 203
155 t.Change(100, Timeout.Infinite); 204 public void Enqueue(PollServiceHttpRequest req)
205 {
206 lock (m_bycontext)
207 {
208 Queue<PollServiceHttpRequest> ctxQeueue;
209 if (m_bycontext.TryGetValue(req, out ctxQeueue))
210 {
211 ctxQeueue.Enqueue(req);
212 }
213 else
214 {
215 ctxQeueue = new Queue<PollServiceHttpRequest>();
216 m_bycontext[req] = ctxQeueue;
217 EnqueueInt(req);
218 }
219 }
220 }
156 221
222 public void byContextDequeue(PollServiceHttpRequest req)
223 {
224 Queue<PollServiceHttpRequest> ctxQeueue;
225 lock (m_bycontext)
226 {
227 if (m_bycontext.TryGetValue(req, out ctxQeueue))
228 {
229 if (ctxQeueue.Count > 0)
230 {
231 PollServiceHttpRequest newreq = ctxQeueue.Dequeue();
232 EnqueueInt(newreq);
233 }
234 else
235 {
236 m_bycontext.Remove(req);
237 }
238 }
157 } 239 }
158 } 240 }
159 241
160 public void Enqueue(PollServiceHttpRequest req) 242
243 public void EnqueueInt(PollServiceHttpRequest req)
161 { 244 {
162 if (IsRunning) 245 if (IsRunning)
163 { 246 {
164 if (req.PollServiceArgs.Type == PollServiceEventArgs.EventType.LongPoll) 247 if (req.PollServiceArgs.Type != PollServiceEventArgs.EventType.LongPoll)
165 { 248 {
166 lock (m_longPollRequests) 249 m_requests.Enqueue(req);
167 m_longPollRequests.Add(req);
168 } 250 }
169 else 251 else
170 m_requests.Enqueue(req); 252 {
253 lock (m_slowRequests)
254 m_slowRequests.Enqueue(req);
255 }
171 } 256 }
172 } 257 }
173 258
174 private void CheckLongPollThreads() 259 private void CheckRetries()
175 { 260 {
261<<<<<<< HEAD
176 // The only purpose of this thread is to check the EQs for events. 262 // The only purpose of this thread is to check the EQs for events.
177 // If there are events, that thread will be placed in the "ready-to-serve" queue, m_requests. 263 // If there are events, that thread will be placed in the "ready-to-serve" queue, m_requests.
178 // If there are no events, that thread will be back to its "waiting" queue, m_longPollRequests. 264 // If there are no events, that thread will be back to its "waiting" queue, m_longPollRequests.
@@ -180,13 +266,15 @@ namespace OpenSim.Framework.Servers.HttpServer
180 // so if they aren't ready to be served by a worker thread (no events), they are placed 266 // so if they aren't ready to be served by a worker thread (no events), they are placed
181 // directly back in the "ready-to-serve" queue by the worker thread. 267 // directly back in the "ready-to-serve" queue by the worker thread.
182 while (IsRunning) 268 while (IsRunning)
269=======
270 while (m_running)
271>>>>>>> avn/ubitvar
183 { 272 {
184 Thread.Sleep(500); 273 Thread.Sleep(100); // let the world move .. back to faster rate
185 Watchdog.UpdateThread(); 274 Watchdog.UpdateThread();
186 275 lock (m_retryRequests)
187// List<PollServiceHttpRequest> not_ready = new List<PollServiceHttpRequest>();
188 lock (m_longPollRequests)
189 { 276 {
277<<<<<<< HEAD
190 if (m_longPollRequests.Count > 0 && IsRunning) 278 if (m_longPollRequests.Count > 0 && IsRunning)
191 { 279 {
192 List<PollServiceHttpRequest> ready = m_longPollRequests.FindAll(req => 280 List<PollServiceHttpRequest> ready = m_longPollRequests.FindAll(req =>
@@ -199,28 +287,67 @@ namespace OpenSim.Framework.Servers.HttpServer
199 m_requests.Enqueue(req); 287 m_requests.Enqueue(req);
200 m_longPollRequests.Remove(req); 288 m_longPollRequests.Remove(req);
201 }); 289 });
290=======
291 while (m_retryRequests.Count > 0 && m_running)
292 m_requests.Enqueue(m_retryRequests.Dequeue());
293 }
294 slowCount++;
295 if (slowCount >= 10)
296 {
297 slowCount = 0;
298>>>>>>> avn/ubitvar
202 299
300 lock (m_slowRequests)
301 {
302 while (m_slowRequests.Count > 0 && m_running)
303 m_requests.Enqueue(m_slowRequests.Dequeue());
203 } 304 }
204
205 } 305 }
206 } 306 }
207 } 307 }
208 308
209 public void Stop() 309 public void Stop()
210 { 310 {
311<<<<<<< HEAD
211 IsRunning = false; 312 IsRunning = false;
212// m_timeout = -10000; // cause all to expire 313// m_timeout = -10000; // cause all to expire
314=======
315 m_running = false;
316>>>>>>> avn/ubitvar
213 Thread.Sleep(1000); // let the world move 317 Thread.Sleep(1000); // let the world move
214 318
215 foreach (Thread t in m_workerThreads) 319 foreach (Thread t in m_workerThreads)
216 Watchdog.AbortThread(t.ManagedThreadId); 320 Watchdog.AbortThread(t.ManagedThreadId);
217 321
322 // any entry in m_bycontext should have a active request on the other queues
323 // so just delete contents to easy GC
324 foreach (Queue<PollServiceHttpRequest> qu in m_bycontext.Values)
325 qu.Clear();
326 m_bycontext.Clear();
327
328 try
329 {
330 foreach (PollServiceHttpRequest req in m_retryRequests)
331 {
332 req.DoHTTPstop(m_server);
333 }
334 }
335 catch
336 {
337 }
338
218 PollServiceHttpRequest wreq; 339 PollServiceHttpRequest wreq;
340 m_retryRequests.Clear();
219 341
220 lock (m_longPollRequests) 342 lock (m_slowRequests)
221 { 343 {
344<<<<<<< HEAD
222 if (m_longPollRequests.Count > 0 && IsRunning) 345 if (m_longPollRequests.Count > 0 && IsRunning)
223 m_longPollRequests.ForEach(req => m_requests.Enqueue(req)); 346 m_longPollRequests.ForEach(req => m_requests.Enqueue(req));
347=======
348 while (m_slowRequests.Count > 0)
349 m_requests.Enqueue(m_slowRequests.Dequeue());
350>>>>>>> avn/ubitvar
224 } 351 }
225 352
226 while (m_requests.Count() > 0) 353 while (m_requests.Count() > 0)
@@ -228,16 +355,19 @@ namespace OpenSim.Framework.Servers.HttpServer
228 try 355 try
229 { 356 {
230 wreq = m_requests.Dequeue(0); 357 wreq = m_requests.Dequeue(0);
358<<<<<<< HEAD
231 ResponsesProcessed++; 359 ResponsesProcessed++;
232 wreq.DoHTTPGruntWork( 360 wreq.DoHTTPGruntWork(
233 m_server, wreq.PollServiceArgs.NoEvents(wreq.RequestID, wreq.PollServiceArgs.Id)); 361 m_server, wreq.PollServiceArgs.NoEvents(wreq.RequestID, wreq.PollServiceArgs.Id));
362=======
363 wreq.DoHTTPstop(m_server);
364>>>>>>> avn/ubitvar
234 } 365 }
235 catch 366 catch
236 { 367 {
237 } 368 }
238 } 369 }
239 370
240 m_longPollRequests.Clear();
241 m_requests.Clear(); 371 m_requests.Clear();
242 } 372 }
243 373
@@ -247,6 +377,11 @@ namespace OpenSim.Framework.Servers.HttpServer
247 { 377 {
248 while (IsRunning) 378 while (IsRunning)
249 { 379 {
380<<<<<<< HEAD
381=======
382 PollServiceHttpRequest req = m_requests.Dequeue(5000);
383
384>>>>>>> avn/ubitvar
250 Watchdog.UpdateThread(); 385 Watchdog.UpdateThread();
251 WaitPerformResponse(); 386 WaitPerformResponse();
252 } 387 }
@@ -265,6 +400,7 @@ namespace OpenSim.Framework.Servers.HttpServer
265 { 400 {
266 Hashtable responsedata = req.PollServiceArgs.GetEvents(req.RequestID, req.PollServiceArgs.Id); 401 Hashtable responsedata = req.PollServiceArgs.GetEvents(req.RequestID, req.PollServiceArgs.Id);
267 402
403<<<<<<< HEAD
268 if (responsedata == null) 404 if (responsedata == null)
269 return; 405 return;
270 406
@@ -287,11 +423,15 @@ namespace OpenSim.Framework.Servers.HttpServer
287 else 423 else
288 { 424 {
289 m_threadPool.QueueWorkItem(x => 425 m_threadPool.QueueWorkItem(x =>
426=======
427 if (req.PollServiceArgs.Type == PollServiceEventArgs.EventType.LongPoll) // This is the event queue
428>>>>>>> avn/ubitvar
290 { 429 {
291 try 430 try
292 { 431 {
293 ResponsesProcessed++; 432 ResponsesProcessed++;
294 req.DoHTTPGruntWork(m_server, responsedata); 433 req.DoHTTPGruntWork(m_server, responsedata);
434 byContextDequeue(req);
295 } 435 }
296 catch (ObjectDisposedException e) // Browser aborted before we could read body, server closed the stream 436 catch (ObjectDisposedException e) // Browser aborted before we could read body, server closed the stream
297 { 437 {
@@ -300,6 +440,7 @@ namespace OpenSim.Framework.Servers.HttpServer
300 } 440 }
301 catch (Exception e) 441 catch (Exception e)
302 { 442 {
443<<<<<<< HEAD
303 m_log.Error(e); 444 m_log.Error(e);
304 } 445 }
305 446
@@ -318,6 +459,34 @@ namespace OpenSim.Framework.Servers.HttpServer
318 else 459 else
319 { 460 {
320 ReQueueEvent(req); 461 ReQueueEvent(req);
462=======
463 try
464 {
465 req.DoHTTPGruntWork(m_server, responsedata);
466 byContextDequeue(req);
467 }
468 catch (ObjectDisposedException) // Browser aborted before we could read body, server closed the stream
469 {
470 // Ignore it, no need to reply
471 }
472
473 return null;
474 }, null);
475 }
476 }
477 else
478 {
479 if ((Environment.TickCount - req.RequestTime) > req.PollServiceArgs.TimeOutms)
480 {
481 req.DoHTTPGruntWork(m_server,
482 req.PollServiceArgs.NoEvents(req.RequestID, req.PollServiceArgs.Id));
483 byContextDequeue(req);
484 }
485 else
486 {
487 ReQueueEvent(req);
488 }
489>>>>>>> avn/ubitvar
321 } 490 }
322 } 491 }
323 } 492 }
@@ -327,5 +496,7 @@ namespace OpenSim.Framework.Servers.HttpServer
327 } 496 }
328 } 497 }
329 } 498 }
499
330 } 500 }
331} \ No newline at end of file 501}
502
diff --git a/OpenSim/Framework/Servers/ServerBase.cs b/OpenSim/Framework/Servers/ServerBase.cs
index e403ba0..35177f4 100644
--- a/OpenSim/Framework/Servers/ServerBase.cs
+++ b/OpenSim/Framework/Servers/ServerBase.cs
@@ -871,7 +871,7 @@ namespace OpenSim.Framework.Servers
871 } 871 }
872 } 872 }
873 873
874 protected string GetVersionText() 874 public string GetVersionText()
875 { 875 {
876 return String.Format("Version: {0} (interface version {1})", m_version, VersionInfo.MajorInterfaceVersion); 876 return String.Format("Version: {0} (interface version {1})", m_version, VersionInfo.MajorInterfaceVersion);
877 } 877 }
@@ -1044,4 +1044,4 @@ namespace OpenSim.Framework.Servers
1044 /// </summary> 1044 /// </summary>
1045 protected virtual void ShutdownSpecific() {} 1045 protected virtual void ShutdownSpecific() {}
1046 } 1046 }
1047} \ No newline at end of file 1047}
diff --git a/OpenSim/Framework/Servers/Tests/OSHttpTests.cs b/OpenSim/Framework/Servers/Tests/OSHttpTests.cs
index 5c0e0df..e13551c 100644
--- a/OpenSim/Framework/Servers/Tests/OSHttpTests.cs
+++ b/OpenSim/Framework/Servers/Tests/OSHttpTests.cs
@@ -41,7 +41,331 @@ namespace OpenSim.Framework.Servers.Tests
41{ 41{
42 [TestFixture] 42 [TestFixture]
43 public class OSHttpTests : OpenSimTestCase 43 public class OSHttpTests : OpenSimTestCase
44<<<<<<< HEAD
44 { 45 {
46=======
47 {
48 // we need an IHttpClientContext for our tests
49 public class TestHttpClientContext: IHttpClientContext
50 {
51 private bool _secured;
52 public bool IsSecured
53 {
54 get { return _secured; }
55 }
56 public bool Secured
57 {
58 get { return _secured; }
59 }
60
61 public TestHttpClientContext(bool secured)
62 {
63 _secured = secured;
64 }
65
66 public void Disconnect(SocketError error) {}
67 public void Respond(string httpVersion, HttpStatusCode statusCode, string reason, string body) {}
68 public void Respond(string httpVersion, HttpStatusCode statusCode, string reason) {}
69 public void Respond(string body) {}
70 public void Send(byte[] buffer) {}
71 public void Send(byte[] buffer, int offset, int size) {}
72 public void Respond(string httpVersion, HttpStatusCode statusCode, string reason, string body, string contentType) {}
73 public void Close() { }
74 public bool EndWhenDone { get { return false;} set { return;}}
75
76 public HTTPNetworkContext GiveMeTheNetworkStreamIKnowWhatImDoing()
77 {
78 return new HTTPNetworkContext();
79 }
80
81 public event EventHandler<DisconnectedEventArgs> Disconnected = delegate { };
82 /// <summary>
83 /// A request have been received in the context.
84 /// </summary>
85 public event EventHandler<RequestEventArgs> RequestReceived = delegate { };
86
87 public bool CanSend { get { return true; } }
88 public string RemoteEndPoint { get { return ""; } }
89 public string RemoteEndPointAddress { get { return ""; } }
90 public string RemoteEndPointPort { get { return ""; } }
91 }
92
93 public class TestHttpRequest: IHttpRequest
94 {
95 private string _uriPath;
96 public bool BodyIsComplete
97 {
98 get { return true; }
99 }
100 public string[] AcceptTypes
101 {
102 get {return _acceptTypes; }
103 }
104 private string[] _acceptTypes;
105 public Stream Body
106 {
107 get { return _body; }
108 set { _body = value;}
109 }
110 private Stream _body;
111 public ConnectionType Connection
112 {
113 get { return _connection; }
114 set { _connection = value; }
115 }
116 private ConnectionType _connection;
117 public int ContentLength
118 {
119 get { return _contentLength; }
120 set { _contentLength = value; }
121 }
122 private int _contentLength;
123 public NameValueCollection Headers
124 {
125 get { return _headers; }
126 }
127 private NameValueCollection _headers = new NameValueCollection();
128 public string HttpVersion
129 {
130 get { return _httpVersion; }
131 set { _httpVersion = value; }
132 }
133 private string _httpVersion = null;
134 public string Method
135 {
136 get { return _method; }
137 set { _method = value; }
138 }
139 private string _method = null;
140 public HttpInput QueryString
141 {
142 get { return _queryString; }
143 }
144 private HttpInput _queryString = null;
145 public Uri Uri
146 {
147 get { return _uri; }
148 set { _uri = value; }
149 }
150 private Uri _uri = null;
151 public string[] UriParts
152 {
153 get { return _uri.Segments; }
154 }
155 public HttpParam Param
156 {
157 get { return null; }
158 }
159 public HttpForm Form
160 {
161 get { return null; }
162 }
163 public bool IsAjax
164 {
165 get { return false; }
166 }
167 public RequestCookies Cookies
168 {
169 get { return null; }
170 }
171
172 public TestHttpRequest() {}
173
174 public TestHttpRequest(string contentEncoding, string contentType, string userAgent,
175 string remoteAddr, string remotePort, string[] acceptTypes,
176 ConnectionType connectionType, int contentLength, Uri uri)
177 {
178 _headers["content-encoding"] = contentEncoding;
179 _headers["content-type"] = contentType;
180 _headers["user-agent"] = userAgent;
181 _headers["remote_addr"] = remoteAddr;
182 _headers["remote_port"] = remotePort;
183
184 _acceptTypes = acceptTypes;
185 _connection = connectionType;
186 _contentLength = contentLength;
187 _uri = uri;
188 }
189
190 public void DecodeBody(FormDecoderProvider providers) {}
191 public void SetCookies(RequestCookies cookies) {}
192 public void AddHeader(string name, string value)
193 {
194 _headers.Add(name, value);
195 }
196 public int AddToBody(byte[] bytes, int offset, int length)
197 {
198 return 0;
199 }
200 public void Clear() {}
201
202 public object Clone()
203 {
204 TestHttpRequest clone = new TestHttpRequest();
205 clone._acceptTypes = _acceptTypes;
206 clone._connection = _connection;
207 clone._contentLength = _contentLength;
208 clone._uri = _uri;
209 clone._headers = new NameValueCollection(_headers);
210
211 return clone;
212 }
213 public IHttpResponse CreateResponse(IHttpClientContext context)
214 {
215 return new HttpResponse(context, this);
216 }
217 /// <summary>
218 /// Path and query (will be merged with the host header) and put in Uri
219 /// </summary>
220 /// <see cref="Uri"/>
221 public string UriPath
222 {
223 get { return _uriPath; }
224 set
225 {
226 _uriPath = value;
227
228 }
229 }
230
231 }
232
233 public class TestHttpResponse: IHttpResponse
234 {
235 public Stream Body
236 {
237 get { return _body; }
238
239 set { _body = value; }
240 }
241 private Stream _body;
242
243 public string ProtocolVersion
244 {
245 get { return _protocolVersion; }
246 set { _protocolVersion = value; }
247 }
248 private string _protocolVersion;
249
250 public bool Chunked
251 {
252 get { return _chunked; }
253
254 set { _chunked = value; }
255 }
256 private bool _chunked;
257
258 public ConnectionType Connection
259 {
260 get { return _connection; }
261
262 set { _connection = value; }
263 }
264 private ConnectionType _connection;
265
266 public Encoding Encoding
267 {
268 get { return _encoding; }
269
270 set { _encoding = value; }
271 }
272 private Encoding _encoding;
273
274 public int KeepAlive
275 {
276 get { return _keepAlive; }
277
278 set { _keepAlive = value; }
279 }
280 private int _keepAlive;
281
282 public HttpStatusCode Status
283 {
284 get { return _status; }
285
286 set { _status = value; }
287 }
288 private HttpStatusCode _status;
289
290 public string Reason
291 {
292 get { return _reason; }
293
294 set { _reason = value; }
295 }
296 private string _reason;
297
298 public long ContentLength
299 {
300 get { return _contentLength; }
301
302 set { _contentLength = value; }
303 }
304 private long _contentLength;
305
306 public string ContentType
307 {
308 get { return _contentType; }
309
310 set { _contentType = value; }
311 }
312 private string _contentType;
313
314 public bool HeadersSent
315 {
316 get { return _headersSent; }
317 }
318 private bool _headersSent;
319
320 public bool Sent
321 {
322 get { return _sent; }
323 }
324 private bool _sent;
325
326 public ResponseCookies Cookies
327 {
328 get { return _cookies; }
329 }
330 private ResponseCookies _cookies = null;
331
332 public TestHttpResponse()
333 {
334 _headersSent = false;
335 _sent = false;
336 }
337
338 public void AddHeader(string name, string value) {}
339 public void Send()
340 {
341 if (!_headersSent) SendHeaders();
342 if (_sent) throw new InvalidOperationException("stuff already sent");
343 _sent = true;
344 }
345
346 public void SendBody(byte[] buffer, int offset, int count)
347 {
348 if (!_headersSent) SendHeaders();
349 _sent = true;
350 }
351 public void SendBody(byte[] buffer)
352 {
353 if (!_headersSent) SendHeaders();
354 _sent = true;
355 }
356
357 public void SendHeaders()
358 {
359 if (_headersSent) throw new InvalidOperationException("headers already sent");
360 _headersSent = true;
361 }
362
363 public void Redirect(Uri uri) {}
364 public void Redirect(string url) {}
365 }
366
367
368>>>>>>> avn/ubitvar
45 public OSHttpRequest req0; 369 public OSHttpRequest req0;
46 public OSHttpRequest req1; 370 public OSHttpRequest req1;
47 371
@@ -113,4 +437,4 @@ namespace OpenSim.Framework.Servers.Tests
113 Assert.That(rsp0.ContentType, Is.EqualTo("text/xml")); 437 Assert.That(rsp0.ContentType, Is.EqualTo("text/xml"));
114 } 438 }
115 } 439 }
116} \ No newline at end of file 440}