public bool DoSendResult(byte[] buffer, int offset, int count)
        {
            string commandText = m_outgoingDataAssembler.GetProtocolText();

            byte[] bufferUTF8  = Encoding.UTF8.GetBytes(commandText);
            int    totalLength = sizeof(int) + bufferUTF8.Length + count; //获取总大小
            AsyncSendBufferManager asyncSendBufferManager = m_asyncSocketUserToken.SendBuffer;

            asyncSendBufferManager.StartPacket();
            asyncSendBufferManager.DynamicBufferManager.WriteInt(totalLength, false);       //写入总大小
            asyncSendBufferManager.DynamicBufferManager.WriteInt(bufferUTF8.Length, false); //写入命令大小
            asyncSendBufferManager.DynamicBufferManager.WriteBuffer(bufferUTF8);            //写入命令内容
            asyncSendBufferManager.DynamicBufferManager.WriteBuffer(buffer, offset, count); //写入二进制数据
            asyncSendBufferManager.EndPacket();

            bool result = true;

            if (!m_asyncSocketUserToken.SendAsyncState)
            {
                int packetOffset = 0;
                int packetCount  = 0;
                if (asyncSendBufferManager.GetFirstPacket(ref packetOffset, ref packetCount))
                {
                    m_asyncSocketUserToken.SendAsyncState = true;
                    result = m_asyncSocketServer.SendAsyncEvent(m_asyncSocketUserToken.ConnectSocket, m_asyncSocketUserToken.SendEventArgs,
                                                                asyncSendBufferManager.DynamicBufferManager.Buffer, packetOffset, packetCount);
                }
            }
            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;
     m_receiveBuffer           = new DynamicBufferManager(ProtocolConst.InitBufferSize);
     m_sendBuffer = new AsyncSendBufferManager(ProtocolConst.InitBufferSize);;
 }
        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;

            if (!m_asyncSocketUserToken.SendAsyncState)
            {
                int packetOffset = 0;
                int packetCount  = 0;
                if (asyncSendBufferManager.GetFirstPacket(ref packetOffset, ref packetCount))
                {
                    m_asyncSocketUserToken.SendAsyncState = true;
                    result = m_asyncSocketServer.SendAsyncEvent(m_asyncSocketUserToken.ConnectSocket, m_asyncSocketUserToken.SendEventArgs,
                                                                asyncSendBufferManager.DynamicBufferManager.Buffer, packetOffset, packetCount);
                }
            }
            return(result);
        }
        public virtual bool SendCompleted()
        {
            m_activeDT = DateTime.UtcNow;
            m_asyncSocketUserToken.SendAsyncState = false;
            // Console.WriteLine("public virtual bool SendCompleted(): m_asyncSocketUserToken.SendAsyncState = false;");
            AsyncSendBufferManager asyncSendBufferManager = m_asyncSocketUserToken.SendBuffer;

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

            if (asyncSendBufferManager.GetFirstPacket(ref offset, ref count))
            {
                // m_sendAsync = true;
                m_asyncSocketUserToken.SendAsyncState = true;
                Console.WriteLine("public virtual bool SendCompleted():m_asyncSocketUserToken.SendAsyncState = true;");
                return(m_asyncSocketServer.SendAsyncEvent(m_asyncSocketUserToken.ConnectSocket, m_asyncSocketUserToken.SendEventArgs,
                                                          asyncSendBufferManager.DynamicBufferManager.Buffer, offset, count));
            }
            else
            {
                return(SendCallback());
            }
        }