RFR 8203369 : Check for both EAGAIN and EWOULDBLOCK error codes

David Holmes david.holmes at oracle.com
Fri May 25 06:40:51 UTC 2018


On 25/05/2018 4:14 PM, Ivan Gerasimov wrote:
> Hi David!
> 
>>> If gcc, then we already have the same test for both constants in code 
>>> with no issues.
>>> For example, java.base/unix/native/libnet/SocketInputStream.c, in 
>>> NET_ReadWithTimeout():
>>>          result = NET_NonBlockingRead(fd, bufP, len);
>>>          if (result == -1 && ((errno == EAGAIN) || (errno == 
>>> EWOULDBLOCK))) {
>>>
>>>
>>> If javac, then, I was thinking about it too, but I don't have a good 
>>> a universal solution to propose right now.
>>
>> javac should treat these symbolically rather than based on actual 
>> value, so I don't see any issue there. It's the C compiler that sees 
>> the raw value after preprocessing and so sees "duplicate" clauses.
>>
> If fact, as UnixContant.java is built from the template file 
> UnixConstants.java.template, which is processed with cpp preprocessor, 
> javac also sees the raw values.
> 
> So if someone decides to write something like
> switch (exc.errno()) {
>      case UnixConstants.EAGAIN:
>      case UnixConstants.EWOULDBLOCK:
> }
> then there will be compile time trouble on some platforms and no issues 
> on the others.

I was thinking javac wouldn't examine the actual value of the fields, 
but it does for switch :(

Oh well.

David
-----

> Fortunately, UnixContant class is package private, so it is quite 
> unlikely to happen.
> 
> I was even thinking about proposing a language-level enhancement: If a 
> switch statement contains duplicate cases *and* these are combined, then 
> treat them as just one case.
> Though the use case it too limited to justify the need :)
> 
> With kind regards,
> Ivan
> 
> 


More information about the nio-dev mailing list