On Oct 10, 2013, at 12:37 PM, Brian Burkhalter wrote:

> Yes, I read about the thread safety. There are other ways to do this but I 
> wanted first to air the general idea using gai_strerror() before doing any 
> further work.
> 
>> […]
> 
> Thanks, I did read about FormatMessage() but forewent the usage thereof for 
> the just stated reason.

Assuming that the general idea is correct, there are a few possible 
alternatives for a final version for Windows. I am not concerned in this 
discussion about picky details including naming which can be fine tuned at the 
end.

1) In net_util_mh.c/NET_ThrowUnknownHostExceptionWithGaiError replace 
gai_strerror() with FormatMessage().

2) In Inet4AddressImpl.c and Inet6AddressImpl.c replace 
NET_ThrowUnknownHostExceptionWithGaiError with NET_ThrowByNameWithLastError 
(see net_md_util.c).

3) In net_md_util.c change (line 97 in 
http://cr.openjdk.java.net/~bpb/8010371/webrev.3/ version)

    { WSATRY_AGAIN,             0,      "Nonauthoritative host not found" },

to

    { WSATRY_AGAIN,             "UnknownHostException",      "Nonauthoritative 
host not found" },

and in Inet4AddressImpl.c and Inet6AddressImpl.c replace 
NET_ThrowUnknownHostExceptionWithGaiError with NET_ThrowNew().

4) In NET_ThrowUnknownHostExceptionWithGaiError instead of using gai_strerror() 
use the hard-coded error message "Nonauthoritative host not found".

The pros and/or cons for each, respectively, are

1) Most closely matches the Unix version and avoids hard-coded messages.

2) Simple and obviates the need for 
NET_ThrowUnknownHostExceptionWithGaiError(), but the exception message has a 
different format from the Unix version and contains the error code instead of 
an error string.

3) Simple and obviates the need for 
NET_ThrowUnknownHostExceptionWithGaiError(), but the exception message format 
is slightly different from the Unix version and the change could have the 
undesirable (and unpredictable) side effect of an UnknownHostException being 
thrown somewhere else where a SocketException used to be thrown.

4) Simplest option but has distasteful hard-coding (as do option 3 indirectly 
and NET_ThrowNew() for that matter).

If the "con" of option 2 is acceptable then I think that would be the best way 
to go, otherwise option 1.

Thanks,

Brian

Reply via email to