private void Deserialize(byte[] dataBytes, int dataLen) { NetAdapter.DeserializeData deserializeData = adapter.Deserialize(dataBytes, dataLen); if (deserializeData != null) { //Debugger.Log("recv pmsg 2->" + deSerializationData.toScript + "^" + deSerializationData.Data); if (deserializeData.toScript) { #if JSSCRIPT MessagePool.ScriptSendMessage(null, MessagePool.OnNetMessageArrived, Message.FilterTypeNothing, (string)deSerializationData.Data); #elif LUASCRIPT //MessagePool.CSSendMessage(null, MessagePool.OnNetMessageArrived, Message.FilterTypeNothing, new RecvData() { node = this, data = deSerializationData }); ThreadTask.QueueOnMainThread(() => { CallLuaRecvFunc(deserializeData); NetMsgPool.RecycleMsg(deserializeData.data); deserializeData.data = null; }); #endif } else { //MessagePool.CSSendMessage(null, csNetGID, Message.FilterTypeNothing, deserializeData.data); NetMsgPool.RecycleMsg(deserializeData.data); deserializeData.data = null; } } }
void OnDisable() { if (_current == this) { _current = null; } }
internal void Receive(byte[] arr) { if (receiveCall == null) { return; } if (arr == null) { return; } int gID = -1; int uID = -1; int re = -1; ThreadTask.RunAsync(() => { re = sthread_receive(channel, ref gID, ref uID, arr, arr.Length); }, () => { receiveCall(gID, uID, re); }); }
private static void _RemoveImpurity(byte[] bytes, Action <byte[]> call, bool async = true) { if (async && call == null) { return; } if (bytes == null) { if (call != null) { call(null); } return; } if (async) { ThreadTask.RunAsync(() => { DataDecode(bytes, bytes.Length); }, () => { call(bytes); }); } else { DataDecode(bytes, bytes.Length); } }
internal void Send() { if (sending) { return; } if (msgs.Count <= 0) { return; } lock (locksend) { if (sending) { return; } sending = true; } //may contains timing sequence error ThreadTask.RunAsync(() => { List <MsgBase> list = new List <MsgBase>(); lock (lockobj) { list.AddRange(msgs); msgs.Clear(); } MsgBase mb; for (int i = 0, count = list.Count; i < count; i++) { mb = list[i]; int msgLen = 0; try { byte[] arr = mb.GetMsg(ref msgLen); sthread_send(mb.toChannel, mb.gID, mb.uID, arr, msgLen); } catch (Exception e) { Debugger.LogError("cthread send error->" + e.ToString()); } } lock (locksend) { sending = false; } }, null); }
private static void __AsynReadBytesByPath(string originName, string destName, string path, VersionFile.Type fileType, EndReadBytes endRead, System.Object obj, bool cb_whatever = false, bool needRemoveImpurity = true) { if (instance == null || instance.platformLoader == null) { return; } byte[] arr = null; if (fileType == VersionFile.Type.COMBINE_FILE) { CombineFile cf = CombineFileManager.GetInstance().GetCombineFile(destName); arr = cf.Read(originName); } else { arr = instance.platformLoader.SyncReadBytes(path); } if (arr != null) { if (needRemoveImpurity) { ThreadTask.RunAsync(() => { DataDecode(arr, arr.Length); }, () => { if (endRead != null) { endRead(arr, obj); } }); } else { if (endRead != null) { endRead(arr, obj); } } } else { if (cb_whatever) { if (endRead != null) { endRead(arr, obj); } } } }
private static void Initialize() { if (!initialized) { if (GameCommon.IsMainThread()) { if (!Application.isPlaying) { return; } initialized = true; var g = new GameObject("ThreadTask"); UnityEngine.Object.DontDestroyOnLoad(g); _current = g.AddComponent <ThreadTask>(); } } }
public static void BytesMD5Value(byte[] datas, int dataLen, Action <string> call) { string str = null; ThreadTask.RunAsync(() => { MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider(); byte[] bytHash; bytHash = md5.ComputeHash(datas, 0, dataLen); md5.Clear(); str = MD5BytesToString(bytHash); }, () => { call(str); }); }
public static void StringMD5Value(string str, Action <string> call) { string reStr = null; ThreadTask.RunAsync(() => { MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider(); byte[] bytValue, bytHash; bytValue = System.Text.Encoding.UTF8.GetBytes(str); bytHash = md5.ComputeHash(bytValue); md5.Clear(); reStr = MD5BytesToString(bytHash); }, () => { call(reStr); }); }
void Start() { if (inited) { return; } inited = true; GameCommon.Init(); ThreadTask.RunAsync(() => { }, null); Object.DontDestroyOnLoad(gameObject); Application.runInBackground = true; BeforeInit(); Init(); }
public static void FileMD5Value(String filepath, Action <string> call) { string str = null; ThreadTask.RunAsync(() => { MD5 md5 = new MD5CryptoServiceProvider(); byte[] md5ch; using (FileStream fs = File.OpenRead(filepath)) { md5ch = md5.ComputeHash(fs); } md5.Clear(); str = MD5BytesToString(md5ch); }, () => { call(str); }); }
private void Deserialize(byte[] dataBytes, int dataLen) { if (Config.Detail_Debug_Log()) { Debug.Log("---------net client deserialize msg data 1->" + dataBytes + "^" + dataLen); } if (Config.Detail_Debug_Log()) { Debug.LogError("/////////////////////////////////////////////////////////////////////"); StringBuilder sb = new StringBuilder(); if (dataBytes != null) { int num = 0; for (int i = 0; i < dataLen; i++) { sb.Append(dataBytes[i].ToString("X2")); sb.Append(" "); if (num >= 10) { sb.Append("\r\n"); num = 0; } num++; } Debug.LogError(sb.ToString()); } Debug.LogError("*********************************************************************"); } NetAdapter.DeserializeData deserializeData = adapter.Deserialize(dataBytes, dataLen); if (Config.Detail_Debug_Log()) { Debug.Log("---------net client deserialize msg data 2->" + (deserializeData == null)); } if (deserializeData != null) { if (deserializeData.toScript) { #if JSSCRIPT MessagePool.ScriptSendMessage(null, MessagePool.OnNetMessageArrived, Message.FilterTypeNothing, (string)deSerializationData.Data); #elif LUASCRIPT if (Config.Detail_Debug_Log()) { Debug.Log("---------net client deserialize msg data 3->" + (deserializeData.data == null)); if (deserializeData.data != null) { Debug.Log("----------------------net client deserialize msg data 10->" + deserializeData.data.get_tid() + "^" + deserializeData.data.get_gid() + "^" + deserializeData.data.get_uid() + "^" + deserializeData.data.get_datalen()); } } ThreadTask.QueueOnMainThread(() => { if (Config.Detail_Debug_Log()) { Debug.Log("---------net client deserialize msg data 4->" + (deserializeData.data == null ? -1 : (deserializeData.data.get_data() == null ? -2 : 1))); if (deserializeData.data != null) { Debug.Log("----------------------net client deserialize msg data 11->" + deserializeData.data.get_tid() + "^" + deserializeData.data.get_gid() + "^" + deserializeData.data.get_uid() + "^" + deserializeData.data.get_datalen()); } } CallLuaRecvFunc(deserializeData); NetMsgPool.RecycleMsg(deserializeData.data); deserializeData.data = null; }); #endif } else { NetMsgPool.RecycleMsg(deserializeData.data); deserializeData.data = null; } } }
void Awake() { _current = this; initialized = true; }
public static void LoadToTemp(string path, bool removeImpurity, EndLoadToTemp endcall) { string rePath = null; ThreadTask.RunAsync(() => { try { using (FileStream fs = File.OpenRead(path)) { byte[] buffer; int bufferID; lock (lockBuffer) { bufferID = cachedBuffer.GetByteBuffer(out buffer); } if (bufferID >= 0) { FileStream tfs = LoadToTempAdditive_Begin(path, out rePath); try { int bufferLen = buffer.Length; int remain = (int)fs.Length; int total = remain; int pindex = 0; int readlen = 0; int remainTime = 0; while (remain > 0) { remainTime++; if (remainTime > 1000) { Debugger.LogError("error read file temp large"); rePath = null; break; } if (remain > bufferLen) { readlen = bufferLen; } else { readlen = remain; } if (readlen > 0) { fs.Read(buffer, 0, readlen); LoadToTempAdditive(rePath, tfs, buffer, readlen, total, removeImpurity, ref pindex); } remain -= readlen; if (remain <= 0) { break; } } } catch (Exception e) { Debugger.LogError("error read file temp->" + e.ToString()); rePath = null; } lock (lockBuffer) { cachedBuffer.RecycleByteBuffer(bufferID); } LoadToTempAdditive_End(rePath, tfs); } else { Debugger.LogError("load to temp get cached buffer failed->" + bufferID); } fs.Close(); } } catch (System.Exception e) { Debugger.LogError("read file exception->" + path + "^" + e.ToString()); } }, () => { if (endcall != null) { endcall(rePath); } }); }