zookeeper-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From enixon <...@git.apache.org>
Subject [GitHub] zookeeper pull request #587: ZOOKEEPER-3106: Zookeeper client supports IPv6 ...
Date Wed, 01 Aug 2018 18:35:46 GMT
Github user enixon commented on a diff in the pull request:

    https://github.com/apache/zookeeper/pull/587#discussion_r206983579
  
    --- Diff: src/java/main/org/apache/zookeeper/client/ConnectStringParser.java ---
    @@ -68,14 +69,26 @@ public ConnectStringParser(String connectString) {
             List<String> hostsList = split(connectString,",");
             for (String host : hostsList) {
                 int port = DEFAULT_PORT;
    -            int pidx = host.lastIndexOf(':');
    -            if (pidx >= 0) {
    -                // otherwise : is at the end of the string, ignore
    -                if (pidx < host.length() - 1) {
    -                    port = Integer.parseInt(host.substring(pidx + 1));
    -                }
    -                host = host.substring(0, pidx);
    +            if (!connectString.startsWith("[")) {//IPv4
    +	            int pidx = host.lastIndexOf(':');
    +	            if (pidx >= 0) {
    +	                // otherwise : is at the end of the string, ignore
    +	                if (pidx < host.length() - 1) {
    +	                    port = Integer.parseInt(host.substring(pidx + 1));
    +	                }
    +	                host = host.substring(0, pidx);
    +            	}
    +            } else {                            //IPv6
    +            	int pidx = host.lastIndexOf(':');
    +            	int bracketIdx = host.lastIndexOf(']');
    +	            if (pidx >=0 && bracketIdx >=0 && pidx > bracketIdx)
{
    +	                if (pidx < host.length() - 1) {
    +	                    port = Integer.parseInt(host.substring(pidx + 1));
    +	                }
    +	                host = host.substring(0, pidx);
    +	            }
    --- End diff --
    
    nit - you've added tabs with your whitespace


---

Mime
View raw message