protected override async Task <T> ParseResponseInfo <T>(FDFSHeader responseHeader)
        {
            var buff = ArrayPool <byte> .Shared.Rent(DEFAULT_BUFFER_SIZE);

            try
            {
                var remainBytes = responseHeader.Length;
                while (remainBytes > 0)
                {
                    var bytes = await _connection.ReceiveExAsync(buff, remainBytes > buff.Length?buff.Length : (int)remainBytes);

                    int result;
                    if ((result = await Callback.ReceiveAsync(responseHeader.Length, buff, bytes)) != 0)
                    {
                        throw new FDFSStatusException(responseHeader.Status, $"Callback Receive Error:{result}");
                    }
                    remainBytes -= bytes;
                }
                return(new T());
            }
            finally
            {
                ArrayPool <byte> .Shared.Return(buff);

                responseHeader.Dispose();
            }
        }
Esempio n. 2
0
        private async Task <T> GetResponseInfo <T>(FDFSHeader responseHeader) where T : IFDFSResponse, new()
        {
            if (responseHeader.Status != 0)
            {
                if (Header.Command == FDFSConstants.STORAGE_PROTO_CMD_QUERY_FILE_INFO)
                {
                    return(default(T));
                }
                throw new FDFSStatusException(responseHeader.Status, $"Get Response Error, Error Code:{(FDFSConstants.ErrorCode)responseHeader.Status}");
            }

            if (responseHeader.Length <= 0)
            {
                return(default(T));
            }

            int resLen    = (int)responseHeader.Length;
            var resBuffer = ArrayPool <byte> .Shared.Rent(resLen);

            try
            {
                await _connection.ReceiveExAsync(resBuffer, resLen);

                var response = new T();
                response.ParseBuffer(resBuffer, resLen);
                return(response);
            }
            finally
            {
                ArrayPool <byte> .Shared.Return(resBuffer);

                responseHeader.Dispose();
            }
        }
Esempio n. 3
0
        protected virtual async Task <T> ParseResponseInfo <T>(FDFSHeader responseHeader) where T : IFDFSResponse, new()
        {
            int resLen    = (int)responseHeader.Length;
            var resBuffer = ArrayPool <byte> .Shared.Rent(resLen);

            try
            {
                await _connection.ReceiveExAsync(resBuffer, resLen);

                var response = new T();
                response.ParseBuffer(resBuffer, resLen);
                return(response);
            }
            finally
            {
                ArrayPool <byte> .Shared.Return(resBuffer);

                responseHeader.Dispose();
            }
        }