ReadResponse() public static method

Reads the response of the server.
The server did not sent a response or an empty line was returned. The server did not specified any reason just returned the string ERROR. - or - The server returned a SERVER_ERROR, in this case the Message of the exception is the message returned by the server. The server did not recognize the request sent by the memcachedClient. The Message of the exception is the message returned by the server.
public static ReadResponse ( PooledSocket socket ) : string
socket PooledSocket
return string
コード例 #1
0
 protected internal override IOperationResult ReadResponse(PooledSocket socket)
 {
     return(new TextOperationResult
     {
         Success = String.Compare(TextSocketHelper.ReadResponse(socket), "DELETED", StringComparison.Ordinal) == 0
     });
 }
コード例 #2
0
 protected internal override ValueTask <IOperationResult> ReadResponseAsync(PooledSocket socket)
 {
     return(new ValueTask <IOperationResult>(new TextOperationResult
     {
         Success = String.Compare(TextSocketHelper.ReadResponse(socket), "STORED", StringComparison.Ordinal) == 0
     }));
 }
コード例 #3
0
        public static void FinishCurrent(PooledSocket socket)
        {
            string response = TextSocketHelper.ReadResponse(socket);

            if (String.Compare(response, "END", StringComparison.Ordinal) != 0)
            {
                throw new MemcachedClientException("No END was received.");
            }
        }
コード例 #4
0
ファイル: GetHelper.cs プロジェクト: lanicon/Enyim.Caching
        public static GetResponse ReadItem(PooledSocket socket)
        {
            var description = TextSocketHelper.ReadResponse(socket);

            if (String.Compare(description, "END", StringComparison.Ordinal) == 0)
            {
                return(null);
            }

            else if (description.Length < 6 || String.Compare(description, 0, "VALUE ", 0, 6, StringComparison.Ordinal) != 0)
            {
                throw new MemcachedClientException("No VALUE response received.\r\n" + description);
            }

            // response is:
            // VALUE <key> <flags> <bytes> [<cas unique>]
            // 0     1     2       3       4
            //
            // cas only exists in 1.2.4+
            //

            ulong cas   = 0;
            var   parts = description.Split(' ');

            if (parts.Length == 5)
            {
                if (!UInt64.TryParse(parts[4], out cas))
                {
                    throw new MemcachedClientException("Invalid CAS VALUE received.");
                }
            }
            else if (parts.Length < 4)
            {
                throw new MemcachedClientException("Invalid VALUE response received: " + description);
            }

            var flags  = UInt16.Parse(parts[2], CultureInfo.InvariantCulture);
            var length = Int32.Parse(parts[3], CultureInfo.InvariantCulture);

            var allData = new byte[length];
            var eod     = new byte[2];

            socket.Receive(allData, 0, length);
            socket.Receive(eod, 0, 2);             // data is terminated by \r\n

            var result = new GetResponse(parts[1], flags, cas, allData);

            GetHelper.Logger = GetHelper.Logger ?? Caching.Logger.CreateLogger(typeof(GetHelper));
            if (GetHelper.Logger.IsEnabled(LogLevel.Debug))
            {
                GetHelper.Logger.LogDebug("Received value. Data type: {0}, size: {1}.", result.Item.Flags, result.Item.Data.Count);
            }

            return(result);
        }
コード例 #5
0
        public static GetResponse ReadItem(PooledSocket socket)
        {
            string description = TextSocketHelper.ReadResponse(socket);

            if (String.Compare(description, "END", StringComparison.Ordinal) == 0)
            {
                return(null);
            }

            if (description.Length < 6 || String.Compare(description, 0, "VALUE ", 0, 6, StringComparison.Ordinal) != 0)
            {
                throw new MemcachedClientException("No VALUE response received.\r\n" + description);
            }

            ulong cas = 0;

            string[] parts = description.Split(' ');

            // response is:
            // VALUE <key> <flags> <bytes> [<cas unique>]
            // 0     1     2       3       4
            //
            // cas only exists in 1.2.4+
            //
            if (parts.Length == 5)
            {
                if (!UInt64.TryParse(parts[4], out cas))
                {
                    throw new MemcachedClientException("Invalid CAS VALUE received.");
                }
            }
            else if (parts.Length < 4)
            {
                throw new MemcachedClientException("Invalid VALUE response received: " + description);
            }

            ushort flags  = UInt16.Parse(parts[2], CultureInfo.InvariantCulture);
            int    length = Int32.Parse(parts[3], CultureInfo.InvariantCulture);

            byte[] allData = new byte[length];
            byte[] eod     = new byte[2];

            socket.Read(allData, 0, length);
            socket.Read(eod, 0, 2);             // data is terminated by \r\n

            GetResponse retval = new GetResponse(parts[1], flags, cas, allData);

            if (log.IsDebugEnabled)
            {
                log.DebugFormat("Received value. Data type: {0}, size: {1}.", retval.Item.Flags, retval.Item.Data.Count);
            }

            return(retval);
        }
コード例 #6
0
        protected internal override bool ReadResponse(PooledSocket socket)
        {
            string response = TextSocketHelper.ReadResponse(socket);

            //maybe we should throw an exception when the item is not found?
            if (String.Compare(response, "NOT_FOUND", StringComparison.Ordinal) == 0)
            {
                return(false);
            }

            return(UInt64.TryParse(response, NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite, CultureInfo.InvariantCulture, out this.result));
        }
コード例 #7
0
        protected internal override IOperationResult ReadResponse(PooledSocket socket)
        {
            string response = TextSocketHelper.ReadResponse(socket);
            var    result   = new TextOperationResult();

            //maybe we should throw an exception when the item is not found?
            if (String.Compare(response, "NOT_FOUND", StringComparison.Ordinal) == 0)
            {
                return(result.Fail("Failed to read response.  Item not found"));
            }

            result.Success = UInt64.TryParse(response, NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite, CultureInfo.InvariantCulture, out this.result);
            return(result);
        }
コード例 #8
0
        protected internal override bool ReadResponse(PooledSocket socket)
        {
            var serverData = new Dictionary <string, string>();

            while (true)
            {
                string line = TextSocketHelper.ReadResponse(socket);

                // stat values are terminated by END
                if (String.Compare(line, "END", StringComparison.Ordinal) == 0)
                {
                    break;
                }

                // expected response is STAT item_name item_value
                if (line.Length < 6 || String.Compare(line, 0, "STAT ", 0, 5, StringComparison.Ordinal) != 0)
                {
                    if (log.IsWarnEnabled)
                    {
                        log.Warn("Unknow response: " + line);
                    }

                    continue;
                }

                // get the key&value
                string[] parts = line.Remove(0, 5).Split(' ');
                if (parts.Length != 2)
                {
                    if (log.IsWarnEnabled)
                    {
                        log.Warn("Unknow response: " + line);
                    }

                    continue;
                }

                // store the stat item
                serverData[parts[0]] = parts[1];
            }

            this.result = serverData;

            return(true);
        }
コード例 #9
0
 protected internal override IOperationResult ReadResponse(PooledSocket socket)
 {
     TextSocketHelper.ReadResponse(socket);
     return(new TextOperationResult().Pass());
 }
コード例 #10
0
 protected internal override bool ReadResponse(PooledSocket socket)
 {
     return(String.Compare(TextSocketHelper.ReadResponse(socket), "STORED", StringComparison.Ordinal) == 0);
 }
コード例 #11
0
 protected internal override ValueTask <IOperationResult> ReadResponseAsync(PooledSocket socket)
 {
     TextSocketHelper.ReadResponse(socket);
     return(new ValueTask <IOperationResult>(new TextOperationResult().Pass()));
 }
コード例 #12
0
        protected internal override bool ReadResponse(PooledSocket socket)
        {
            TextSocketHelper.ReadResponse(socket);

            return(true);
        }