Example #1
0
        /// <summary>
        /// 从socket中接收数据输出到接收器中
        /// </summary>
        public void Read(AbstractOutputReceiver receiver, int bufSize)
        {
            CurAdbSocket.ReceiveBufferSize = bufSize;
            var data  = new byte[bufSize];
            int count = -1;

            try
            {
                while (count != 0)
                {
                    count = CurAdbSocket.Receive(data);
                    if (count <= 0)
                    {
                        break;
                    }
                    receiver.Add(data, 0, count);
                }
            }
            finally
            {
                receiver.Flush();
            }
        }
Example #2
0
        /// <summary>
        /// 从socket中接收读取指定大小的数据流
        /// </summary>
        public void Read(byte[] data, int length = -1)
        {
            int expLen = length < 0 ? data.Length : length;

            expLen = expLen > data.Length ? data.Length : expLen;
            CurAdbSocket.ReceiveBufferSize = expLen;
            int count     = -1;
            int totalRead = 0;

            while (count != 0 && totalRead < expLen)
            {
                int    left   = expLen - totalRead;
                int    buflen = left < CurAdbSocket.ReceiveBufferSize ? left : CurAdbSocket.ReceiveBufferSize;
                byte[] buffer = new byte[buflen];

                count = CurAdbSocket.Receive(buffer, buflen, SocketFlags.None);
                if (count > 0)
                {
                    Array.Copy(buffer, 0, data, totalRead, count);
                    totalRead += count;
                }
            }
        }
Example #3
0
        /// <summary>
        /// 读取所有数据
        /// </summary>
        /// <returns></returns>
        public byte[] ReadToEnd()
        {
            List <byte> result = new List <byte>();

            CurAdbSocket.ReceiveBufferSize = 1024 * 16;
            byte[] value = new byte[1024 * 16];
            try
            {
                while (true)
                {
                    var readLength = CurAdbSocket.Receive(value, value.Length, SocketFlags.None);
                    if (readLength < 1)
                    {
                        break;
                    }
                    result.AddRange(value.Take(readLength));
                }
            }
            catch (Exception ex)
            {
                LoggerManagerSingle.Instance.Error(ex);
            }
            return(result.ToArray());
        }