X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libmemcached%2Futil%2Fpid.cc;h=0ac3d4f38ad6617df226dcc9544ba6e2bce317cb;hb=3e87de62b0b39279bdec62a07b45e42fe798fd41;hp=d9ba79c7b28bdd36aee9251fe1b8e83435296082;hpb=9cd57ce737375540f6c3b5e2e3684160e5c4bfce;p=m6w6%2Flibmemcached diff --git a/libmemcached/util/pid.cc b/libmemcached/util/pid.cc index d9ba79c7..0ac3d4f3 100644 --- a/libmemcached/util/pid.cc +++ b/libmemcached/util/pid.cc @@ -56,31 +56,100 @@ 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_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); + +#if 0 + assert_msg(instance and instance->error_messages, " "); +#endif + if (instance and instance->error_messages) + { + rc= memcached_server_error_return(instance); + } + } memcached_stat_free(memc_ptr, stat); } @@ -90,4 +159,3 @@ pid_t libmemcached_util_getpid(const char *hostname, in_port_t port, memcached_r return pid; } -