diff options
Diffstat (limited to 'OpenSim/Region/CoreModules/Scripting/HttpRequest/ScriptsHttpRequests.cs')
-rw-r--r-- | OpenSim/Region/CoreModules/Scripting/HttpRequest/ScriptsHttpRequests.cs | 65 |
1 files changed, 51 insertions, 14 deletions
diff --git a/OpenSim/Region/CoreModules/Scripting/HttpRequest/ScriptsHttpRequests.cs b/OpenSim/Region/CoreModules/Scripting/HttpRequest/ScriptsHttpRequests.cs index a0ae203..0276267 100644 --- a/OpenSim/Region/CoreModules/Scripting/HttpRequest/ScriptsHttpRequests.cs +++ b/OpenSim/Region/CoreModules/Scripting/HttpRequest/ScriptsHttpRequests.cs | |||
@@ -42,6 +42,7 @@ using OpenSim.Framework.Servers.HttpServer; | |||
42 | using OpenSim.Region.Framework.Interfaces; | 42 | using OpenSim.Region.Framework.Interfaces; |
43 | using OpenSim.Region.Framework.Scenes; | 43 | using OpenSim.Region.Framework.Scenes; |
44 | using Mono.Addins; | 44 | using Mono.Addins; |
45 | using Amib.Threading; | ||
45 | 46 | ||
46 | /***************************************************** | 47 | /***************************************************** |
47 | * | 48 | * |
@@ -102,6 +103,7 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest | |||
102 | private Dictionary<UUID, HttpRequestClass> m_pendingRequests; | 103 | private Dictionary<UUID, HttpRequestClass> m_pendingRequests; |
103 | private Scene m_scene; | 104 | private Scene m_scene; |
104 | // private Queue<HttpRequestClass> rpcQueue = new Queue<HttpRequestClass>(); | 105 | // private Queue<HttpRequestClass> rpcQueue = new Queue<HttpRequestClass>(); |
106 | public static SmartThreadPool ThreadPool = null; | ||
105 | 107 | ||
106 | public HttpRequestModule() | 108 | public HttpRequestModule() |
107 | { | 109 | { |
@@ -279,7 +281,30 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest | |||
279 | m_proxyurl = config.Configs["Startup"].GetString("HttpProxy"); | 281 | m_proxyurl = config.Configs["Startup"].GetString("HttpProxy"); |
280 | m_proxyexcepts = config.Configs["Startup"].GetString("HttpProxyExceptions"); | 282 | m_proxyexcepts = config.Configs["Startup"].GetString("HttpProxyExceptions"); |
281 | 283 | ||
284 | int maxThreads = 50; | ||
285 | |||
286 | IConfig httpConfig = config.Configs["HttpRequestModule"]; | ||
287 | if (httpConfig != null) | ||
288 | { | ||
289 | maxThreads = httpConfig.GetInt("MaxPoolThreads", maxThreads); | ||
290 | } | ||
291 | |||
282 | m_pendingRequests = new Dictionary<UUID, HttpRequestClass>(); | 292 | m_pendingRequests = new Dictionary<UUID, HttpRequestClass>(); |
293 | |||
294 | // First instance sets this up for all sims | ||
295 | if (ThreadPool == null) | ||
296 | { | ||
297 | STPStartInfo startInfo = new STPStartInfo(); | ||
298 | startInfo.IdleTimeout = 20000; | ||
299 | startInfo.MaxWorkerThreads = maxThreads; | ||
300 | startInfo.MinWorkerThreads = 5; | ||
301 | startInfo.ThreadPriority = ThreadPriority.BelowNormal; | ||
302 | startInfo.StartSuspended = true; | ||
303 | |||
304 | ThreadPool = new SmartThreadPool(startInfo); | ||
305 | |||
306 | ThreadPool.Start(); | ||
307 | } | ||
283 | } | 308 | } |
284 | 309 | ||
285 | public void AddRegion(Scene scene) | 310 | public void AddRegion(Scene scene) |
@@ -340,7 +365,7 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest | |||
340 | public string HttpMIMEType = "text/plain;charset=utf-8"; | 365 | public string HttpMIMEType = "text/plain;charset=utf-8"; |
341 | public int HttpTimeout; | 366 | public int HttpTimeout; |
342 | public bool HttpVerifyCert = true; | 367 | public bool HttpVerifyCert = true; |
343 | private Thread httpThread; | 368 | public IWorkItemResult WorkItem = null; |
344 | 369 | ||
345 | // Request info | 370 | // Request info |
346 | private UUID _itemID; | 371 | private UUID _itemID; |
@@ -374,12 +399,16 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest | |||
374 | 399 | ||
375 | public void Process() | 400 | public void Process() |
376 | { | 401 | { |
377 | httpThread = new Thread(SendRequest); | ||
378 | httpThread.Name = "HttpRequestThread"; | ||
379 | httpThread.Priority = ThreadPriority.BelowNormal; | ||
380 | httpThread.IsBackground = true; | ||
381 | _finished = false; | 402 | _finished = false; |
382 | httpThread.Start(); | 403 | |
404 | lock (HttpRequestModule.ThreadPool) | ||
405 | WorkItem = HttpRequestModule.ThreadPool.QueueWorkItem(new WorkItemCallback(StpSendWrapper), null); | ||
406 | } | ||
407 | |||
408 | private object StpSendWrapper(object o) | ||
409 | { | ||
410 | SendRequest(); | ||
411 | return null; | ||
383 | } | 412 | } |
384 | 413 | ||
385 | /* | 414 | /* |
@@ -409,13 +438,8 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest | |||
409 | { | 438 | { |
410 | // We could hijack Connection Group Name to identify | 439 | // We could hijack Connection Group Name to identify |
411 | // a desired security exception. But at the moment we'll use a dummy header instead. | 440 | // a desired security exception. But at the moment we'll use a dummy header instead. |
412 | // Request.ConnectionGroupName = "NoVerify"; | ||
413 | Request.Headers.Add("NoVerifyCert", "true"); | 441 | Request.Headers.Add("NoVerifyCert", "true"); |
414 | } | 442 | } |
415 | // else | ||
416 | // { | ||
417 | // Request.ConnectionGroupName="Verify"; | ||
418 | // } | ||
419 | if (proxyurl != null && proxyurl.Length > 0) | 443 | if (proxyurl != null && proxyurl.Length > 0) |
420 | { | 444 | { |
421 | if (proxyexcepts != null && proxyexcepts.Length > 0) | 445 | if (proxyexcepts != null && proxyexcepts.Length > 0) |
@@ -485,9 +509,9 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest | |||
485 | 509 | ||
486 | ResponseBody = sb.ToString().Replace("\r", ""); | 510 | ResponseBody = sb.ToString().Replace("\r", ""); |
487 | } | 511 | } |
488 | catch (Exception e) | 512 | catch (WebException e) |
489 | { | 513 | { |
490 | if (e is WebException && ((WebException)e).Status == WebExceptionStatus.ProtocolError) | 514 | if (e.Status == WebExceptionStatus.ProtocolError) |
491 | { | 515 | { |
492 | HttpWebResponse webRsp = (HttpWebResponse)((WebException)e).Response; | 516 | HttpWebResponse webRsp = (HttpWebResponse)((WebException)e).Response; |
493 | Status = (int)webRsp.StatusCode; | 517 | Status = (int)webRsp.StatusCode; |
@@ -509,15 +533,25 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest | |||
509 | ResponseBody = e.Message; | 533 | ResponseBody = e.Message; |
510 | } | 534 | } |
511 | 535 | ||
536 | if (ResponseBody == null) | ||
537 | ResponseBody = String.Empty; | ||
538 | |||
512 | _finished = true; | 539 | _finished = true; |
513 | return; | 540 | return; |
514 | } | 541 | } |
542 | catch (Exception e) | ||
543 | { | ||
544 | // Don't crash on anything else | ||
545 | } | ||
515 | finally | 546 | finally |
516 | { | 547 | { |
517 | if (response != null) | 548 | if (response != null) |
518 | response.Close(); | 549 | response.Close(); |
519 | } | 550 | } |
520 | 551 | ||
552 | if (ResponseBody == null) | ||
553 | ResponseBody = String.Empty; | ||
554 | |||
521 | _finished = true; | 555 | _finished = true; |
522 | } | 556 | } |
523 | 557 | ||
@@ -525,7 +559,10 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest | |||
525 | { | 559 | { |
526 | try | 560 | try |
527 | { | 561 | { |
528 | httpThread.Abort(); | 562 | if (!WorkItem.Cancel()) |
563 | { | ||
564 | WorkItem.Abort(); | ||
565 | } | ||
529 | } | 566 | } |
530 | catch (Exception) | 567 | catch (Exception) |
531 | { | 568 | { |