Пример #1
0
 public void SendMsgCompleted(TcpSendMsg tcpSendMsg)
 {
     if (!tcpSendMsg.SendImmediate)
     {
         DequeueSendMsgPool(tcpSendMsg);
     }
     SendMsgPacket();
 }
Пример #2
0
 private void EnqueueSendMsgPool(TcpSendMsg tcpSendMsg)
 {
     while (true)
     {
         if (Interlocked.CompareExchange(ref sendMsgPoolState, 1, 0) == 0)
         {
             sendMsgPool.Add(tcpSendMsg);
             sendMsgPoolState = 0;
             return;
         }
     }
 }
Пример #3
0
        public void Init(ReceiveInvokeElement receiveInvokeElement, TcpSendMsg heartbeatMsg, int heartbeatInterval)
        {
            this.receiveIvokeElement       = receiveInvokeElement;
            tcpClient.ReceiveInvokeElement = receiveInvokeElement;

            if (heartbeatMsg != null)
            {
                heartbeatMsg.Encode();
                this.heartbeatMsg = heartbeatMsg;
            }

            this.heartbeatInterval  = heartbeatInterval;
            this.maxReceiveInterval = heartbeatInterval * 2;
        }
Пример #4
0
 private void DequeueSendMsgPool(TcpSendMsg tcpSendMsg)
 {
     if (sendMsgPool.Count > 0)
     {
         while (true)
         {
             if (Interlocked.CompareExchange(ref sendMsgPoolState, 2, 0) == 0)
             {
                 sendMsgPool.Remove(tcpSendMsg);
                 sendMsgPoolState = 0;
                 return;
             }
         }
     }
 }
Пример #5
0
        public void SendMessage(TcpSendMsg msg, bool immediate)
        {
            msg.Encode();
            msg.SendImmediate = immediate;

            if (Interlocked.Read(ref tcpSocketState) == 1)
            {
                if (immediate)
                {
                    tcpClient.BeginSend(msg.Packet, msg);
                }
                else
                {
                    EnqueueSendMsgPool(msg);
                    SendMsgPacket();
                }
            }
        }
Пример #6
0
 private bool PeekSendMsgPool(ref TcpSendMsg tcpSendMsg)
 {
     if (sendMsgPool.Count > 0)
     {
         while (true)
         {
             if (Interlocked.CompareExchange(ref sendMsgPoolState, 3, 0) == 0)
             {
                 if (sendMsgPool.Count > 0)
                 {
                     tcpSendMsg       = sendMsgPool[0];
                     sendMsgPoolState = 0;
                     return(true);
                 }
                 else
                 {
                     return(false);
                 }
             }
         }
     }
     return(false);
 }