示例#1
0
 private void EncodeSend(SocketAsyncEventArgs saea, byte[] data)
 {
     try
     {
         byte[] buffer    = saea.Buffer;
         int    offset    = saea.Offset;
         int    count     = data.Length;
         int    packCount = count;
         if (EncodeSend(buffer, offset, count, data, out packCount))
         {
             saea.SetBuffer(offset, packCount);
         }
         else
         {
             saea.SetBuffer(data, 0, data.Length);
         }
     }
     catch (Exception ex)
     {
         NetDebug.Error("[NetSocket] OnSend, error: {0}.", ex.Message.ToString());
     }
 }
示例#2
0
        protected void SendAsync(byte[] data, int offset, int count)
        {
            if (!ready4Send)
            {
                NetDebug.Log("[NetSocket] SendAsync, not ready for send.");
                return;
            }

            if (null == data || data.Length == 0)
            {
                NetDebug.Log("[NetSocket] SendAsync, the data can not be null.");
                return;
            }

            if (data.Length > NetDefine.MAX_TCP_MESSAGE_LENGTH)
            {
                NetDebug.Error("[Netsocket] SendAsync, the data length:{0} is greater message max length:{1}.",
                               data.Length,
                               NetDefine.MAX_TCP_MESSAGE_LENGTH);
                return;
            }

            SocketAsyncEventArgs saea = AllocSAEA();

            try
            {
                EncodeSend(saea, data, offset, count);
                bool willRaiseEvent = socket.SendAsync(saea);
                if (!willRaiseEvent)
                {
                    SendAsyncCallback(saea);
                }
            }
            catch (Exception ex)
            {
                NetDebug.Log("[NetSocket] SendAsync, error:{0}.", ex.Message.ToString());
            }
        }
示例#3
0
 protected void RecycleReceiveSAEA(SocketAsyncEventArgs saea)
 {
     receiveSAEAPool.Recycle(saea);
     NetDebug.Log("Recycle Receive SAEA count:{0} --{1}", sendSAEAPool.count, GetType().ToString());
 }