aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Util.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Framework/Util.cs82
1 files changed, 74 insertions, 8 deletions
diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs
index b8b1039..1cbb53f 100644
--- a/OpenSim/Framework/Util.cs
+++ b/OpenSim/Framework/Util.cs
@@ -56,8 +56,13 @@ namespace OpenSim.Framework
56 /// <summary> 56 /// <summary>
57 /// The method used by Util.FireAndForget for asynchronously firing events 57 /// The method used by Util.FireAndForget for asynchronously firing events
58 /// </summary> 58 /// </summary>
59 /// <remarks>
60 /// None is used to execute the method in the same thread that made the call. It should only be used by regression
61 /// test code that relies on predictable event ordering.
62 /// </remarks>
59 public enum FireAndForgetMethod 63 public enum FireAndForgetMethod
60 { 64 {
65 None,
61 UnsafeQueueUserWorkItem, 66 UnsafeQueueUserWorkItem,
62 QueueUserWorkItem, 67 QueueUserWorkItem,
63 BeginInvoke, 68 BeginInvoke,
@@ -89,7 +94,8 @@ namespace OpenSim.Framework
89 public static readonly Regex UUIDPattern 94 public static readonly Regex UUIDPattern
90 = new Regex("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$"); 95 = new Regex("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$");
91 96
92 public static FireAndForgetMethod FireAndForgetMethod = FireAndForgetMethod.SmartThreadPool; 97 public static FireAndForgetMethod DefaultFireAndForgetMethod = FireAndForgetMethod.SmartThreadPool;
98 public static FireAndForgetMethod FireAndForgetMethod = DefaultFireAndForgetMethod;
93 99
94 /// <summary> 100 /// <summary>
95 /// Gets the name of the directory where the current running executable 101 /// Gets the name of the directory where the current running executable
@@ -1378,11 +1384,30 @@ namespace OpenSim.Framework
1378 return (ipaddr1 != null) ? "http://" + ipaddr1.ToString() + ":" + port1 : uri; 1384 return (ipaddr1 != null) ? "http://" + ipaddr1.ToString() + ":" + port1 : uri;
1379 } 1385 }
1380 1386
1387 /// <summary>
1388 /// Convert a string to a byte format suitable for transport in an LLUDP packet. The output is truncated to 256 bytes if necessary.
1389 /// </summary>
1390 /// <param name="str">
1391 /// If null or empty, then an bytes[0] is returned.
1392 /// Using "\0" will return a conversion of the null character to a byte. This is not the same as bytes[0]
1393 /// </param>
1394 /// <param name="args">
1395 /// Arguments to substitute into the string via the {} mechanism.
1396 /// </param>
1397 /// <returns></returns>
1381 public static byte[] StringToBytes256(string str, params object[] args) 1398 public static byte[] StringToBytes256(string str, params object[] args)
1382 { 1399 {
1383 return StringToBytes256(string.Format(str, args)); 1400 return StringToBytes256(string.Format(str, args));
1384 } 1401 }
1385 1402
1403 /// <summary>
1404 /// Convert a string to a byte format suitable for transport in an LLUDP packet. The output is truncated to 256 bytes if necessary.
1405 /// </summary>
1406 /// <param name="str">
1407 /// If null or empty, then an bytes[0] is returned.
1408 /// Using "\0" will return a conversion of the null character to a byte. This is not the same as bytes[0]
1409 /// </param>
1410 /// <returns></returns>
1386 public static byte[] StringToBytes256(string str) 1411 public static byte[] StringToBytes256(string str)
1387 { 1412 {
1388 if (String.IsNullOrEmpty(str)) { return Utils.EmptyBytes; } 1413 if (String.IsNullOrEmpty(str)) { return Utils.EmptyBytes; }
@@ -1401,11 +1426,30 @@ namespace OpenSim.Framework
1401 return data; 1426 return data;
1402 } 1427 }
1403 1428
1429 /// <summary>
1430 /// Convert a string to a byte format suitable for transport in an LLUDP packet. The output is truncated to 1024 bytes if necessary.
1431 /// </summary>
1432 /// <param name="str">
1433 /// If null or empty, then an bytes[0] is returned.
1434 /// Using "\0" will return a conversion of the null character to a byte. This is not the same as bytes[0]
1435 /// </param>
1436 /// <param name="args">
1437 /// Arguments to substitute into the string via the {} mechanism.
1438 /// </param>
1439 /// <returns></returns>
1404 public static byte[] StringToBytes1024(string str, params object[] args) 1440 public static byte[] StringToBytes1024(string str, params object[] args)
1405 { 1441 {
1406 return StringToBytes1024(string.Format(str, args)); 1442 return StringToBytes1024(string.Format(str, args));
1407 } 1443 }
1408 1444
1445 /// <summary>
1446 /// Convert a string to a byte format suitable for transport in an LLUDP packet. The output is truncated to 1024 bytes if necessary.
1447 /// </summary>
1448 /// <param name="str">
1449 /// If null or empty, then an bytes[0] is returned.
1450 /// Using "\0" will return a conversion of the null character to a byte. This is not the same as bytes[0]
1451 /// </param>
1452 /// <returns></returns>
1409 public static byte[] StringToBytes1024(string str) 1453 public static byte[] StringToBytes1024(string str)
1410 { 1454 {
1411 if (String.IsNullOrEmpty(str)) { return Utils.EmptyBytes; } 1455 if (String.IsNullOrEmpty(str)) { return Utils.EmptyBytes; }
@@ -1511,25 +1555,47 @@ namespace OpenSim.Framework
1511 1555
1512 public static void FireAndForget(System.Threading.WaitCallback callback, object obj) 1556 public static void FireAndForget(System.Threading.WaitCallback callback, object obj)
1513 { 1557 {
1558 // When OpenSim interacts with a database or sends data over the wire, it must send this in en_US culture
1559 // so that we don't encounter problems where, for instance, data is saved with a culture that uses commas
1560 // for decimals places but is read by a culture that treats commas as number seperators.
1561 WaitCallback realCallback = delegate(object o)
1562 {
1563 Culture.SetCurrentCulture();
1564
1565 try
1566 {
1567 callback(o);
1568 }
1569 catch (Exception e)
1570 {
1571 m_log.ErrorFormat(
1572 "[UTIL]: Continuing after async_call_method thread terminated with exception {0}{1}",
1573 e.Message, e.StackTrace);
1574 }
1575 };
1576
1514 switch (FireAndForgetMethod) 1577 switch (FireAndForgetMethod)
1515 { 1578 {
1579 case FireAndForgetMethod.None:
1580 realCallback.Invoke(obj);
1581 break;
1516 case FireAndForgetMethod.UnsafeQueueUserWorkItem: 1582 case FireAndForgetMethod.UnsafeQueueUserWorkItem:
1517 ThreadPool.UnsafeQueueUserWorkItem(callback, obj); 1583 ThreadPool.UnsafeQueueUserWorkItem(realCallback, obj);
1518 break; 1584 break;
1519 case FireAndForgetMethod.QueueUserWorkItem: 1585 case FireAndForgetMethod.QueueUserWorkItem:
1520 ThreadPool.QueueUserWorkItem(callback, obj); 1586 ThreadPool.QueueUserWorkItem(realCallback, obj);
1521 break; 1587 break;
1522 case FireAndForgetMethod.BeginInvoke: 1588 case FireAndForgetMethod.BeginInvoke:
1523 FireAndForgetWrapper wrapper = FireAndForgetWrapper.Instance; 1589 FireAndForgetWrapper wrapper = FireAndForgetWrapper.Instance;
1524 wrapper.FireAndForget(callback, obj); 1590 wrapper.FireAndForget(realCallback, obj);
1525 break; 1591 break;
1526 case FireAndForgetMethod.SmartThreadPool: 1592 case FireAndForgetMethod.SmartThreadPool:
1527 if (m_ThreadPool == null) 1593 if (m_ThreadPool == null)
1528 m_ThreadPool = new SmartThreadPool(2000, 15, 2); 1594 m_ThreadPool = new SmartThreadPool(2000, 15, 2);
1529 m_ThreadPool.QueueWorkItem(SmartThreadPoolCallback, new object[] { callback, obj }); 1595 m_ThreadPool.QueueWorkItem(SmartThreadPoolCallback, new object[] { realCallback, obj });
1530 break; 1596 break;
1531 case FireAndForgetMethod.Thread: 1597 case FireAndForgetMethod.Thread:
1532 Thread thread = new Thread(delegate(object o) { callback(o); }); 1598 Thread thread = new Thread(delegate(object o) { realCallback(o); });
1533 thread.Start(obj); 1599 thread.Start(obj);
1534 break; 1600 break;
1535 default: 1601 default: