Пример #1
0
 public void ClearUp()
 {
     Disconnect();
     m_Socket           = null;
     m_LogicRecvHandler = null;
     m_LogicSendHandler = null;
     m_serverMsgIndex   = 0;
 }
Пример #2
0
        //-- 将逻辑发送缓冲区的数据转存到net层的发送缓冲区,开启异步发送过程。并立即返回。
        public bool SendToSocketBuf(LogicSendHandler logicSendHandler)
        {
            if (logicSendHandler == null)
            {
                return(false);
            }

            //-TODO: 这里之后再考虑
            if (!IsConnected())
            {
                return(true);
            }

            int iSendLength = logicSendHandler.SendBufSize();

            if (iSendLength == 0)
            {
                return(true);
            }

            MemoryStream oMemStream = logicSendHandler.GetLogicSendBuf();

            if (oMemStream == null)
            {
                return(false);
            }

            //-- 将逻辑层缓冲区转到发送缓冲区
            //-TODO: encode type
            SocketSendBuf sendBuff = m_SocketSendBufQueue.GetBuf();

            if (sendBuff == null)
            {
                return(false);
            }
            MemoryStream sendMemStream = sendBuff.GetMemoryStream();

            if (sendMemStream == null)
            {
                return(false);
            }
            //-- oMemStream.GetBuffer()不发生new byte[]操作。
            if (oMemStream.Length == 0)
            {
                //Console.WriteLine("Error:==[logicSendHandler.SendBufSize() != 0 && oMemStream.Length == 0]");
                return(false);
            }
            try
            {
                sendMemStream.Write(oMemStream.GetBuffer(), 0, (int)oMemStream.Length);
            }
            catch (System.Exception ex)
            {
                //-- log
                CommonDebugLog.LogWarning("ex:=[" + ex.ToString() + "]");
                return(false);
            }
            sendBuff.SetEmptyFlag(false);
            logicSendHandler.ClearUp();

            return(Send(sendBuff));
        }
Пример #3
0
 public NetManager()
 {
     m_Socket           = new TSocket();
     m_LogicRecvHandler = new LogicRecvHandler(m_Socket);
     m_LogicSendHandler = new LogicSendHandler(m_Socket);
 }