diff options
author | John Hurliman | 2009-10-06 02:38:00 -0700 |
---|---|---|
committer | John Hurliman | 2009-10-06 02:38:00 -0700 |
commit | e7c877407f2a72a9519eb53debca5aeef20cded9 (patch) | |
tree | ed67cb35522f357874f6e2749d66fd48493ede80 /OpenSim/Framework/Util.cs | |
parent | Merge branch 'master' of ssh://opensimulator.org/var/git/opensim into htb-thr... (diff) | |
download | opensim-SC-e7c877407f2a72a9519eb53debca5aeef20cded9.zip opensim-SC-e7c877407f2a72a9519eb53debca5aeef20cded9.tar.gz opensim-SC-e7c877407f2a72a9519eb53debca5aeef20cded9.tar.bz2 opensim-SC-e7c877407f2a72a9519eb53debca5aeef20cded9.tar.xz |
* Continued work on the new LLUDP implementation. Appears to be functioning, although not everything is reimplemented yet
* Replaced logic in ThreadTracker with a call to System.Diagnostics that does the same thing
* Added Util.StringToBytes256() and Util.StringToBytes1024() to clamp output at byte[256] and byte[1024], respectively
* Fixed formatting for a MySQLAssetData error logging line
Diffstat (limited to 'OpenSim/Framework/Util.cs')
-rw-r--r-- | OpenSim/Framework/Util.cs | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs index 0851d26..189fa38 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) |