[ 
https://issues.apache.org/jira/browse/ZOOKEEPER-1020?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13007045#comment-13007045
 ] 

Stephen Tyree commented on ZOOKEEPER-1020:
------------------------------------------

Posting discussion with Benjamin Reed while on the IRC channel:

13:19 < breed_zk>  it looks good, but i think it might be better to use 
sockaddr instead of converting to a string. we should return a null if we 
aren't connected. your
                  patch really tells the host that you should be connected to 
rather than which one you are connected to. maybe use getpeername
13:21 < styree> Ok, so the function would return the sockaddr of the 
connection, letting the client do any conversion they want to?
13:21 < styree> And calling getpeername on the fd used to talk to Zookeeper
13:24 < styree> Using the sockaddr would remove the need to seperate the 
function into getting the host and the port, but how do we feel about the 
function name?
13:31 < breed_zk> yes
13:32 < breed_zk> one sec
13:32 < styree> k
13:35 < breed_zk> there is this, perhaps silly, distinction we make with the 
naming in C. zoo_ is for standard zookeeper calls, where zookeeper_ is for the 
management
                  API, so by that logic i think it should be called 
zookeeper_get_connected_host.

So I'm going to rename the function zookeeper_get_connected_host and have it 
return the underlying sockaddr for the connection based on getpeername.

> Implement function in C client to determine which host you're currently 
> connected to.
> -------------------------------------------------------------------------------------
>
>                 Key: ZOOKEEPER-1020
>                 URL: https://issues.apache.org/jira/browse/ZOOKEEPER-1020
>             Project: ZooKeeper
>          Issue Type: New Feature
>          Components: c client
>            Reporter: Stephen Tyree
>            Priority: Minor
>         Attachments: ZOOKEEPER-1020.patch
>
>
> On occasion it might be useful to determine which host your Zookeeper client 
> is currently connected to, be it for debugging purposes or otherwise. A 
> possible signature for that function:
> const char* zoo_get_connected_host(zhandle_t *zh, char *buffer, size_t 
> buffer_size, unsigned short *port);
> Clients could use it like below:
>   char buffer[33];
>   unsigned short port = 0;
>   if (!zoo_get_connected_host(zh, buffer, sizeof(buffer), &port))
>     return EXIT_FAILURE;
>   printf("The connected host is: %s:%d\n", buffer, port);

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to