You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@zookeeper.apache.org by 李赫元 <li...@gmail.com> on 2012/05/14 11:04:12 UTC
How to know if connection to zk is successful in C API.
Hi All,
I encounter a problem in zookeeper 3.4.1 with C API.
The following is always show "success" even the zkserver is actually down.
char* zk_server = "127.0.0.1:2181";
zhandle_t* zh = zookeeper_init(zk_server, watcher_callback, 3000,
0, NULL, 0);
if(!zh)
{
print_error(errno);
return -1;
}else
{
::std::cout << "success" << ::std::endl;
}
Even if the zookeeper is shutdown, the zh handle is still not NULL.
So, I don't know how to judge if connection to zookeeper is succful in C API.
Thanks all.
Heyuan Li
Re: How to know if connection to zk is successful in C API.
Posted by 李赫元 <li...@gmail.com>.
Thanks, I have found that a ZOO_SESSION_EVENT event with state
ZOO_CONNECTED_STATE will be recv after session is built.
2012/5/14 Martin Kou <bi...@gmail.com>:
> The connection API is asynchronous, you'll need to look for the session
> state changes in the watcher_callback.
>
> Best Regards,
> Martin Kou
>
> On Mon, May 14, 2012 at 2:04 AM, 李赫元 <li...@gmail.com> wrote:
>
>> Hi All,
>>
>> I encounter a problem in zookeeper 3.4.1 with C API.
>> The following is always show "success" even the zkserver is actually down.
>>
>> char* zk_server = "127.0.0.1:2181";
>> zhandle_t* zh = zookeeper_init(zk_server, watcher_callback, 3000,
>> 0, NULL, 0);
>> if(!zh)
>> {
>> print_error(errno);
>> return -1;
>> }else
>> {
>> ::std::cout << "success" << ::std::endl;
>> }
>>
>> Even if the zookeeper is shutdown, the zh handle is still not NULL.
>> So, I don't know how to judge if connection to zookeeper is succful in C
>> API.
>>
>> Thanks all.
>>
>> Heyuan Li
>>
Re: How to know if connection to zk is successful in C API.
Posted by Martin Kou <bi...@gmail.com>.
The connection API is asynchronous, you'll need to look for the session
state changes in the watcher_callback.
Best Regards,
Martin Kou
On Mon, May 14, 2012 at 2:04 AM, 李赫元 <li...@gmail.com> wrote:
> Hi All,
>
> I encounter a problem in zookeeper 3.4.1 with C API.
> The following is always show "success" even the zkserver is actually down.
>
> char* zk_server = "127.0.0.1:2181";
> zhandle_t* zh = zookeeper_init(zk_server, watcher_callback, 3000,
> 0, NULL, 0);
> if(!zh)
> {
> print_error(errno);
> return -1;
> }else
> {
> ::std::cout << "success" << ::std::endl;
> }
>
> Even if the zookeeper is shutdown, the zh handle is still not NULL.
> So, I don't know how to judge if connection to zookeeper is succful in C
> API.
>
> Thanks all.
>
> Heyuan Li
>