You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by rw...@apache.org on 2008/03/05 10:25:55 UTC

svn commit: r633798 - /commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/telnet/TelnetInputStream.java

Author: rwinston
Date: Wed Mar  5 01:25:48 2008
New Revision: 633798

URL: http://svn.apache.org/viewvc?rev=633798&view=rev
Log:
Add missing patch (NET-73)

Modified:
    commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/telnet/TelnetInputStream.java

Modified: commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/telnet/TelnetInputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/telnet/TelnetInputStream.java?rev=633798&r1=633797&r2=633798&view=diff
==============================================================================
--- commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/telnet/TelnetInputStream.java (original)
+++ commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/telnet/TelnetInputStream.java Wed Mar  5 01:25:48 2008
@@ -106,14 +106,19 @@
     // TelnetOutputStream writing through the telnet client at same time
     // as a processDo/Will/etc. command invoked from TelnetInputStream
     // tries to write.
-    private int __read() throws IOException
+    private int __read(boolean mayBlock) throws IOException
     {
         int ch;
 
 _loop:
         while (true)
         {
-            // Exit only when we reach end of stream.
+ 
+            // If there is no more data AND we were told not to block, just return -2. (More efficient than exception.)
+            if(!mayBlock && super.available() == 0)
+                return -2;
+        	
+            // Otherwise, exit only when we reach end of stream.
             if ((ch = super.read()) < 0)
                 return -1;
 
@@ -360,12 +365,13 @@
                         //__alreadyread = false;
                         __readIsWaiting = true;
                         int ch;
-
+                        boolean mayBlock = true;	// block on the first read only
+                        
                         do
                         {
                             try
                             {
-                                if ((ch = __read()) < 0)
+                                if ((ch = __read(mayBlock)) < 0)
                                     if(ch != -2)
                                         return (ch);
                             }
@@ -399,6 +405,11 @@
                                 if (__isClosed)
                                     return (-1);
                             }
+                            
+                            // Reads should not block on subsequent iterations. Potentially, this could happen if the 
+                            // remaining buffered socket data consists entirely of Telnet command sequence and no "user" data.
+                            mayBlock = false;
+                            
                         }
                         // Continue reading as long as there is data available and the queue is not full.
                         while (super.available() > 0 && __bytesAvailable < __queue.length - 1);
@@ -544,7 +555,7 @@
             {
                 try
                 {
-                    if ((ch = __read()) < 0)
+                    if ((ch = __read(true)) < 0)
                         break;
                 }
                 catch (InterruptedIOException e)



Re: svn commit: r633798 - /commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/telnet/TelnetInputStream.java

Posted by sebb <se...@gmail.com>.
On 05/03/2008, rwinston@apache.org <rw...@apache.org> wrote:
> Author: rwinston
>  Date: Wed Mar  5 01:25:48 2008
>  New Revision: 633798
>
>  URL: http://svn.apache.org/viewvc?rev=633798&view=rev
>  Log:
>  Add missing patch (NET-73)
>
>  Modified:
>     commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/telnet/TelnetInputStream.java
>
>  Modified: commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/telnet/TelnetInputStream.java
>  URL: http://svn.apache.org/viewvc/commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/telnet/TelnetInputStream.java?rev=633798&r1=633797&r2=633798&view=diff
>  ==============================================================================
>  --- commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/telnet/TelnetInputStream.java (original)
>  +++ commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/telnet/TelnetInputStream.java Wed Mar  5 01:25:48 2008
>  @@ -106,14 +106,19 @@
>      // TelnetOutputStream writing through the telnet client at same time
>      // as a processDo/Will/etc. command invoked from TelnetInputStream
>      // tries to write.
>  -    private int __read() throws IOException
>  +    private int __read(boolean mayBlock) throws IOException
>      {
>          int ch;
>
>   _loop:

BTW, the _loop: label is not used (in either version of the class).

>          while (true)
>          {
>  -            // Exit only when we reach end of stream.
>  +
>  +            // If there is no more data AND we were told not to block, just return -2. (More efficient than exception.)
>  +            if(!mayBlock && super.available() == 0)
>  +                return -2;
>  +
>  +            // Otherwise, exit only when we reach end of stream.
>              if ((ch = super.read()) < 0)
>                  return -1;
>
>  @@ -360,12 +365,13 @@
>                          //__alreadyread = false;
>                          __readIsWaiting = true;
>                          int ch;
>  -
>  +                        boolean mayBlock = true;       // block on the first read only
>  +
>                          do
>                          {
>                              try
>                              {
>  -                                if ((ch = __read()) < 0)
>  +                                if ((ch = __read(mayBlock)) < 0)
>                                      if(ch != -2)
>                                          return (ch);
>                              }
>  @@ -399,6 +405,11 @@
>                                  if (__isClosed)
>                                      return (-1);
>                              }
>  +
>  +                            // Reads should not block on subsequent iterations. Potentially, this could happen if the
>  +                            // remaining buffered socket data consists entirely of Telnet command sequence and no "user" data.
>  +                            mayBlock = false;
>  +
>                          }
>                          // Continue reading as long as there is data available and the queue is not full.
>                          while (super.available() > 0 && __bytesAvailable < __queue.length - 1);
>  @@ -544,7 +555,7 @@
>              {
>                  try
>                  {
>  -                    if ((ch = __read()) < 0)
>  +                    if ((ch = __read(true)) < 0)
>                          break;
>                  }
>                  catch (InterruptedIOException e)
>
>
>

Re: svn commit: r633798 - /commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/telnet/TelnetInputStream.java

Posted by sebb <se...@gmail.com>.
On 05/03/2008, rwinston@apache.org <rw...@apache.org> wrote:
> Author: rwinston
>  Date: Wed Mar  5 01:25:48 2008
>  New Revision: 633798
>
>  URL: http://svn.apache.org/viewvc?rev=633798&view=rev
>  Log:
>  Add missing patch (NET-73)
>
>  Modified:
>     commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/telnet/TelnetInputStream.java
>
>  Modified: commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/telnet/TelnetInputStream.java
>  URL: http://svn.apache.org/viewvc/commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/telnet/TelnetInputStream.java?rev=633798&r1=633797&r2=633798&view=diff
>  ==============================================================================
>  --- commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/telnet/TelnetInputStream.java (original)
>  +++ commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/telnet/TelnetInputStream.java Wed Mar  5 01:25:48 2008
>  @@ -106,14 +106,19 @@
>      // TelnetOutputStream writing through the telnet client at same time
>      // as a processDo/Will/etc. command invoked from TelnetInputStream
>      // tries to write.
>  -    private int __read() throws IOException
>  +    private int __read(boolean mayBlock) throws IOException
>      {
>          int ch;
>
>   _loop:

BTW, the _loop: label is not used (in either version of the class).

>          while (true)
>          {
>  -            // Exit only when we reach end of stream.
>  +
>  +            // If there is no more data AND we were told not to block, just return -2. (More efficient than exception.)
>  +            if(!mayBlock && super.available() == 0)
>  +                return -2;
>  +
>  +            // Otherwise, exit only when we reach end of stream.
>              if ((ch = super.read()) < 0)
>                  return -1;
>
>  @@ -360,12 +365,13 @@
>                          //__alreadyread = false;
>                          __readIsWaiting = true;
>                          int ch;
>  -
>  +                        boolean mayBlock = true;       // block on the first read only
>  +
>                          do
>                          {
>                              try
>                              {
>  -                                if ((ch = __read()) < 0)
>  +                                if ((ch = __read(mayBlock)) < 0)
>                                      if(ch != -2)
>                                          return (ch);
>                              }
>  @@ -399,6 +405,11 @@
>                                  if (__isClosed)
>                                      return (-1);
>                              }
>  +
>  +                            // Reads should not block on subsequent iterations. Potentially, this could happen if the
>  +                            // remaining buffered socket data consists entirely of Telnet command sequence and no "user" data.
>  +                            mayBlock = false;
>  +
>                          }
>                          // Continue reading as long as there is data available and the queue is not full.
>                          while (super.available() > 0 && __bytesAvailable < __queue.length - 1);
>  @@ -544,7 +555,7 @@
>              {
>                  try
>                  {
>  -                    if ((ch = __read()) < 0)
>  +                    if ((ch = __read(true)) < 0)
>                          break;
>                  }
>                  catch (InterruptedIOException e)
>
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org