Fixed the ascii protocol handler
authorTrond Norbye <trondn@uname-a>
Wed, 27 Jan 2010 17:04:43 +0000 (09:04 -0800)
committerTrond Norbye <trondn@uname-a>
Wed, 27 Jan 2010 17:04:43 +0000 (09:04 -0800)
* Return error message for all commands that doesn't support noreply
* get returned flags as the length instead of the actual length

libmemcached/protocol/ascii_handler.c

index 19aff1156d3c56698242627239714536a3eb0589..c2fd6870d6929a2cc7b1b7c9fa25fcf7b3ceb771 100644 (file)
@@ -80,6 +80,7 @@ static void send_command_usage(memcached_protocol_client_st *client)
     [UNKNOWN_CMD]= "CLIENT_ERROR: Unknown command\r\n",
   };
 
+  client->mute = false;
   spool_string(client, errmsg[client->ascii_command]);
 }
 
@@ -146,11 +147,11 @@ ascii_get_response_handler(const void *cookie,
   if (client->ascii_command == GETS_CMD)
   {
     snprintf(dest, sizeof(buffer) - used, " %u %u %llu\r\n", flags,
-             flags, (unsigned long long)cas);
+             bodylen, (unsigned long long)cas);
   }
   else
   {
-    snprintf(dest, sizeof(buffer) - used, " %u %u\r\n", flags, flags);
+    snprintf(dest, sizeof(buffer) - used, " %u %u\r\n", flags, bodylen);
   }
 
   client->root->spool(client, buffer, strlen(buffer));
@@ -832,9 +833,10 @@ memcached_protocol_event_t memcached_ascii_protocol_process_data(memcached_proto
       case REPLACE_CMD:
         error= process_replace_command(client, tokens, ntokens,
                                        ptr, &end, *length);
+        break;
       case CAS_CMD:
         error= process_cas_command(client, tokens, ntokens, ptr, &end, *length);
-       break;
+        break;
       case APPEND_CMD:
         error= process_append_command(client, tokens, ntokens,
                                       ptr, &end, *length);
@@ -852,18 +854,34 @@ memcached_protocol_event_t memcached_ascii_protocol_process_data(memcached_proto
         process_arithmetic(client, tokens, ntokens);
         break;
       case STATS_CMD:
-        recover_tokenize_command(ptr, end);
-        process_stats(client, ptr + 6, end);
+        if (client->mute)
+        {
+          send_command_usage(client);
+        }
+        else
+        {
+          recover_tokenize_command(ptr, end);
+          process_stats(client, ptr + 6, end);
+        }
         break;
       case FLUSH_ALL_CMD:
         process_flush(client, tokens, ntokens);
         break;
       case VERSION_CMD:
-        process_version(client, tokens, ntokens);
+        if (client->mute)
+        {
+          send_command_usage(client);
+        }
+        else
+        {
+          process_version(client, tokens, ntokens);
+        }
         break;
       case QUIT_CMD:
-        if (ntokens != 1)
+        if (ntokens != 1 || client->mute)
+        {
           send_command_usage(client);
+        }
         else
         {
           if (client->root->callback->interface.v1.quit != NULL)