Esempio n. 1
0
 protected internal override IOperationResult ReadResponse(PooledSocket socket)
 {
     return(new TextOperationResult
     {
         Success = String.Compare(TextSocketHelper.ReadResponse(socket), "DELETED", StringComparison.Ordinal) == 0
     });
 }
Esempio n. 2
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.");
            }
        }
Esempio n. 3
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);
        }
Esempio n. 4
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);
        }
Esempio n. 5
0
        protected internal override IOperationResult 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(new TextOperationResult().Pass());
        }
Esempio n. 6
0
 protected internal override IOperationResult ReadResponse(PooledSocket socket)
 {
     TextSocketHelper.ReadResponse(socket);
     return(new TextOperationResult().Pass());
 }