コード例 #1
0
    /// <summary>
    /// 释放
    /// </summary>
    /// <param name="block"></param>
    public void Free(MemBlock block)
    {
        if (block.GetBytes() == null)
            return;

        int nIndex = GetIndex(block.GetMaxLength());
        if (nIndex >= mMaxList)
            return;

        mAllMemList[nIndex].Enqueue(block);
    }
コード例 #2
0
ファイル: MemBlockWrap.cs プロジェクト: moto2002/ARPG
 static int GetBytes(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         MemBlock obj = (MemBlock)ToLua.CheckObject(L, 1, typeof(MemBlock));
         byte[]   o   = obj.GetBytes();
         ToLua.Push(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
コード例 #3
0
        /// <summary>
        /// 发送消息
        /// </summary>
        /// <param name="data"></param>
        protected void SendData(MemBlock data)
        {
            // 连接了之后才能发送
            if (!mIsConnected)
                return;

            try
            {
                mIsSending = true;

                IAsyncResult iar = mSocket.BeginSend(data.GetBytes(), 0, data.UseSize, SocketFlags.None, new AsyncCallback(SendDataCallBack), data);
            }
            catch (SocketException ex)
            {
                string strError = ex.ToString();
                Logger.GetLog("NetCommon").Error(strError);

            }
            catch (Exception ex)
            {
                string strError = ex.ToString();
                Logger.GetLog("NetCommon").Error(strError);
            }
        }
コード例 #4
0
 /// <summary>
 /// 发送数据
 /// </summary>
 /// <param name="byData"></param>
 /// <param name="length"></param>
 /// <param name="offset"></param>
 public void SendMessage(byte[] byData, int length, int offset)
 {
     mWriteMem = mPool.Alloc(length);
     Buffer.BlockCopy(byData, offset, mWriteMem.GetBytes(), 0, length);
     // 可以结束了
     SetProcessDone(true);
 }
コード例 #5
0
        /// <summary>
        /// 具体的处理逻辑
        /// </summary>
        protected override void Process()
        {
            try
            {
                Stream stream = mContext.Request.InputStream;
                mReadMem = mPool.Alloc((int)stream.Length);
                stream.Read(mReadMem.GetBytes(), 0, (int)stream.Length);

                mHttpServer.ReceiveData(this, mReadMem.GetBytes(), mReadMem.UseSize);
            }
            catch(Exception ex)
            {
                Logger.GetLog("NetCommon").Error("Http Message Read Error:Process");
                Logger.GetLog("NetCommon").Error(ex.ToString());
            }
        }
コード例 #6
0
        /// <summary>
        /// 添加到发送队列
        /// </summary>
        /// <param name="block"></param>
        protected void PushMessage(MemBlock block)
        {
            lock(mSendLock)
            {
                if (block.GetBytes() == null)
                    return;

                mSendQueue.Enqueue(block);
            }
        }
コード例 #7
0
        /// <summary>
        /// 添加到发送队列,以后定时检查,超时重发
        /// </summary>
        /// <param name="block"></param>
        /// <param name="ipEndPoint"></param>
        /// <param name="sendEvent"></param>
        protected void PushSendData(MemBlock block, IPEndPoint ipEndPoint)
        {
            SendData sendData = new SendData();
            sendData.EndPoint = ipEndPoint;
            sendData.EnterTime = Environment.TickCount;
            sendData.Packet = block;
            sendData.UUID = BitConverter.ToInt64(block.GetBytes(), 0);

            PushSend(sendData);
        }
コード例 #8
0
 /// <summary>
 /// 发送消息
 /// </summary>
 /// <param name="block"></param>
 /// <param name="ipEndPoint"></param>
 public virtual void SendMessage(MemBlock block, IPEndPoint ipEndPoint)
 {
     try
     {
         // 已经Connect过的连接不能发送到远程端口
         if (mRemote == null)
             mUdpClient.Send(block.GetBytes(), block.UseSize, ipEndPoint);
         else
             mUdpClient.Send(block.GetBytes(), block.UseSize);
     }
     catch(SocketException ex)
     {
         // 发送失败,一般是网络连接出错
         if( ex.SocketErrorCode == SocketError.InvalidArgument )
         {
             Logger.GetLog("NetCommon").Error("Net Link Error, Check Network Card Start Or Network Link Is OK!");
         }
     }
     catch(Exception ex)
     {
         Logger.GetLog("NetCommon").Error(ex.ToString());
     }
 }