//Stopwatch sw1 = new Stopwatch(); /// <summary> /// 延迟拼包发送 /// </summary> /// <param name="msg"></param> public override void SendDelay(IEnumerable <VarList> msgs) { //sw1.Restart(); if (_tcpSock == null || !_tcpSock.Connected) { return; } try { using (var ms = new MemoryStream()) { long lastPosition = 0; foreach (var msg in msgs) { //包头定义 var ph = new PackageHead(); ms.Position = lastPosition; ph.GetHeadBytes(ms); ms.Position = lastPosition + ph.HEADSIZE + ph.BODYLENGTH; Serializer.Serialize(ms, msg); var count = Convert.ToInt32(ms.Position - ph.HEADSIZE - ph.BODYLENGTH - lastPosition); lastPosition = ms.Position; ms.Position = lastPosition - count - ph.BODYLENGTH; ph.Write(ms, count); ph.Dispose(); } Send(ms.GetBuffer(), 0, (int)lastPosition); } } catch (Exception ex) { Log.Error(ex.Message); Log.Error(ex.StackTrace); Csl.Wl(ConsoleColor.Red, ex.StackTrace); } //sw1.Stop(); //if (sw1.ElapsedMilliseconds > 50) //{ // Csl.Wl(ConsoleColor.Red, "Send msgs " + sw1.ElapsedMilliseconds); //} }
public void Push(PackageHead item) { _headPools.Enqueue(item); }