diff options
Diffstat (limited to 'OpenSim/Framework')
-rw-r--r-- | OpenSim/Framework/RestClient.cs | 25 | ||||
-rw-r--r-- | OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs | 10 | ||||
-rw-r--r-- | OpenSim/Framework/Servers/ServerBase.cs | 48 | ||||
-rw-r--r-- | OpenSim/Framework/Util.cs | 184 | ||||
-rw-r--r-- | OpenSim/Framework/WebUtil.cs | 55 |
5 files changed, 128 insertions, 194 deletions
diff --git a/OpenSim/Framework/RestClient.cs b/OpenSim/Framework/RestClient.cs index 0166d9d..4939cf7 100644 --- a/OpenSim/Framework/RestClient.cs +++ b/OpenSim/Framework/RestClient.cs | |||
@@ -428,22 +428,23 @@ namespace OpenSim.Framework | |||
428 | if (WebUtil.DebugLevel >= 5) | 428 | if (WebUtil.DebugLevel >= 5) |
429 | WebUtil.LogOutgoingDetail(string.Format("SEND {0}: ", reqnum), src); | 429 | WebUtil.LogOutgoingDetail(string.Format("SEND {0}: ", reqnum), src); |
430 | 430 | ||
431 | using (Stream dst = _request.GetRequestStream()) | 431 | |
432 | try | ||
432 | { | 433 | { |
433 | m_log.Debug("[REST]: GetRequestStream is ok"); | 434 | using (Stream dst = _request.GetRequestStream()) |
434 | |||
435 | byte[] buf = new byte[1024]; | ||
436 | int length = src.Read(buf, 0, 1024); | ||
437 | m_log.Debug("[REST]: First Read is ok"); | ||
438 | while (length > 0) | ||
439 | { | 435 | { |
440 | dst.Write(buf, 0, length); | 436 | // m_log.Debug("[REST]: GetRequestStream is ok"); |
441 | length = src.Read(buf, 0, 1024); | 437 | |
438 | byte[] buf = new byte[1024]; | ||
439 | int length = src.Read(buf, 0, 1024); | ||
440 | // m_log.Debug("[REST]: First Read is ok"); | ||
441 | while (length > 0) | ||
442 | { | ||
443 | dst.Write(buf, 0, length); | ||
444 | length = src.Read(buf, 0, 1024); | ||
445 | } | ||
442 | } | 446 | } |
443 | } | ||
444 | 447 | ||
445 | try | ||
446 | { | ||
447 | _response = (HttpWebResponse)_request.GetResponse(); | 448 | _response = (HttpWebResponse)_request.GetResponse(); |
448 | } | 449 | } |
449 | catch (WebException e) | 450 | catch (WebException e) |
diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs index ffc6ad3..415c264 100644 --- a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs +++ b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs | |||
@@ -207,7 +207,6 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
207 | qu.Clear(); | 207 | qu.Clear(); |
208 | m_bycontext.Clear(); | 208 | m_bycontext.Clear(); |
209 | 209 | ||
210 | /* | ||
211 | try | 210 | try |
212 | { | 211 | { |
213 | foreach (PollServiceHttpRequest req in m_retryRequests) | 212 | foreach (PollServiceHttpRequest req in m_retryRequests) |
@@ -220,22 +219,21 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
220 | } | 219 | } |
221 | 220 | ||
222 | PollServiceHttpRequest wreq; | 221 | PollServiceHttpRequest wreq; |
223 | */ | 222 | |
224 | m_retryRequests.Clear(); | 223 | m_retryRequests.Clear(); |
225 | /* | 224 | |
226 | while (m_requests.Count() > 0) | 225 | while (m_requests.Count() > 0) |
227 | { | 226 | { |
228 | try | 227 | try |
229 | { | 228 | { |
230 | wreq = m_requests.Dequeue(0); | 229 | wreq = m_requests.Dequeue(0); |
231 | wreq.DoHTTPstop(m_server); | 230 | wreq.DoHTTPstop(m_server); |
232 | |||
233 | } | 231 | } |
234 | catch | 232 | catch |
235 | { | 233 | { |
236 | } | 234 | } |
237 | } | 235 | } |
238 | */ | 236 | |
239 | m_requests.Clear(); | 237 | m_requests.Clear(); |
240 | } | 238 | } |
241 | 239 | ||
@@ -245,7 +243,7 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
245 | { | 243 | { |
246 | while (m_running) | 244 | while (m_running) |
247 | { | 245 | { |
248 | PollServiceHttpRequest req = m_requests.Dequeue(5000); | 246 | PollServiceHttpRequest req = m_requests.Dequeue(4500); |
249 | Watchdog.UpdateThread(); | 247 | Watchdog.UpdateThread(); |
250 | if(req == null) | 248 | if(req == null) |
251 | continue; | 249 | continue; |
diff --git a/OpenSim/Framework/Servers/ServerBase.cs b/OpenSim/Framework/Servers/ServerBase.cs index f627ae6..3bb2313 100644 --- a/OpenSim/Framework/Servers/ServerBase.cs +++ b/OpenSim/Framework/Servers/ServerBase.cs | |||
@@ -275,18 +275,6 @@ namespace OpenSim.Framework.Servers | |||
275 | (string module, string[] args) => Notice(GetThreadsReport())); | 275 | (string module, string[] args) => Notice(GetThreadsReport())); |
276 | 276 | ||
277 | m_console.Commands.AddCommand ( | 277 | m_console.Commands.AddCommand ( |
278 | "Debug", false, "debug comms set", | ||
279 | "debug comms set serialosdreq true|false", | ||
280 | "Set comms parameters. For debug purposes.", | ||
281 | HandleDebugCommsSet); | ||
282 | |||
283 | m_console.Commands.AddCommand ( | ||
284 | "Debug", false, "debug comms status", | ||
285 | "debug comms status", | ||
286 | "Show current debug comms parameters.", | ||
287 | HandleDebugCommsStatus); | ||
288 | |||
289 | m_console.Commands.AddCommand ( | ||
290 | "Debug", false, "debug threadpool set", | 278 | "Debug", false, "debug threadpool set", |
291 | "debug threadpool set worker|iocp min|max <n>", | 279 | "debug threadpool set worker|iocp min|max <n>", |
292 | "Set threadpool parameters. For debug purposes.", | 280 | "Set threadpool parameters. For debug purposes.", |
@@ -343,47 +331,13 @@ namespace OpenSim.Framework.Servers | |||
343 | 331 | ||
344 | public void RegisterCommonComponents(IConfigSource configSource) | 332 | public void RegisterCommonComponents(IConfigSource configSource) |
345 | { | 333 | { |
346 | IConfig networkConfig = configSource.Configs["Network"]; | 334 | // IConfig networkConfig = configSource.Configs["Network"]; |
347 | |||
348 | if (networkConfig != null) | ||
349 | { | ||
350 | WebUtil.SerializeOSDRequestsPerEndpoint = networkConfig.GetBoolean("SerializeOSDRequests", false); | ||
351 | } | ||
352 | 335 | ||
353 | m_serverStatsCollector = new ServerStatsCollector(); | 336 | m_serverStatsCollector = new ServerStatsCollector(); |
354 | m_serverStatsCollector.Initialise(configSource); | 337 | m_serverStatsCollector.Initialise(configSource); |
355 | m_serverStatsCollector.Start(); | 338 | m_serverStatsCollector.Start(); |
356 | } | 339 | } |
357 | 340 | ||
358 | private void HandleDebugCommsStatus(string module, string[] args) | ||
359 | { | ||
360 | Notice("serialosdreq is {0}", WebUtil.SerializeOSDRequestsPerEndpoint); | ||
361 | } | ||
362 | |||
363 | private void HandleDebugCommsSet(string module, string[] args) | ||
364 | { | ||
365 | if (args.Length != 5) | ||
366 | { | ||
367 | Notice("Usage: debug comms set serialosdreq true|false"); | ||
368 | return; | ||
369 | } | ||
370 | |||
371 | if (args[3] != "serialosdreq") | ||
372 | { | ||
373 | Notice("Usage: debug comms set serialosdreq true|false"); | ||
374 | return; | ||
375 | } | ||
376 | |||
377 | bool setSerializeOsdRequests; | ||
378 | |||
379 | if (!ConsoleUtil.TryParseConsoleBool(m_console, args[4], out setSerializeOsdRequests)) | ||
380 | return; | ||
381 | |||
382 | WebUtil.SerializeOSDRequestsPerEndpoint = setSerializeOsdRequests; | ||
383 | |||
384 | Notice("serialosdreq is now {0}", setSerializeOsdRequests); | ||
385 | } | ||
386 | |||
387 | private void HandleShowThreadpoolCallsActive(string module, string[] args) | 341 | private void HandleShowThreadpoolCallsActive(string module, string[] args) |
388 | { | 342 | { |
389 | List<KeyValuePair<string, int>> calls = Util.GetFireAndForgetCallsInProgress().ToList(); | 343 | List<KeyValuePair<string, int>> calls = Util.GetFireAndForgetCallsInProgress().ToList(); |
diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs index 83d9df1..f52a84c 100644 --- a/OpenSim/Framework/Util.cs +++ b/OpenSim/Framework/Util.cs | |||
@@ -429,64 +429,6 @@ namespace OpenSim.Framework | |||
429 | return regionCoord << 8; | 429 | return regionCoord << 8; |
430 | } | 430 | } |
431 | 431 | ||
432 | public static IPEndPoint getEndPoint(IPAddress ia, int port) | ||
433 | { | ||
434 | if(ia == null) | ||
435 | return null; | ||
436 | |||
437 | IPEndPoint newEP = null; | ||
438 | try | ||
439 | { | ||
440 | newEP = new IPEndPoint(ia, port); | ||
441 | } | ||
442 | catch | ||
443 | { | ||
444 | newEP = null; | ||
445 | } | ||
446 | return newEP; | ||
447 | } | ||
448 | |||
449 | public static IPEndPoint getEndPoint(string hostname, int port) | ||
450 | { | ||
451 | IPAddress ia = null; | ||
452 | // If it is already an IP, don't resolve it - just return directly | ||
453 | // we should not need this | ||
454 | if (IPAddress.TryParse(hostname, out ia)) | ||
455 | { | ||
456 | if (ia.Equals(IPAddress.Any) || ia.Equals(IPAddress.IPv6Any)) | ||
457 | return null; | ||
458 | return getEndPoint(ia, port); | ||
459 | } | ||
460 | |||
461 | // Reset for next check | ||
462 | ia = null; | ||
463 | try | ||
464 | { | ||
465 | foreach (IPAddress Adr in Dns.GetHostAddresses(hostname)) | ||
466 | { | ||
467 | if (ia == null) | ||
468 | ia = Adr; | ||
469 | |||
470 | if (Adr.AddressFamily == AddressFamily.InterNetwork) | ||
471 | { | ||
472 | ia = Adr; | ||
473 | break; | ||
474 | } | ||
475 | } | ||
476 | } | ||
477 | catch // (SocketException e) | ||
478 | { | ||
479 | /*throw new Exception( | ||
480 | "Unable to resolve local hostname " + m_externalHostName + " innerException of type '" + | ||
481 | e + "' attached to this exception", e);*/ | ||
482 | // Don't throw a fatal exception here, instead, return Null and handle it in the caller. | ||
483 | // Reason is, on systems such as OSgrid it has occured that known hostnames stop | ||
484 | // resolving and thus make surrounding regions crash out with this exception. | ||
485 | return null; | ||
486 | } | ||
487 | |||
488 | return getEndPoint(ia,port); | ||
489 | } | ||
490 | 432 | ||
491 | public static bool checkServiceURI(string uristr, out string serviceURI) | 433 | public static bool checkServiceURI(string uristr, out string serviceURI) |
492 | { | 434 | { |
@@ -1049,6 +991,8 @@ namespace OpenSim.Framework | |||
1049 | return output.ToString(); | 991 | return output.ToString(); |
1050 | } | 992 | } |
1051 | 993 | ||
994 | private static ExpiringCache<string,IPAddress> dnscache = new ExpiringCache<string, IPAddress>(); | ||
995 | |||
1052 | /// <summary> | 996 | /// <summary> |
1053 | /// Converts a URL to a IPAddress | 997 | /// Converts a URL to a IPAddress |
1054 | /// </summary> | 998 | /// </summary> |
@@ -1066,38 +1010,128 @@ namespace OpenSim.Framework | |||
1066 | /// <returns>An IP address, or null</returns> | 1010 | /// <returns>An IP address, or null</returns> |
1067 | public static IPAddress GetHostFromDNS(string dnsAddress) | 1011 | public static IPAddress GetHostFromDNS(string dnsAddress) |
1068 | { | 1012 | { |
1069 | // Is it already a valid IP? No need to look it up. | 1013 | if(String.IsNullOrWhiteSpace(dnsAddress)) |
1070 | IPAddress ipa; | 1014 | return null; |
1071 | if (IPAddress.TryParse(dnsAddress, out ipa)) | ||
1072 | return ipa; | ||
1073 | 1015 | ||
1074 | IPAddress[] hosts = null; | 1016 | IPAddress ia = null; |
1017 | if(dnscache.TryGetValue(dnsAddress, out ia) && ia != null) | ||
1018 | { | ||
1019 | dnscache.AddOrUpdate(dnsAddress, ia, 300); | ||
1020 | return ia; | ||
1021 | } | ||
1022 | |||
1023 | ia = null; | ||
1024 | // If it is already an IP, don't let GetHostEntry see it | ||
1025 | if (IPAddress.TryParse(dnsAddress, out ia) && ia != null) | ||
1026 | { | ||
1027 | if (ia.Equals(IPAddress.Any) || ia.Equals(IPAddress.IPv6Any)) | ||
1028 | return null; | ||
1029 | dnscache.AddOrUpdate(dnsAddress, ia, 300); | ||
1030 | return ia; | ||
1031 | } | ||
1075 | 1032 | ||
1076 | // Not an IP, lookup required | 1033 | IPHostEntry IPH; |
1077 | try | 1034 | try |
1078 | { | 1035 | { |
1079 | hosts = Dns.GetHostEntry(dnsAddress).AddressList; | 1036 | IPH = Dns.GetHostEntry(dnsAddress); |
1080 | } | 1037 | } |
1081 | catch (Exception e) | 1038 | catch // (SocketException e) |
1082 | { | 1039 | { |
1083 | m_log.WarnFormat("[UTIL]: An error occurred while resolving host name {0}, {1}", dnsAddress, e); | 1040 | return null; |
1041 | } | ||
1042 | |||
1043 | if(IPH == null || IPH.AddressList.Length == 0) | ||
1044 | return null; | ||
1084 | 1045 | ||
1085 | // Still going to throw the exception on for now, since this was what was happening in the first place | 1046 | ia = null; |
1086 | throw e; | 1047 | foreach (IPAddress Adr in IPH.AddressList) |
1048 | { | ||
1049 | if (ia == null) | ||
1050 | ia = Adr; | ||
1051 | |||
1052 | if (Adr.AddressFamily == AddressFamily.InterNetwork) | ||
1053 | { | ||
1054 | ia = Adr; | ||
1055 | break; | ||
1056 | } | ||
1057 | } | ||
1058 | if(ia != null) | ||
1059 | dnscache.AddOrUpdate(dnsAddress, ia, 300); | ||
1060 | return ia; | ||
1061 | } | ||
1062 | |||
1063 | public static IPEndPoint getEndPoint(IPAddress ia, int port) | ||
1064 | { | ||
1065 | if(ia == null) | ||
1066 | return null; | ||
1067 | |||
1068 | IPEndPoint newEP = null; | ||
1069 | try | ||
1070 | { | ||
1071 | newEP = new IPEndPoint(ia, port); | ||
1072 | } | ||
1073 | catch | ||
1074 | { | ||
1075 | newEP = null; | ||
1076 | } | ||
1077 | return newEP; | ||
1078 | } | ||
1079 | |||
1080 | public static IPEndPoint getEndPoint(string hostname, int port) | ||
1081 | { | ||
1082 | if(String.IsNullOrWhiteSpace(hostname)) | ||
1083 | return null; | ||
1084 | |||
1085 | IPAddress ia = null; | ||
1086 | if(dnscache.TryGetValue(hostname, out ia) && ia != null) | ||
1087 | { | ||
1088 | dnscache.AddOrUpdate(hostname, ia, 300); | ||
1089 | return getEndPoint(ia, port); | ||
1087 | } | 1090 | } |
1088 | 1091 | ||
1089 | foreach (IPAddress host in hosts) | 1092 | ia = null; |
1093 | |||
1094 | // If it is already an IP, don't let GetHostEntry see it | ||
1095 | if (IPAddress.TryParse(hostname, out ia) && ia != null) | ||
1090 | { | 1096 | { |
1091 | if (host.AddressFamily == AddressFamily.InterNetwork) | 1097 | if (ia.Equals(IPAddress.Any) || ia.Equals(IPAddress.IPv6Any)) |
1098 | return null; | ||
1099 | |||
1100 | dnscache.AddOrUpdate(hostname, ia, 300); | ||
1101 | return getEndPoint(ia, port); | ||
1102 | } | ||
1103 | |||
1104 | |||
1105 | IPHostEntry IPH; | ||
1106 | try | ||
1107 | { | ||
1108 | IPH = Dns.GetHostEntry(hostname); | ||
1109 | } | ||
1110 | catch // (SocketException e) | ||
1111 | { | ||
1112 | return null; | ||
1113 | } | ||
1114 | |||
1115 | if(IPH == null || IPH.AddressList.Length == 0) | ||
1116 | return null; | ||
1117 | |||
1118 | ia = null; | ||
1119 | foreach (IPAddress Adr in IPH.AddressList) | ||
1120 | { | ||
1121 | if (ia == null) | ||
1122 | ia = Adr; | ||
1123 | |||
1124 | if (Adr.AddressFamily == AddressFamily.InterNetwork) | ||
1092 | { | 1125 | { |
1093 | return host; | 1126 | ia = Adr; |
1127 | break; | ||
1094 | } | 1128 | } |
1095 | } | 1129 | } |
1096 | 1130 | ||
1097 | if (hosts.Length > 0) | 1131 | if(ia != null) |
1098 | return hosts[0]; | 1132 | dnscache.AddOrUpdate(hostname, ia, 300); |
1099 | 1133 | ||
1100 | return null; | 1134 | return getEndPoint(ia,port); |
1101 | } | 1135 | } |
1102 | 1136 | ||
1103 | public static Uri GetURI(string protocol, string hostname, int port, string path) | 1137 | public static Uri GetURI(string protocol, string hostname, int port, string path) |
diff --git a/OpenSim/Framework/WebUtil.cs b/OpenSim/Framework/WebUtil.cs index 12f58fe..7b085d0 100644 --- a/OpenSim/Framework/WebUtil.cs +++ b/OpenSim/Framework/WebUtil.cs | |||
@@ -72,11 +72,6 @@ namespace OpenSim.Framework | |||
72 | public static int RequestNumber { get; set; } | 72 | public static int RequestNumber { get; set; } |
73 | 73 | ||
74 | /// <summary> | 74 | /// <summary> |
75 | /// Control where OSD requests should be serialized per endpoint. | ||
76 | /// </summary> | ||
77 | public static bool SerializeOSDRequestsPerEndpoint { get; set; } | ||
78 | |||
79 | /// <summary> | ||
80 | /// this is the header field used to communicate the local request id | 75 | /// this is the header field used to communicate the local request id |
81 | /// used for performance and debugging | 76 | /// used for performance and debugging |
82 | /// </summary> | 77 | /// </summary> |
@@ -98,31 +93,6 @@ namespace OpenSim.Framework | |||
98 | /// </remarks> | 93 | /// </remarks> |
99 | public const int MaxRequestDiagLength = 200; | 94 | public const int MaxRequestDiagLength = 200; |
100 | 95 | ||
101 | /// <summary> | ||
102 | /// Dictionary of end points | ||
103 | /// </summary> | ||
104 | private static Dictionary<string,object> m_endpointSerializer = new Dictionary<string,object>(); | ||
105 | |||
106 | private static object EndPointLock(string url) | ||
107 | { | ||
108 | System.Uri uri = new System.Uri(url); | ||
109 | string endpoint = string.Format("{0}:{1}",uri.Host,uri.Port); | ||
110 | |||
111 | lock (m_endpointSerializer) | ||
112 | { | ||
113 | object eplock = null; | ||
114 | |||
115 | if (! m_endpointSerializer.TryGetValue(endpoint,out eplock)) | ||
116 | { | ||
117 | eplock = new object(); | ||
118 | m_endpointSerializer.Add(endpoint,eplock); | ||
119 | // m_log.WarnFormat("[WEB UTIL] add a new host to end point serializer {0}",endpoint); | ||
120 | } | ||
121 | |||
122 | return eplock; | ||
123 | } | ||
124 | } | ||
125 | |||
126 | #region JSONRequest | 96 | #region JSONRequest |
127 | 97 | ||
128 | /// <summary> | 98 | /// <summary> |
@@ -154,21 +124,6 @@ namespace OpenSim.Framework | |||
154 | return ServiceOSDRequest(url, null, "GET", timeout, false, false); | 124 | return ServiceOSDRequest(url, null, "GET", timeout, false, false); |
155 | } | 125 | } |
156 | 126 | ||
157 | public static OSDMap ServiceOSDRequest(string url, OSDMap data, string method, int timeout, bool compressed, bool rpc) | ||
158 | { | ||
159 | if (SerializeOSDRequestsPerEndpoint) | ||
160 | { | ||
161 | lock (EndPointLock(url)) | ||
162 | { | ||
163 | return ServiceOSDRequestWorker(url, data, method, timeout, compressed, rpc); | ||
164 | } | ||
165 | } | ||
166 | else | ||
167 | { | ||
168 | return ServiceOSDRequestWorker(url, data, method, timeout, compressed, rpc); | ||
169 | } | ||
170 | } | ||
171 | |||
172 | public static void LogOutgoingDetail(Stream outputStream) | 127 | public static void LogOutgoingDetail(Stream outputStream) |
173 | { | 128 | { |
174 | LogOutgoingDetail("", outputStream); | 129 | LogOutgoingDetail("", outputStream); |
@@ -222,7 +177,7 @@ namespace OpenSim.Framework | |||
222 | LogOutgoingDetail(string.Format("RESPONSE {0}: ", reqnum), input); | 177 | LogOutgoingDetail(string.Format("RESPONSE {0}: ", reqnum), input); |
223 | } | 178 | } |
224 | 179 | ||
225 | private static OSDMap ServiceOSDRequestWorker(string url, OSDMap data, string method, int timeout, bool compressed, bool rpc) | 180 | public static OSDMap ServiceOSDRequest(string url, OSDMap data, string method, int timeout, bool compressed, bool rpc) |
226 | { | 181 | { |
227 | int reqnum = RequestNumber++; | 182 | int reqnum = RequestNumber++; |
228 | 183 | ||
@@ -422,14 +377,6 @@ namespace OpenSim.Framework | |||
422 | 377 | ||
423 | public static OSDMap ServiceFormRequest(string url, NameValueCollection data, int timeout) | 378 | public static OSDMap ServiceFormRequest(string url, NameValueCollection data, int timeout) |
424 | { | 379 | { |
425 | lock (EndPointLock(url)) | ||
426 | { | ||
427 | return ServiceFormRequestWorker(url,data,timeout); | ||
428 | } | ||
429 | } | ||
430 | |||
431 | private static OSDMap ServiceFormRequestWorker(string url, NameValueCollection data, int timeout) | ||
432 | { | ||
433 | int reqnum = RequestNumber++; | 380 | int reqnum = RequestNumber++; |
434 | string method = (data != null && data["RequestMethod"] != null) ? data["RequestMethod"] : "unknown"; | 381 | string method = (data != null && data["RequestMethod"] != null) ? data["RequestMethod"] : "unknown"; |
435 | 382 | ||