[9] RFR of 8132652: Java_sun_nio_ch_Net_poll passes a long to an int

Brian Burkhalter brian.burkhalter at oracle.com
Mon Aug 3 17:44:40 UTC 2015


On Aug 1, 2015, at 6:14 AM, Alan Bateman <Alan.Bateman at oracle.com> wrote:

> On 31/07/2015 02:19, Brian Burkhalter wrote:
>> 
>> Summary: While the jlong value passed as the parameter ‘timeout’ appears in all cases to be a widened jint and therefore that there is really no problem at present, clamping the jlong to the range of int might avert unforeseen future problems should the calling logic change.
>> 
> This looks okay. A slight variant would be to set timeout to -1 then any negative value means an infinite timeout to the poll syscall.

Good point as the specifications vary.

Linux (Ubuntu 12.04):

       The  timeout  argument  specifies  an upper limit on the time for which
       poll() will block, in milliseconds.  Specifying  a  negative  value  in
       timeout means an infinite timeout.

Mac OS X (10.9.5):

     If timeout is greater than zero, it specifies a maximum interval (in mil-
     liseconds) to wait for any file descriptor to become ready.  If timeout
     is zero, then poll() will return without blocking. If the value of
     timeout is -1, the poll blocks indefinitely.

I changed it to this:

+    if (timeout < -1) {
+        timeout = -1;
+    } else if (timeout > INT_MAX) {
+        timeout = INT_MAX;
+    }
+    rv = poll(&pfd, 1, (int)timeout);

I am re-running the regression tests with this change and if those pass I will go ahead and push the fix.

Thanks,

Brian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/nio-dev/attachments/20150803/55b3576a/attachment.html>


More information about the nio-dev mailing list