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)
WATCHPOINT_ASSERT(0);
rc= MEMCACHED_NOT_SUPPORTED;
break;
+
case MEMCACHED_CONNECTION_UDP:
case MEMCACHED_CONNECTION_TCP:
rc= network_connect(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;
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);
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)
}
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);
void memcached_server_free(memcached_server_st *self)
{
- assert(self);
+ if (not self)
+ return;
+
memcached_quit_server(self, false);
if (self->cached_server_error)
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;
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;
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);