aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Util.cs
diff options
context:
space:
mode:
authorMelanie2009-10-08 10:32:15 +0100
committerMelanie2009-10-08 10:32:15 +0100
commitf6b8bac0fab3dfc3d25775e51bb89ee10feebb53 (patch)
treede16f4c7c14fce6851a4cd9c80117d1cbdd4b38e /OpenSim/Framework/Util.cs
parentCorrect a build break caused by an optimization in trunk (diff)
parentRemove ThreadTrackerTest. It's no longer relevant because the thread (diff)
downloadopensim-SC-f6b8bac0fab3dfc3d25775e51bb89ee10feebb53.zip
opensim-SC-f6b8bac0fab3dfc3d25775e51bb89ee10feebb53.tar.gz
opensim-SC-f6b8bac0fab3dfc3d25775e51bb89ee10feebb53.tar.bz2
opensim-SC-f6b8bac0fab3dfc3d25775e51bb89ee10feebb53.tar.xz
Merge branch 'master' into vehicles
Diffstat (limited to 'OpenSim/Framework/Util.cs')
-rw-r--r--OpenSim/Framework/Util.cs40
1 files changed, 39 insertions, 1 deletions
diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs
index 0851d26..38729c6 100644
--- a/OpenSim/Framework/Util.cs
+++ b/OpenSim/Framework/Util.cs
@@ -1231,6 +1231,42 @@ namespace OpenSim.Framework
1231 return (ipaddr1 != null) ? "http://" + ipaddr1.ToString() + ":" + port1 : uri; 1231 return (ipaddr1 != null) ? "http://" + ipaddr1.ToString() + ":" + port1 : uri;
1232 } 1232 }
1233 1233
1234 public static byte[] StringToBytes256(string str)
1235 {
1236 if (String.IsNullOrEmpty(str)) { return Utils.EmptyBytes; }
1237 if (str.Length > 254) str = str.Remove(254);
1238 if (!str.EndsWith("\0")) { str += "\0"; }
1239
1240 // Because this is UTF-8 encoding and not ASCII, it's possible we
1241 // might have gotten an oversized array even after the string trim
1242 byte[] data = UTF8.GetBytes(str);
1243 if (data.Length > 256)
1244 {
1245 Array.Resize<byte>(ref data, 256);
1246 data[255] = 0;
1247 }
1248
1249 return data;
1250 }
1251
1252 public static byte[] StringToBytes1024(string str)
1253 {
1254 if (String.IsNullOrEmpty(str)) { return Utils.EmptyBytes; }
1255 if (str.Length > 1023) str = str.Remove(1023);
1256 if (!str.EndsWith("\0")) { str += "\0"; }
1257
1258 // Because this is UTF-8 encoding and not ASCII, it's possible we
1259 // might have gotten an oversized array even after the string trim
1260 byte[] data = UTF8.GetBytes(str);
1261 if (data.Length > 1024)
1262 {
1263 Array.Resize<byte>(ref data, 1024);
1264 data[1023] = 0;
1265 }
1266
1267 return data;
1268 }
1269
1234 #region FireAndForget Threading Pattern 1270 #region FireAndForget Threading Pattern
1235 1271
1236 public static void FireAndForget(System.Threading.WaitCallback callback) 1272 public static void FireAndForget(System.Threading.WaitCallback callback)
@@ -1247,7 +1283,9 @@ namespace OpenSim.Framework
1247 { 1283 {
1248 System.Threading.WaitCallback callback = (System.Threading.WaitCallback)ar.AsyncState; 1284 System.Threading.WaitCallback callback = (System.Threading.WaitCallback)ar.AsyncState;
1249 1285
1250 callback.EndInvoke(ar); 1286 try { callback.EndInvoke(ar); }
1287 catch (Exception ex) { m_log.Error("[UTIL]: Asynchronous method threw an exception: " + ex.Message, ex); }
1288
1251 ar.AsyncWaitHandle.Close(); 1289 ar.AsyncWaitHandle.Close();
1252 } 1290 }
1253 1291