On Tue, 13 Sep 2011 12:59:35 +0300, Regan Heath <[email protected]> wrote:

I'm thinking of making all of Address.to(Addr|HostName|Port|Service)String return null on failure for consistency. Sounds good?

In some of these cases you'll be returning null for incorrect input (essentially)

Why do you say that? Let's look at each of those functions.

An Address class encapsulates a socket address that has already been parsed/resolved/retrieved to a binary numeric format.

Address.toAddrString returns a numeric string representation of the host address. For IPv4, it means taking the 32-bit value and formatting it to the common %d.%d.%d.%d format. I don't see how that could fail, except for catastrophic conditions (out-of-memory etc). Same with IPv6 - AFAIK any 16-byte sequence can be represented as an IPv6 string (%02x:%02x:%02x...). Same with Address.toPortString.

The only question regarding the above is with address families which do not have a meaningful host address/port, for example Unix domain sockets.

Address.toHostNameString was the point of our discussion. The method attempts a reverse lookup, which can be expected to fail. Address.toServiceString is similar, however it doesn't need to perform a network lookup - it only needs to check the host's database of service names.

--
Best regards,
 Vladimir                            mailto:[email protected]

Reply via email to