Merge in trunk.
authorBrian Aker <brian@tangent.org>
Wed, 25 May 2011 01:03:51 +0000 (18:03 -0700)
committerBrian Aker <brian@tangent.org>
Wed, 25 May 2011 01:03:51 +0000 (18:03 -0700)
libmemcached/connect.cc
libmemcached/hosts.cc
libmemcached/memcached.cc
libmemcached/options/parser.cc
libmemcached/options/scanner.cc
libmemcached/quit.cc
libmemcached/server.cc
tests/mem_functions.cc
tests/parser.cc
tests/parser.h

index 35053d60cb3c34d1931b2410d9eeebc294977615..90d3facb06728f24edc3ac7effa8004c1684c2ff 100644 (file)
@@ -505,19 +505,18 @@ static memcached_return_t network_connect(memcached_server_st *ptr)
   return MEMCACHED_SUCCESS; /* The last error should be from connect() */
 }
 
-void set_last_disconnected_host(memcached_server_write_instance_st ptr)
+void set_last_disconnected_host(memcached_server_write_instance_st self)
 {
   // const_cast
-  memcached_st *root= (memcached_st *)ptr->root;
+  memcached_st *root= (memcached_st *)self->root;
 
 #if 0
-  WATCHPOINT_STRING(ptr->hostname);
-  WATCHPOINT_NUMBER(ptr->port);
-  WATCHPOINT_ERRNO(ptr->cached_errno);
+  WATCHPOINT_STRING(self->hostname);
+  WATCHPOINT_NUMBER(self->port);
+  WATCHPOINT_ERRNO(self->cached_errno);
 #endif
-  if (root->last_disconnected_server)
-    memcached_server_free(root->last_disconnected_server);
-  root->last_disconnected_server= memcached_server_clone(NULL, ptr);
+  memcached_server_free(root->last_disconnected_server);
+  root->last_disconnected_server= memcached_server_clone(NULL, self);
 }
 
 memcached_return_t memcached_connect(memcached_server_write_instance_st ptr)
@@ -570,6 +569,7 @@ memcached_return_t memcached_connect(memcached_server_write_instance_st ptr)
     WATCHPOINT_ASSERT(0);
     rc= MEMCACHED_NOT_SUPPORTED;
     break;
+
   case MEMCACHED_CONNECTION_UDP:
   case MEMCACHED_CONNECTION_TCP:
     rc= network_connect(ptr);
@@ -585,15 +585,17 @@ memcached_return_t memcached_connect(memcached_server_write_instance_st ptr)
     }
 #endif
     break;
+
   case MEMCACHED_CONNECTION_UNIX_SOCKET:
     rc= unix_socket_connect(ptr);
     break;
+
   case MEMCACHED_CONNECTION_MAX:
   default:
     WATCHPOINT_ASSERT(0);
   }
 
-  if (rc == MEMCACHED_SUCCESS)
+  if (memcached_success(rc))
   {
     ptr->server_failure_counter= 0;
     ptr->next_retry= 0;
index 1852e540eca11ecd87f6623fc371cd87b8065203..10af05c8eb83e38f72887450cccf981bbf88e10d 100644 (file)
@@ -448,10 +448,10 @@ memcached_return_t memcached_server_add_with_weight(memcached_st *ptr,
                                                     in_port_t port,
                                                     uint32_t weight)
 {
-  if (! port)
+  if (not port)
     port= MEMCACHED_DEFAULT_PORT;
 
-  if (! hostname)
+  if (not hostname)
     hostname= "localhost";
 
   return server_add(ptr, hostname, port, weight, MEMCACHED_CONNECTION_TCP);
@@ -462,23 +462,23 @@ static memcached_return_t server_add(memcached_st *ptr, const char *hostname,
                                      uint32_t weight,
                                      memcached_connection_t type)
 {
-  memcached_server_st *new_host_list;
-  memcached_server_write_instance_st instance;
 
-  if ( (ptr->flags.use_udp && type != MEMCACHED_CONNECTION_UDP)
-      || ( (type == MEMCACHED_CONNECTION_UDP) && (! ptr->flags.use_udp) ) )
+  if ( (ptr->flags.use_udp and type != MEMCACHED_CONNECTION_UDP)
+      or ( (type == MEMCACHED_CONNECTION_UDP) and (not ptr->flags.use_udp) ) )
+  {
     return MEMCACHED_INVALID_HOST_PROTOCOL;
+  }
 
-  new_host_list= static_cast<memcached_server_st*>(libmemcached_realloc(ptr, memcached_server_list(ptr),
-                                                                       sizeof(memcached_server_st) * (ptr->number_of_hosts + 1)));
+  memcached_server_st *new_host_list= static_cast<memcached_server_st*>(libmemcached_realloc(ptr, memcached_server_list(ptr),
+                                                                                             sizeof(memcached_server_st) * (ptr->number_of_hosts + 1)));
 
-  if (new_host_list == NULL)
+  if (not new_host_list)
     return MEMCACHED_MEMORY_ALLOCATION_FAILURE;
 
   memcached_server_list_set(ptr, new_host_list);
 
   /* TODO: Check return type */
-  instance= memcached_server_instance_fetch(ptr, memcached_server_count(ptr));
+  memcached_server_write_instance_st instance= memcached_server_instance_fetch(ptr, memcached_server_count(ptr));
 
   (void)memcached_server_create_with(ptr, instance, hostname, port, weight, type);
 
index 21306f2a94f784e3b1fae0e4ad834f53209b1b88..f2e8993b5f57200b25372a416890eb34af35fd4b 100644 (file)
@@ -151,8 +151,7 @@ static void _free(memcached_st *ptr, bool release_st)
 
   memcached_virtual_bucket_free(ptr);
 
-  if (ptr->last_disconnected_server)
-    memcached_server_free(ptr->last_disconnected_server);
+  memcached_server_free(ptr->last_disconnected_server);
 
   if (ptr->on_cleanup)
     ptr->on_cleanup(ptr);
@@ -273,33 +272,27 @@ memcached_return_t memcached_reset(memcached_st *ptr)
   return MEMCACHED_SUCCESS;
 }
 
-void memcached_servers_reset(memcached_st *ptr)
+void memcached_servers_reset(memcached_st *self)
 {
-  if (not ptr)
+  if (not self)
     return;
 
-  memcached_server_list_free(memcached_server_list(ptr));
+  memcached_server_list_free(memcached_server_list(self));
 
-  memcached_server_list_set(ptr, NULL);
-  ptr->number_of_hosts= 0;
-  if (ptr->last_disconnected_server)
-  {
-    memcached_server_free(ptr->last_disconnected_server);
-  }
-  ptr->last_disconnected_server= NULL;
-  ptr->server_failure_limit= 0;
+  memcached_server_list_set(self, NULL);
+  self->number_of_hosts= 0;
+  memcached_server_free(self->last_disconnected_server);
+  self->last_disconnected_server= NULL;
+  self->server_failure_limit= 0;
 }
 
-void memcached_reset_last_disconnected_server(memcached_st *ptr)
+void memcached_reset_last_disconnected_server(memcached_st *self)
 {
-  if (not ptr)
+  if (not self)
     return;
 
-  if (ptr->last_disconnected_server)
-  {
-    memcached_server_free(ptr->last_disconnected_server);
-    ptr->last_disconnected_server= NULL;
-  }
+  memcached_server_free(self->last_disconnected_server);
+  self->last_disconnected_server= NULL;
 }
 
 void memcached_free(memcached_st *ptr)
index 491bb0cc37c5066d1d86053ab10f2641ec7c45c0..d199a5fa08ab59df51f83745908b96465f641137 100644 (file)
@@ -522,13 +522,13 @@ static const yytype_int8 yyrhs[] =
 /* YYRLINE[YYN] -- source line where rule number YYN was defined.  */
 static const yytype_uint16 yyrline[] =
 {
-       0,   155,   155,   156,   160,   162,   164,   166,   171,   176,
-     180,   184,   195,   203,   211,   215,   219,   223,   227,   234,
-     241,   252,   259,   266,   273,   279,   283,   287,   291,   295,
-     299,   303,   307,   311,   315,   319,   323,   330,   334,   338,
-     342,   346,   350,   354,   358,   362,   366,   370,   374,   381,
-     382,   387,   388,   393,   397,   401,   405,   409,   413,   417,
-     421,   425,   432,   436,   444,   448,   452
+       0,   157,   157,   158,   162,   164,   166,   168,   173,   178,
+     182,   186,   197,   205,   213,   217,   221,   225,   229,   236,
+     243,   254,   261,   268,   275,   281,   285,   289,   293,   297,
+     301,   305,   309,   313,   317,   321,   325,   332,   336,   340,
+     344,   348,   352,   356,   360,   364,   368,   372,   376,   383,
+     384,   389,   390,   395,   399,   403,   407,   411,   415,   419,
+     423,   427,   434,   438,   446,   450,   454
 };
 #endif
 
@@ -1520,28 +1520,28 @@ yyreduce:
         case 4:
 
 /* Line 1464 of yacc.c  */
-#line 161 "libmemcached/options/parser.yy"
+#line 163 "libmemcached/options/parser.yy"
     { ;}
     break;
 
   case 5:
 
 /* Line 1464 of yacc.c  */
-#line 163 "libmemcached/options/parser.yy"
+#line 165 "libmemcached/options/parser.yy"
     { ;}
     break;
 
   case 6:
 
 /* Line 1464 of yacc.c  */
-#line 165 "libmemcached/options/parser.yy"
+#line 167 "libmemcached/options/parser.yy"
     { ;}
     break;
 
   case 7:
 
 /* Line 1464 of yacc.c  */
-#line 167 "libmemcached/options/parser.yy"
+#line 169 "libmemcached/options/parser.yy"
     {
             context->set_end();
             YYACCEPT;
@@ -1551,7 +1551,7 @@ yyreduce:
   case 8:
 
 /* Line 1464 of yacc.c  */
-#line 172 "libmemcached/options/parser.yy"
+#line 174 "libmemcached/options/parser.yy"
     {
             context->rc= MEMCACHED_PARSE_USER_ERROR;
             parser_abort(context, NULL);
@@ -1561,7 +1561,7 @@ yyreduce:
   case 9:
 
 /* Line 1464 of yacc.c  */
-#line 177 "libmemcached/options/parser.yy"
+#line 179 "libmemcached/options/parser.yy"
     {
             memcached_reset(context->memc);
           ;}
@@ -1570,7 +1570,7 @@ yyreduce:
   case 10:
 
 /* Line 1464 of yacc.c  */
-#line 181 "libmemcached/options/parser.yy"
+#line 183 "libmemcached/options/parser.yy"
     {
             yydebug= 1;
           ;}
@@ -1579,7 +1579,7 @@ yyreduce:
   case 11:
 
 /* Line 1464 of yacc.c  */
-#line 185 "libmemcached/options/parser.yy"
+#line 187 "libmemcached/options/parser.yy"
     {
             if ((context->rc= memcached_parse_configure_file(context->memc, (yyvsp[(3) - (3)].string).c_str, (yyvsp[(3) - (3)].string).size)) != MEMCACHED_SUCCESS)
             {
@@ -1591,9 +1591,9 @@ yyreduce:
   case 12:
 
 /* Line 1464 of yacc.c  */
-#line 196 "libmemcached/options/parser.yy"
+#line 198 "libmemcached/options/parser.yy"
     {
-            if ((context->rc= memcached_server_add_with_weight(context->memc, (yyvsp[(2) - (4)].server).c_str, (yyvsp[(2) - (4)].server).port, (yyvsp[(2) - (4)].server).weight)) != MEMCACHED_SUCCESS)
+            if (memcached_failed(context->rc= memcached_server_add_with_weight(context->memc, (yyvsp[(2) - (4)].server).c_str, (yyvsp[(3) - (4)].number), (yyvsp[(4) - (4)].number))))
             {
               parser_abort(context, NULL);
             }
@@ -1604,9 +1604,9 @@ yyreduce:
   case 13:
 
 /* Line 1464 of yacc.c  */
-#line 204 "libmemcached/options/parser.yy"
+#line 206 "libmemcached/options/parser.yy"
     {
-            if ((context->rc= memcached_server_add_with_weight(context->memc, (yyvsp[(2) - (4)].server).c_str, (yyvsp[(2) - (4)].server).port, (yyvsp[(2) - (4)].server).weight)) != MEMCACHED_SUCCESS)
+            if (memcached_failed(context->rc= memcached_server_add_with_weight(context->memc, (yyvsp[(2) - (4)].server).c_str, (yyvsp[(3) - (4)].number), (yyvsp[(4) - (4)].number))))
             {
               parser_abort(context, NULL);
             }
@@ -1617,7 +1617,7 @@ yyreduce:
   case 14:
 
 /* Line 1464 of yacc.c  */
-#line 212 "libmemcached/options/parser.yy"
+#line 214 "libmemcached/options/parser.yy"
     {
             memcached_set_configuration_file(context->memc, (yyvsp[(2) - (2)].string).c_str, (yyvsp[(2) - (2)].string).size);
           ;}
@@ -1626,7 +1626,7 @@ yyreduce:
   case 15:
 
 /* Line 1464 of yacc.c  */
-#line 216 "libmemcached/options/parser.yy"
+#line 218 "libmemcached/options/parser.yy"
     {
             context->memc->configure.initial_pool_size= (yyvsp[(2) - (2)].number);
           ;}
@@ -1635,7 +1635,7 @@ yyreduce:
   case 16:
 
 /* Line 1464 of yacc.c  */
-#line 220 "libmemcached/options/parser.yy"
+#line 222 "libmemcached/options/parser.yy"
     {
             context->memc->configure.max_pool_size= (yyvsp[(2) - (2)].number);
           ;}
@@ -1644,7 +1644,7 @@ yyreduce:
   case 18:
 
 /* Line 1464 of yacc.c  */
-#line 228 "libmemcached/options/parser.yy"
+#line 230 "libmemcached/options/parser.yy"
     {
             if ((context->rc= memcached_set_prefix_key(context->memc, (yyvsp[(2) - (2)].string).c_str, (yyvsp[(2) - (2)].string).size)) != MEMCACHED_SUCCESS)
             {
@@ -1656,7 +1656,7 @@ yyreduce:
   case 19:
 
 /* Line 1464 of yacc.c  */
-#line 235 "libmemcached/options/parser.yy"
+#line 237 "libmemcached/options/parser.yy"
     {
             if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, (yyvsp[(2) - (2)].distribution))) != MEMCACHED_SUCCESS)
             {
@@ -1668,7 +1668,7 @@ yyreduce:
   case 20:
 
 /* Line 1464 of yacc.c  */
-#line 242 "libmemcached/options/parser.yy"
+#line 244 "libmemcached/options/parser.yy"
     {
             if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, (yyvsp[(2) - (4)].distribution))) != MEMCACHED_SUCCESS)
             {
@@ -1684,7 +1684,7 @@ yyreduce:
   case 21:
 
 /* Line 1464 of yacc.c  */
-#line 253 "libmemcached/options/parser.yy"
+#line 255 "libmemcached/options/parser.yy"
     {
             if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_HASH, (yyvsp[(2) - (2)].hash))) != MEMCACHED_SUCCESS)
             {
@@ -1696,7 +1696,7 @@ yyreduce:
   case 22:
 
 /* Line 1464 of yacc.c  */
-#line 260 "libmemcached/options/parser.yy"
+#line 262 "libmemcached/options/parser.yy"
     {
             if ((context->rc= memcached_behavior_set(context->memc, (yyvsp[(1) - (2)].behavior), (yyvsp[(2) - (2)].number))) != MEMCACHED_SUCCESS)
             {
@@ -1708,7 +1708,7 @@ yyreduce:
   case 23:
 
 /* Line 1464 of yacc.c  */
-#line 267 "libmemcached/options/parser.yy"
+#line 269 "libmemcached/options/parser.yy"
     {
             if ((context->rc= memcached_behavior_set(context->memc, (yyvsp[(1) - (1)].behavior), true)) != MEMCACHED_SUCCESS)
             {
@@ -1720,7 +1720,7 @@ yyreduce:
   case 24:
 
 /* Line 1464 of yacc.c  */
-#line 274 "libmemcached/options/parser.yy"
+#line 276 "libmemcached/options/parser.yy"
     {
           ;}
     break;
@@ -1728,7 +1728,7 @@ yyreduce:
   case 25:
 
 /* Line 1464 of yacc.c  */
-#line 280 "libmemcached/options/parser.yy"
+#line 282 "libmemcached/options/parser.yy"
     {
             (yyval.behavior)= MEMCACHED_BEHAVIOR_REMOVE_FAILED_SERVERS;
           ;}
@@ -1737,7 +1737,7 @@ yyreduce:
   case 26:
 
 /* Line 1464 of yacc.c  */
-#line 284 "libmemcached/options/parser.yy"
+#line 286 "libmemcached/options/parser.yy"
     {
             (yyval.behavior)= MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT;
           ;}
@@ -1746,7 +1746,7 @@ yyreduce:
   case 27:
 
 /* Line 1464 of yacc.c  */
-#line 288 "libmemcached/options/parser.yy"
+#line 290 "libmemcached/options/parser.yy"
     {
             (yyval.behavior)= MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK;
           ;}
@@ -1755,7 +1755,7 @@ yyreduce:
   case 28:
 
 /* Line 1464 of yacc.c  */
-#line 292 "libmemcached/options/parser.yy"
+#line 294 "libmemcached/options/parser.yy"
     {
             (yyval.behavior)= MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK;
           ;}
@@ -1764,7 +1764,7 @@ yyreduce:
   case 29:
 
 /* Line 1464 of yacc.c  */
-#line 296 "libmemcached/options/parser.yy"
+#line 298 "libmemcached/options/parser.yy"
     {
             (yyval.behavior)= MEMCACHED_BEHAVIOR_IO_KEY_PREFETCH;
           ;}
@@ -1773,7 +1773,7 @@ yyreduce:
   case 30:
 
 /* Line 1464 of yacc.c  */
-#line 300 "libmemcached/options/parser.yy"
+#line 302 "libmemcached/options/parser.yy"
     {
             (yyval.behavior)= MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS;
           ;}
@@ -1782,7 +1782,7 @@ yyreduce:
   case 31:
 
 /* Line 1464 of yacc.c  */
-#line 304 "libmemcached/options/parser.yy"
+#line 306 "libmemcached/options/parser.yy"
     {
             (yyval.behavior)= MEMCACHED_BEHAVIOR_POLL_TIMEOUT;
           ;}
@@ -1791,7 +1791,7 @@ yyreduce:
   case 32:
 
 /* Line 1464 of yacc.c  */
-#line 308 "libmemcached/options/parser.yy"
+#line 310 "libmemcached/options/parser.yy"
     {
             (yyval.behavior)= MEMCACHED_BEHAVIOR_RCV_TIMEOUT;
           ;}
@@ -1800,7 +1800,7 @@ yyreduce:
   case 33:
 
 /* Line 1464 of yacc.c  */
-#line 312 "libmemcached/options/parser.yy"
+#line 314 "libmemcached/options/parser.yy"
     {
             (yyval.behavior)= MEMCACHED_BEHAVIOR_RETRY_TIMEOUT;
           ;}
@@ -1809,7 +1809,7 @@ yyreduce:
   case 34:
 
 /* Line 1464 of yacc.c  */
-#line 316 "libmemcached/options/parser.yy"
+#line 318 "libmemcached/options/parser.yy"
     {
             (yyval.behavior)= MEMCACHED_BEHAVIOR_SND_TIMEOUT;
           ;}
@@ -1818,7 +1818,7 @@ yyreduce:
   case 35:
 
 /* Line 1464 of yacc.c  */
-#line 320 "libmemcached/options/parser.yy"
+#line 322 "libmemcached/options/parser.yy"
     {
             (yyval.behavior)= MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE;
           ;}
@@ -1827,7 +1827,7 @@ yyreduce:
   case 36:
 
 /* Line 1464 of yacc.c  */
-#line 324 "libmemcached/options/parser.yy"
+#line 326 "libmemcached/options/parser.yy"
     {
             (yyval.behavior)= MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE;
           ;}
@@ -1836,7 +1836,7 @@ yyreduce:
   case 37:
 
 /* Line 1464 of yacc.c  */
-#line 331 "libmemcached/options/parser.yy"
+#line 333 "libmemcached/options/parser.yy"
     {
             (yyval.behavior)= MEMCACHED_BEHAVIOR_BINARY_PROTOCOL;
           ;}
@@ -1845,7 +1845,7 @@ yyreduce:
   case 38:
 
 /* Line 1464 of yacc.c  */
-#line 335 "libmemcached/options/parser.yy"
+#line 337 "libmemcached/options/parser.yy"
     {
             (yyval.behavior)= MEMCACHED_BEHAVIOR_BUFFER_REQUESTS;
           ;}
@@ -1854,7 +1854,7 @@ yyreduce:
   case 39:
 
 /* Line 1464 of yacc.c  */
-#line 339 "libmemcached/options/parser.yy"
+#line 341 "libmemcached/options/parser.yy"
     {
             (yyval.behavior)= MEMCACHED_BEHAVIOR_HASH_WITH_PREFIX_KEY;
           ;}
@@ -1863,7 +1863,7 @@ yyreduce:
   case 40:
 
 /* Line 1464 of yacc.c  */
-#line 343 "libmemcached/options/parser.yy"
+#line 345 "libmemcached/options/parser.yy"
     {
             (yyval.behavior)= MEMCACHED_BEHAVIOR_NOREPLY;
           ;}
@@ -1872,7 +1872,7 @@ yyreduce:
   case 41:
 
 /* Line 1464 of yacc.c  */
-#line 347 "libmemcached/options/parser.yy"
+#line 349 "libmemcached/options/parser.yy"
     {
             (yyval.behavior)= MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ;
           ;}
@@ -1881,7 +1881,7 @@ yyreduce:
   case 42:
 
 /* Line 1464 of yacc.c  */
-#line 351 "libmemcached/options/parser.yy"
+#line 353 "libmemcached/options/parser.yy"
     {
             (yyval.behavior)= MEMCACHED_BEHAVIOR_SORT_HOSTS;
           ;}
@@ -1890,7 +1890,7 @@ yyreduce:
   case 43:
 
 /* Line 1464 of yacc.c  */
-#line 355 "libmemcached/options/parser.yy"
+#line 357 "libmemcached/options/parser.yy"
     {
             (yyval.behavior)= MEMCACHED_BEHAVIOR_SUPPORT_CAS;
           ;}
@@ -1899,7 +1899,7 @@ yyreduce:
   case 44:
 
 /* Line 1464 of yacc.c  */
-#line 359 "libmemcached/options/parser.yy"
+#line 361 "libmemcached/options/parser.yy"
     {
             (yyval.behavior)= MEMCACHED_BEHAVIOR_TCP_NODELAY;
           ;}
@@ -1908,7 +1908,7 @@ yyreduce:
   case 45:
 
 /* Line 1464 of yacc.c  */
-#line 363 "libmemcached/options/parser.yy"
+#line 365 "libmemcached/options/parser.yy"
     {
             (yyval.behavior)= MEMCACHED_BEHAVIOR_TCP_KEEPALIVE;
           ;}
@@ -1917,7 +1917,7 @@ yyreduce:
   case 46:
 
 /* Line 1464 of yacc.c  */
-#line 367 "libmemcached/options/parser.yy"
+#line 369 "libmemcached/options/parser.yy"
     {
             (yyval.behavior)= MEMCACHED_BEHAVIOR_TCP_KEEPIDLE;
           ;}
@@ -1926,7 +1926,7 @@ yyreduce:
   case 47:
 
 /* Line 1464 of yacc.c  */
-#line 371 "libmemcached/options/parser.yy"
+#line 373 "libmemcached/options/parser.yy"
     {
             (yyval.behavior)= MEMCACHED_BEHAVIOR_USE_UDP;
           ;}
@@ -1935,7 +1935,7 @@ yyreduce:
   case 48:
 
 /* Line 1464 of yacc.c  */
-#line 375 "libmemcached/options/parser.yy"
+#line 377 "libmemcached/options/parser.yy"
     {
             (yyval.behavior)= MEMCACHED_BEHAVIOR_VERIFY_KEY;
           ;}
@@ -1944,35 +1944,35 @@ yyreduce:
   case 49:
 
 /* Line 1464 of yacc.c  */
-#line 381 "libmemcached/options/parser.yy"
-    { ;}
+#line 383 "libmemcached/options/parser.yy"
+    { (yyval.number)= MEMCACHED_DEFAULT_PORT;;}
     break;
 
   case 50:
 
 /* Line 1464 of yacc.c  */
-#line 383 "libmemcached/options/parser.yy"
+#line 385 "libmemcached/options/parser.yy"
     { ;}
     break;
 
   case 51:
 
 /* Line 1464 of yacc.c  */
-#line 387 "libmemcached/options/parser.yy"
-    { ;}
+#line 389 "libmemcached/options/parser.yy"
+    { (yyval.number)= 1; ;}
     break;
 
   case 52:
 
 /* Line 1464 of yacc.c  */
-#line 389 "libmemcached/options/parser.yy"
+#line 391 "libmemcached/options/parser.yy"
     { ;}
     break;
 
   case 53:
 
 /* Line 1464 of yacc.c  */
-#line 394 "libmemcached/options/parser.yy"
+#line 396 "libmemcached/options/parser.yy"
     {
             (yyval.hash)= MEMCACHED_HASH_MD5;
           ;}
@@ -1981,7 +1981,7 @@ yyreduce:
   case 54:
 
 /* Line 1464 of yacc.c  */
-#line 398 "libmemcached/options/parser.yy"
+#line 400 "libmemcached/options/parser.yy"
     {
             (yyval.hash)= MEMCACHED_HASH_CRC;
           ;}
@@ -1990,7 +1990,7 @@ yyreduce:
   case 55:
 
 /* Line 1464 of yacc.c  */
-#line 402 "libmemcached/options/parser.yy"
+#line 404 "libmemcached/options/parser.yy"
     {
             (yyval.hash)= MEMCACHED_HASH_FNV1_64;
           ;}
@@ -1999,7 +1999,7 @@ yyreduce:
   case 56:
 
 /* Line 1464 of yacc.c  */
-#line 406 "libmemcached/options/parser.yy"
+#line 408 "libmemcached/options/parser.yy"
     {
             (yyval.hash)= MEMCACHED_HASH_FNV1A_64;
           ;}
@@ -2008,7 +2008,7 @@ yyreduce:
   case 57:
 
 /* Line 1464 of yacc.c  */
-#line 410 "libmemcached/options/parser.yy"
+#line 412 "libmemcached/options/parser.yy"
     {
             (yyval.hash)= MEMCACHED_HASH_FNV1_32;
           ;}
@@ -2017,7 +2017,7 @@ yyreduce:
   case 58:
 
 /* Line 1464 of yacc.c  */
-#line 414 "libmemcached/options/parser.yy"
+#line 416 "libmemcached/options/parser.yy"
     {
             (yyval.hash)= MEMCACHED_HASH_FNV1A_32;
           ;}
@@ -2026,7 +2026,7 @@ yyreduce:
   case 59:
 
 /* Line 1464 of yacc.c  */
-#line 418 "libmemcached/options/parser.yy"
+#line 420 "libmemcached/options/parser.yy"
     {
             (yyval.hash)= MEMCACHED_HASH_HSIEH;
           ;}
@@ -2035,7 +2035,7 @@ yyreduce:
   case 60:
 
 /* Line 1464 of yacc.c  */
-#line 422 "libmemcached/options/parser.yy"
+#line 424 "libmemcached/options/parser.yy"
     {
             (yyval.hash)= MEMCACHED_HASH_MURMUR;
           ;}
@@ -2044,7 +2044,7 @@ yyreduce:
   case 61:
 
 /* Line 1464 of yacc.c  */
-#line 426 "libmemcached/options/parser.yy"
+#line 428 "libmemcached/options/parser.yy"
     {
             (yyval.hash)= MEMCACHED_HASH_JENKINS;
           ;}
@@ -2053,7 +2053,7 @@ yyreduce:
   case 62:
 
 /* Line 1464 of yacc.c  */
-#line 433 "libmemcached/options/parser.yy"
+#line 435 "libmemcached/options/parser.yy"
     {
             (yyval.string)= (yyvsp[(1) - (1)].string);
           ;}
@@ -2062,7 +2062,7 @@ yyreduce:
   case 63:
 
 /* Line 1464 of yacc.c  */
-#line 437 "libmemcached/options/parser.yy"
+#line 439 "libmemcached/options/parser.yy"
     {
             (yyval.string).c_str= (yyvsp[(1) - (1)].string).c_str +1; // +1 to move use passed the initial quote
             (yyval.string).size= (yyvsp[(1) - (1)].string).size -2; // -2 removes the begin and end quote
@@ -2072,7 +2072,7 @@ yyreduce:
   case 64:
 
 /* Line 1464 of yacc.c  */
-#line 445 "libmemcached/options/parser.yy"
+#line 447 "libmemcached/options/parser.yy"
     {
             (yyval.distribution)= MEMCACHED_DISTRIBUTION_CONSISTENT;
           ;}
@@ -2081,7 +2081,7 @@ yyreduce:
   case 65:
 
 /* Line 1464 of yacc.c  */
-#line 449 "libmemcached/options/parser.yy"
+#line 451 "libmemcached/options/parser.yy"
     {
             (yyval.distribution)= MEMCACHED_DISTRIBUTION_MODULA;
           ;}
@@ -2090,7 +2090,7 @@ yyreduce:
   case 66:
 
 /* Line 1464 of yacc.c  */
-#line 453 "libmemcached/options/parser.yy"
+#line 455 "libmemcached/options/parser.yy"
     {
             (yyval.distribution)= MEMCACHED_DISTRIBUTION_RANDOM;
           ;}
@@ -2311,7 +2311,7 @@ yyreturn:
 
 
 /* Line 1684 of yacc.c  */
-#line 458 "libmemcached/options/parser.yy"
+#line 460 "libmemcached/options/parser.yy"
  
 
 void Context::start() 
index 84d1c69ce5c121bba159756444b0df9abafe3d9a..fd5a0cb98ae53aa4f3fe4ff38ed69d1140285805 100644 (file)
@@ -1568,17 +1568,17 @@ YY_RULE_SETUP
 case 2:
 YY_RULE_SETUP
 #line 79 "libmemcached/options/scanner.l"
-{ yylval->number = atoi(yytext); return (NUMBER); }
+{ yylval->number= atoi(yytext); return (NUMBER); }
        YY_BREAK
 case 3:
 YY_RULE_SETUP
 #line 81 "libmemcached/options/scanner.l"
-{ yylval->server.port = atoi(yytext +1); return PORT; }
+{ yylval->number= atoi(yytext +1); return PORT; }
        YY_BREAK
 case 4:
 YY_RULE_SETUP
 #line 83 "libmemcached/options/scanner.l"
-{ yylval->server.weight = atoi(yytext +2); return WEIGHT_START; }
+{ yylval->number= atoi(yytext +2); return WEIGHT_START; }
        YY_BREAK
 case 5:
 /* rule 5 can match eol */
index cd5d9ecd9e7275dcb20a235de8936a22e2c382f8..fb045ce1d9a05545e95d8a75dd0b961386e62a7d 100644 (file)
@@ -67,7 +67,7 @@ void memcached_quit_server(memcached_server_st *ptr, bool io_death)
       }
       else
       {
-        rc= memcached_do(ptr, "quit\r\n", sizeof("quit\r\n") -1, true);
+        rc= memcached_do(ptr, memcached_literal_param("quit\r\n"), true);
       }
 
       WATCHPOINT_ASSERT(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_FETCH_NOTFINISHED);
index 72f1b822808fd810c76fb8a4b14001926ef0235b..57540ccff06d150f9db5c1ed5e997ffe086a7783 100644 (file)
@@ -135,7 +135,9 @@ memcached_server_st *memcached_server_create_with(const memcached_st *memc,
 
 void memcached_server_free(memcached_server_st *self)
 {
-  assert(self);
+  if (not self)
+    return;
+
   memcached_quit_server(self, false);
 
   if (self->cached_server_error)
@@ -167,7 +169,7 @@ memcached_server_st *memcached_server_clone(memcached_server_st *destination,
   destination= memcached_server_create_with(source->root, destination,
                                             source->hostname, source->port, source->weight,
                                             source->type);
-  if (destination != NULL)
+  if (not destination)
   {
     destination->cached_errno= source->cached_errno;
 
index 712c13d9ac8204ce3ce5934a13b64d99674d7920..14141a0b4e95ac0da50eed997541ef972139838b 100644 (file)
@@ -5380,13 +5380,14 @@ static test_return_t test_get_last_disconnect(memcached_st *memc)
   const char *value= "milka";
 
   memcached_reset_last_disconnected_server(memc);
+  test_false(memc->last_disconnected_server);
   rc= memcached_set(memc, key, strlen(key),
                     value, strlen(value),
                     (time_t)0, (uint32_t)0);
   test_true(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
 
   disconnected_server = memcached_server_get_last_disconnect(memc);
-  test_true(disconnected_server == NULL);
+  test_false(disconnected_server);
 
   /* With a non existing server */
   memcached_st *mine;
@@ -5405,16 +5406,11 @@ static test_return_t test_get_last_disconnect(memcached_st *memc)
   rc= memcached_set(mine, key, strlen(key),
                     value, strlen(value),
                     (time_t)0, (uint32_t)0);
-  test_true(rc != MEMCACHED_SUCCESS);
+  test_true(memcached_failed(rc));
 
   disconnected_server= memcached_server_get_last_disconnect(mine);
-  if (disconnected_server == NULL)
-  {
-    fprintf(stderr, "RC %s\n", memcached_strerror(mine, rc));
-    abort();
-  }
-  test_true(disconnected_server != NULL);
-  test_true(memcached_server_port(disconnected_server)== 9);
+  test_true_got(disconnected_server, memcached_strerror(mine, rc));
+  test_compare(9, memcached_server_port(disconnected_server));
   test_true(strncmp(memcached_server_name(disconnected_server),"localhost",9) == 0);
 
   memcached_quit(mine);
@@ -5423,6 +5419,46 @@ static test_return_t test_get_last_disconnect(memcached_st *memc)
   return TEST_SUCCESS;
 }
 
+static test_return_t test_multiple_get_last_disconnect(memcached_st *)
+{
+  const char *server_string= "--server=localhost:8888 --server=localhost:8889 --server=localhost:8890 --server=localhost:8891 --server=localhost:8892";
+  char buffer[BUFSIZ];
+
+  memcached_return_t rc;
+  test_compare_got(MEMCACHED_SUCCESS,
+                   rc= libmemcached_check_configuration(server_string, strlen(server_string), buffer, sizeof(buffer)),
+                   memcached_strerror(NULL, rc));
+
+  memcached_st *memc= memcached(server_string, strlen(server_string));
+  test_true(memc);
+
+  // We will just use the error strings as our keys
+  uint32_t counter= 100;
+  while (--counter)
+  {
+    for (int x= int(MEMCACHED_SUCCESS); x < int(MEMCACHED_MAXIMUM_RETURN); ++x)
+    {
+      const char *msg=  memcached_strerror(memc, memcached_return_t(x));
+      memcached_return_t ret= memcached_set(memc, msg, strlen(msg), NULL, 0, (time_t)0, (uint32_t)0);
+      test_compare_got(MEMCACHED_WRITE_FAILURE, ret, memcached_strerror(NULL, ret));
+
+      memcached_server_instance_st disconnected_server= memcached_server_get_last_disconnect(memc);
+      test_true(disconnected_server);
+      test_strcmp("localhost", memcached_server_name(disconnected_server));
+      test_true(memcached_server_port(disconnected_server) >= 8888 and memcached_server_port(disconnected_server) <= 8892);
+
+      if (random() % 2)
+      {
+        memcached_reset_last_disconnected_server(memc);
+      }
+    }
+  }
+
+  memcached_free(memc);
+
+  return TEST_SUCCESS;
+}
+
 static test_return_t test_verbosity(memcached_st *memc)
 {
   memcached_verbosity(memc, 3);
@@ -6017,6 +6053,12 @@ test_st string_tests[] ={
   {0, 0, (test_callback_fn)0}
 };
 
+test_st memcached_server_get_last_disconnect_tests[] ={
+  {"memcached_server_get_last_disconnect()", 0, (test_callback_fn)test_multiple_get_last_disconnect},
+  {0, 0, (test_callback_fn)0}
+};
+
+
 test_st result_tests[] ={
   {"result static", 0, (test_callback_fn)result_static},
   {"result alloc", 0, (test_callback_fn)result_alloc},
@@ -6208,6 +6250,7 @@ test_st parser_tests[] ={
   {"server", 0, (test_callback_fn)server_test },
   {"bad server strings", 0, (test_callback_fn)servers_bad_test },
   {"server with weights", 0, (test_callback_fn)server_with_weight_test },
+  {"parsing servername, port, and weight", 0, (test_callback_fn)test_hostname_port_weight },
   {0, 0, (test_callback_fn)0}
 };
 
@@ -6281,6 +6324,7 @@ collection_st collection[] ={
   {"error_conditions", 0, 0, error_conditions},
   {"parser", 0, 0, parser_tests},
   {"virtual buckets", 0, 0, virtual_bucket_tests},
+  {"memcached_server_get_last_disconnect", 0, 0, memcached_server_get_last_disconnect_tests},
   {0, 0, 0, 0}
 };
 
index 68a65a40f011aaeab15e8e71da5601e8cfb298ec..7a8b869070a8a64a08742dabb22d975c440696be 100644 (file)
@@ -40,7 +40,8 @@
 #include <vector>
 #include <iostream>
 #include <string>
-#include <errno.h>
+#include <cerrno>
+#include <cassert>
 
 #define BUILDING_LIBMEMCACHED
 // !NEVER use common.h, always use memcached.h in your own apps
@@ -497,3 +498,50 @@ test_return_t random_statement_build_test(memcached_st*)
 
   return TEST_SUCCESS;
 }
+
+static memcached_return_t dump_server_information(const memcached_st *,
+                                                  const memcached_server_st *instance,
+                                                  void *)
+{
+  if (strcmp(memcached_server_name(instance), "localhost")) 
+  {
+    assert(not memcached_server_name(instance));
+    return MEMCACHED_FAILURE;
+  }
+
+  if (memcached_server_port(instance) < 8888 or memcached_server_port(instance) > 8892)
+  {
+    assert(not memcached_server_port(instance));
+    return MEMCACHED_FAILURE;
+  }
+
+  if (instance->weight > 5 or instance->weight < 2)
+  {
+    assert(not instance->weight);
+    return MEMCACHED_FAILURE;
+  }
+
+  return MEMCACHED_SUCCESS;
+}
+
+
+test_return_t test_hostname_port_weight(memcached_st *)
+{
+  const char *server_string= "--server=localhost:8888/?2 --server=localhost:8889/?3 --server=localhost:8890/?4 --server=localhost:8891/?5 --server=localhost:8892/?3";
+  char buffer[BUFSIZ];
+
+  memcached_return_t rc;
+  test_compare_got(MEMCACHED_SUCCESS,
+                   rc= libmemcached_check_configuration(server_string, strlen(server_string), buffer, sizeof(buffer)),
+                   memcached_strerror(NULL, rc));
+
+  memcached_st *memc= memcached(server_string, strlen(server_string));
+  test_true(memc);
+
+  memcached_server_fn callbacks[]= { dump_server_information };
+  test_true(memcached_success(memcached_server_cursor(memc, callbacks, NULL, 1)));
+
+  memcached_free(memc);
+
+  return TEST_SUCCESS;
+}
index c53f0e411fca128fb47316dd2a80e6a1f2baa77a..dba9bc59ca55b97142cf9a4d6d2060a9edebeb36 100644 (file)
@@ -97,6 +97,9 @@ test_return_t test_error_keyword(memcached_st*);
 LIBTEST_INTERNAL_API
 test_return_t server_with_weight_test(memcached_st *);
 
+LIBTEST_INTERNAL_API
+test_return_t test_hostname_port_weight(memcached_st *);
+
 #ifdef __cplusplus
 }
 #endif