This change obviously has one thing I need to fix (committed too quickly, which is the printStackTrace. Anyone want to review the rest of it as well? It seems like the right way to implement "ready" but it also seems really heavy. Perhaps there's a better way?

This is for JRUBY-2109.

-------- Original Message --------
Subject:        [jruby-scm] [jruby] [8982]
trunk/jruby/src/org/jruby/util/io/ChannelStream.java: Fix for
JRUBY-2108: IOWaitLibrary ready? returns nil when ready
Date:   Tue, 03 Feb 2009 22:36:03 -0600 (CST)
From:   [email protected]
Reply-To:       [email protected]
To:     [email protected]



Revision
    8982 <http://fisheye.codehaus.org/changelog/jruby/?cs=8982>
Author
    headius
Date
    2009-02-03 22:36:03 -0600 (Tue, 03 Feb 2009)


      Log Message

Fix for JRUBY-2108 <http://jira.codehaus.org/secure/ViewIssue.jspa?key=JRUBY-2108>: IOWaitLibrary ready? returns nil when ready


      Modified Paths

    * trunk/jruby/src/org/jruby/util/io/ChannelStream.java
      <#trunkjrubysrcorgjrubyutilioChannelStreamjava>


      Diff


        Modified: trunk/jruby/src/org/jruby/util/io/ChannelStream.java
        (8981 => 8982)

--- trunk/jruby/src/org/jruby/util/io/ChannelStream.java 2009-02-03 18:39:37 UTC (rev 8981) +++ trunk/jruby/src/org/jruby/util/io/ChannelStream.java 2009-02-04 04:36:03 UTC (rev 8982)
@@ -851,7 +851,26 @@
     }

     public int ready() throws IOException {
-        return newInputStream().available();
+        if (descriptor.getChannel() instanceof SelectableChannel) {
+           int ready_stat = 0;
+           java.nio.channels.Selector sel = java.nio.channels.Selector.open();
+ SelectableChannel selchan = (SelectableChannel)descriptor.getChannel();
+           boolean is_block = selchan.isBlocking();
+            try {
+                synchronized (selchan.blockingLock()) {
+                   selchan.configureBlocking(false);
+                   selchan.register(sel, 
java.nio.channels.SelectionKey.OP_READ);
+                   ready_stat = sel.selectNow();
+                   sel.close();
+                   selchan.configureBlocking( is_block );
+                }
+           }catch(Throwable ex){
+               ex.printStackTrace();
+           }
+           return ready_stat;
+       } else {
+           return newInputStream().available();
+       }
     }

public synchronized void fputc(int c) throws IOException, BadDescriptorException {

------------------------------------------------------------------------

To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email


Reply via email to