/// <summary>
        /// 数据发送
        /// </summary>
        /// <param name="buffer"></param>
        /// <param name="offset"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public bool DoSendBuffer(byte[] buffer, int offset, int count)
        {
            AsyncSendBufferManager asyncSendBufferManager = m_asyncSocketUserToken.SendBuffer;

            asyncSendBufferManager.StartPacket();
            asyncSendBufferManager.DynamicBufferManager.WriteBuffer(buffer, offset, count);
            asyncSendBufferManager.EndPacket();
            bool result = true;

            try
            {
                if (!m_sendAsync)
                {
                    int packetOffset = 0;
                    int packetCount  = 0;
                    if (asyncSendBufferManager.GetFirstPacket(ref packetOffset, ref packetCount))
                    {
                        m_sendAsync = true;
                        result      = m_asyncSocketServer.SendAsyncEvent(m_asyncSocketUserToken.ConnectSocket, m_asyncSocketUserToken.SendEventArgs,
                                                                         asyncSendBufferManager.DynamicBufferManager.Buffer, packetOffset, packetCount);
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }

            return(result);
        }
 public AsyncSocketUserToken(int asyncReceiveBufferSize)
 {
     m_connectSocket              = null;
     m_asyncSocketInvokeElement   = null;
     m_receiveEventArgs           = new SocketAsyncEventArgs();
     m_receiveEventArgs.UserToken = this;
     m_asyncReceiveBuffer         = new byte[asyncReceiveBufferSize];
     m_receiveEventArgs.SetBuffer(m_asyncReceiveBuffer, 0, m_asyncReceiveBuffer.Length);
     m_sendEventArgs           = new SocketAsyncEventArgs();
     m_sendEventArgs.UserToken = this;
     ReceiveBuffer             = new DynamicBufferManager(ProtocolConst.InitBufferSize);
     m_sendBuffer = new AsyncSendBufferManager(ProtocolConst.InitBufferSize);;
 }
        public virtual bool SendCompleted()
        {
            m_activeDT  = DateTime.UtcNow;
            m_sendAsync = false;
            AsyncSendBufferManager asyncSendBufferManager = m_asyncSocketUserToken.SendBuffer;

            asyncSendBufferManager.ClearFirstPacket(); //清除已发送的包
            int offset = 0;
            int count  = 0;

            if (asyncSendBufferManager.GetFirstPacket(ref offset, ref count))
            {
                m_sendAsync = true;
                return(m_asyncSocketServer.SendAsyncEvent(m_asyncSocketUserToken.ConnectSocket, m_asyncSocketUserToken.SendEventArgs,
                                                          asyncSendBufferManager.DynamicBufferManager.Buffer, offset, count));
            }
            else
            {
                return(SendCallback());
            }
        }