private void ProcessMsg(IBaseMessage msg) { int size = msg.Length; int msgId = msg.MsgID; IMessage message = ReceiverHelper.ParseFrom(msg); if (null == message) { Debug.LogErrorFormat("MsgReceiver OnRead ParseFrom message is null !!!! msgid = {0}", msgId); return; } IReceiver receiver = ReceiverHelper.PopReceiver(); if (null == receiver) { Debug.LogErrorFormat("MsgReceiver OnRead PopReceiver receiver is null !!!! msgid = {0}", msgId); return; } receiver.build(msgId, message, Context); Context.msgProcess.EnqueueReceiver(receiver); if (msgId != DefineProtobuf.MSG_HEARTBEAT) { Debug.LogFormat("============ Socket Read : msgId = {0} size = {1}", msgId, size); } }
public void OnUpdate(float elapse) { SocketConnectState tmp = null; while (socketStateQueue.TryDequeue(out tmp)) { Debug.LogFormat("SocketConnectState state = {0} error = {1}", tmp.socketState, tmp.errorno); this.Context.CoreModules.eventMDL.Publish(DefineEvent.EVENT_SOCKET_STATUS, tmp); } IReceiver receiver = null; while (receiverQueue.TryDequeue(out receiver)) { //Debug.LogFormat("receiverQueue TryDequeue receiver ID = {0}", receiver.ID); receiver.Process(); ReceiverHelper.RecycleReceiver(receiver); } IBaseMessage msg = null; while (senderQueue.TryDequeue(out msg)) { Context.msgSender.SendMsg(msg); ReceiverHelper.RecycleMessage(msg); } }
private void OnTime(int passedTime) { this.heartNum++; //Debug.Log("心跳时间!!啵啵啵"); p.ActionId = this.heartNum; p.T0 = DateTimeHelper.GetTimeStamp(false); IBaseMessage msg = ReceiverHelper.PopMessage(); msg.WriteIn(p, DefineProtobuf.MSG_HEARTBEAT); this.Context.CoreModules.netMDL.SendMessage(msg); }
public void OnRead(byte[] buff, int offset, int length) { //Debug.LogFormat("============ Socket Read : buff.Length = {0} offset = {1}, buff = ( {2} )", length, offset,buff.ToString()); List <IBaseMessage> list = Context.marshalEndian.Decode(buff, length); var enumerator = list.GetEnumerator(); while (enumerator.MoveNext()) { var item = enumerator.Current; ProcessMsg(item); ReceiverHelper.RecycleMessage(item); } }