X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;ds=sidebyside;f=libmemcached%2Futil%2Fpid.cc;h=de009fbbdfac38f8b5c3d84b4189158065b814db;hb=5d66b2f99bf7de6f54a3e463b01542b997f68ac8;hp=d9ba79c7b28bdd36aee9251fe1b8e83435296082;hpb=12a07e58df95bb8dbe167e4157b29c910177ade8;p=m6w6%2Flibmemcached diff --git a/libmemcached/util/pid.cc b/libmemcached/util/pid.cc index d9ba79c7..de009fbb 100644 --- a/libmemcached/util/pid.cc +++ b/libmemcached/util/pid.cc @@ -56,31 +56,104 @@ pid_t libmemcached_util_getpid(const char *hostname, in_port_t port, memcached_r if (not memc_ptr) { *ret= MEMCACHED_MEMORY_ALLOCATION_FAILURE; - return pid; + return -1; } memcached_return_t rc= memcached_server_add(memc_ptr, hostname, port); if (memcached_success(rc)) { memcached_stat_st *stat= memcached_stat(memc_ptr, NULL, &rc); - if (stat and stat->pid > 0) + if (memcached_success(rc) and stat and stat->pid != -1) { pid= stat->pid; } - else if (memcached_failed(rc) and rc == MEMCACHED_SOME_ERRORS) + else if (memcached_success(rc)) + { + rc= MEMCACHED_UNKNOWN_STAT_KEY; // Something went wrong if this happens + } + else if (rc == MEMCACHED_SOME_ERRORS) // Generic answer, we will now find the specific reason (if one exists) { memcached_server_instance_st instance= memcached_server_instance_by_position(memc_ptr, 0); + assert_msg(instance and instance->error_messages, " "); if (instance and instance->error_messages) { rc= memcached_server_error_return(instance); } } + + memcached_stat_free(memc_ptr, stat); + } + memcached_free(memc_ptr); + + *ret= rc; + + return pid; +} + +pid_t libmemcached_util_getpid2(const char *hostname, in_port_t port, const char *username, const char *password, memcached_return_t *ret) +{ + if (username == NULL) + { + return libmemcached_util_getpid(hostname, port, ret); + } + + pid_t pid= -1; + + memcached_return_t unused; + if (not ret) + ret= &unused; + + if (LIBMEMCACHED_WITH_SASL_SUPPORT == 0) + { + *ret= MEMCACHED_NOT_SUPPORTED; + return pid; + } + + memcached_st *memc_ptr= memcached_create(NULL); + if (not memc_ptr) + { + *ret= MEMCACHED_MEMORY_ALLOCATION_FAILURE; + return -1; + } + + if (memcached_failed(*ret= memcached_behavior_set(memc_ptr, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, 1))) + { + memcached_free(memc_ptr); + return false; + } + + if (memcached_failed(*ret= memcached_set_sasl_auth_data(memc_ptr, username, password))) + { + memcached_free(memc_ptr); + return false; + } + + + memcached_return_t rc= memcached_server_add(memc_ptr, hostname, port); + if (memcached_success(rc)) + { + memcached_stat_st *stat= memcached_stat(memc_ptr, NULL, &rc); + if (memcached_success(rc) and stat and stat->pid != -1) + { + pid= stat->pid; + } else if (memcached_success(rc)) { rc= MEMCACHED_UNKNOWN_STAT_KEY; // Something went wrong if this happens } + else if (rc == MEMCACHED_SOME_ERRORS) // Generic answer, we will now find the specific reason (if one exists) + { + memcached_server_instance_st instance= + memcached_server_instance_by_position(memc_ptr, 0); + + assert_msg(instance and instance->error_messages, " "); + if (instance and instance->error_messages) + { + rc= memcached_server_error_return(instance); + } + } memcached_stat_free(memc_ptr, stat); } @@ -90,4 +163,3 @@ pid_t libmemcached_util_getpid(const char *hostname, in_port_t port, memcached_r return pid; } -