public void Enqueue(MsgToSend msg) { lock (lockobj) { sendQueue.Enqueue(msg); } }
public void SendMsg(byte module, byte subid, IBuilder builder = null) { if (_sender != null) { MsgToSend msg = MsgToSend.Create(module, subid, builder); _sender.Enqueue(msg); } }
public static MsgToSend Create(byte module, byte subid, IBuilder builder = null) { MsgToSend msg = new MsgToSend(); msg.moduleId = module; msg.subId = subid; msg._protoBuilder = builder; return(msg); }
private void Run() { Queue <MsgToSend> sending = new Queue <MsgToSend>(); while (running) { while (sendQueue.Count == 0) { Thread.Sleep(1); } while (sendQueue.Count > 0) { lock (lockobj) { sending.Enqueue(sendQueue.Dequeue()); } } while (sending.Count > 0) { MsgToSend msg = sending.Dequeue(); msg.Serialize(); byte[] buff = msg.raw; try { stream.Write(buff, 0, buff.Length); Debug.Log("socket write length: " + buff.Length); } catch (Exception e) { socketMgr.ReportError(client, "send error: " + e.Message + e.StackTrace); running = false; break; } } } }