コード例 #1
0
        /// <summary>
        /// 发送消息(得先从队列里把要发送的数据拿出来)
        /// This method is invoked when an asynchronous send operation completes.
        /// The method issues another receive on the socket to read any additional data sent from the client
        /// </summary>
        /// <param name="e"></param>
        /// <returns></returns>
        private bool ProcessSend(SocketAsyncEventArgs e)
        {
            AsyncSocketUserToken userToken = e.UserToken as AsyncSocketUserToken;

            userToken.ActiveDateTime = DateTime.Now;
            if (e.SocketError == SocketError.Success)
            {
                AsyncSendBufferManager bufferManager = userToken.SendBufferManager;
                bufferManager.ClearFirstPacket(); //清除已发送的包
                int offset = 0;
                int count  = 0;
                if (bufferManager.GetFirstPacket(ref offset, ref count))
                {
                    return(SendAsyncEvent(userToken.ConnectSocket, userToken.SendEventArgs, bufferManager.DynamicBufferManager.Buffer, offset, count));
                }
                else
                {
                    return(true);
                }
                //return SendCallback();
            }
            else
            {
                CloseClientSocket(userToken);
                return(false);
            }
        }
コード例 #2
0
        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());
            }
        }