[jira] [Created] (NET-437) TelnetInputStream doesn't support non-blocking IO when reader thread is not enabled

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

[jira] [Created] (NET-437) TelnetInputStream doesn't support non-blocking IO when reader thread is not enabled

Alex D Herbert (Jira)
TelnetInputStream doesn't support non-blocking IO when reader thread is not enabled
-----------------------------------------------------------------------------------

                 Key: NET-437
                 URL: https://issues.apache.org/jira/browse/NET-437
             Project: Commons Net
          Issue Type: Bug
          Components: Telnet
    Affects Versions: 3.0.1
         Environment: Java 6 + commons-net-3.0.1
            Reporter: Gavin Camp


When the telnet client is used without allowing it to create it's own reader thread (i.e. setReaderThread(false)) then the TelnetInputStream.available() method will always return 0 bytes available.  This makes non-blocking IO impossible as you need to actualy call read to get the data without knowing if it will block or not.

This fix to the available method in org.apache.commons.net.telnet.TelnetInputStream, seems to fix the issue, and should work for reader threads as well:

{noformat}
    @Override
    public int available() throws IOException
    {
        // Critical section because run() may change __bytesAvailable
        synchronized (__queue)
        {
        if (__bytesAvailable == 0 && !__threaded) {
        return super.available();
        } else {
        return __bytesAvailable;
        }
        }
    }
{noformat}


--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       
Reply | Threaded
Open this post in threaded view
|

[jira] [Commented] (NET-437) TelnetInputStream doesn't support non-blocking IO when reader thread is not enabled

Alex D Herbert (Jira)

    [ https://issues.apache.org/jira/browse/NET-437?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13182864#comment-13182864 ]

Sebb commented on NET-437:
--------------------------

I'm not quite sure why it's important to check __bytesAvailable?

Perhaps the condition should be coded as follows:

{code}
if (__threaded) {
    return __bytesAvailable;
} else {
    return __bytesAvailable + super.available();
}
{code}

This should return a value closer to the actual number available.
               

> TelnetInputStream doesn't support non-blocking IO when reader thread is not enabled
> -----------------------------------------------------------------------------------
>
>                 Key: NET-437
>                 URL: https://issues.apache.org/jira/browse/NET-437
>             Project: Commons Net
>          Issue Type: Bug
>          Components: Telnet
>    Affects Versions: 3.0.1
>         Environment: Java 6 + commons-net-3.0.1
>            Reporter: Gavin Camp
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> When the telnet client is used without allowing it to create it's own reader thread (i.e. setReaderThread(false)) then the TelnetInputStream.available() method will always return 0 bytes available.  This makes non-blocking IO impossible as you need to actualy call read to get the data without knowing if it will block or not.
> This fix to the available method in org.apache.commons.net.telnet.TelnetInputStream, seems to fix the issue, and should work for reader threads as well:
> {noformat}
>     @Override
>     public int available() throws IOException
>     {
>         // Critical section because run() may change __bytesAvailable
>         synchronized (__queue)
>         {
>         if (__bytesAvailable == 0 && !__threaded) {
>         return super.available();
>         } else {
>         return __bytesAvailable;
>         }
>         }
>     }
> {noformat}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       
Reply | Threaded
Open this post in threaded view
|

[jira] [Commented] (NET-437) TelnetInputStream doesn't support non-blocking IO when reader thread is not enabled

Alex D Herbert (Jira)
In reply to this post by Alex D Herbert (Jira)

    [ https://issues.apache.org/jira/browse/NET-437?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13183209#comment-13183209 ]

Gavin Camp commented on NET-437:
--------------------------------

Well for the non-threaded case __bytesAvailable will always be zero (this is the bug).  I was trying to check to make sure they hadn't spawned their own thread for the reader.  Although i'm not sure if this is easily possible (perhaps through class inheritance).  I guess if you don't want this case the code would be:

{noformat}
if (__threaded) {
    return __bytesAvailable;
} else {
    return super.available();
}
{noformat}
               

> TelnetInputStream doesn't support non-blocking IO when reader thread is not enabled
> -----------------------------------------------------------------------------------
>
>                 Key: NET-437
>                 URL: https://issues.apache.org/jira/browse/NET-437
>             Project: Commons Net
>          Issue Type: Bug
>          Components: Telnet
>    Affects Versions: 3.0.1
>         Environment: Java 6 + commons-net-3.0.1
>            Reporter: Gavin Camp
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> When the telnet client is used without allowing it to create it's own reader thread (i.e. setReaderThread(false)) then the TelnetInputStream.available() method will always return 0 bytes available.  This makes non-blocking IO impossible as you need to actualy call read to get the data without knowing if it will block or not.
> This fix to the available method in org.apache.commons.net.telnet.TelnetInputStream, seems to fix the issue, and should work for reader threads as well:
> {noformat}
>     @Override
>     public int available() throws IOException
>     {
>         // Critical section because run() may change __bytesAvailable
>         synchronized (__queue)
>         {
>         if (__bytesAvailable == 0 && !__threaded) {
>         return super.available();
>         } else {
>         return __bytesAvailable;
>         }
>         }
>     }
> {noformat}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       
Reply | Threaded
Open this post in threaded view
|

[jira] [Commented] (NET-437) TelnetInputStream doesn't support non-blocking IO when reader thread is not enabled

Alex D Herbert (Jira)
In reply to this post by Alex D Herbert (Jira)

    [ https://issues.apache.org/jira/browse/NET-437?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13183229#comment-13183229 ]

Sebb commented on NET-437:
--------------------------

Or even just do the same for both:

{code}
return __bytesAvailable + super.available();
{code}

AFAICT, that should always work, and would be more accurate.
               

> TelnetInputStream doesn't support non-blocking IO when reader thread is not enabled
> -----------------------------------------------------------------------------------
>
>                 Key: NET-437
>                 URL: https://issues.apache.org/jira/browse/NET-437
>             Project: Commons Net
>          Issue Type: Bug
>          Components: Telnet
>    Affects Versions: 3.0.1
>         Environment: Java 6 + commons-net-3.0.1
>            Reporter: Gavin Camp
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> When the telnet client is used without allowing it to create it's own reader thread (i.e. setReaderThread(false)) then the TelnetInputStream.available() method will always return 0 bytes available.  This makes non-blocking IO impossible as you need to actualy call read to get the data without knowing if it will block or not.
> This fix to the available method in org.apache.commons.net.telnet.TelnetInputStream, seems to fix the issue, and should work for reader threads as well:
> {noformat}
>     @Override
>     public int available() throws IOException
>     {
>         // Critical section because run() may change __bytesAvailable
>         synchronized (__queue)
>         {
>         if (__bytesAvailable == 0 && !__threaded) {
>         return super.available();
>         } else {
>         return __bytesAvailable;
>         }
>         }
>     }
> {noformat}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       
Reply | Threaded
Open this post in threaded view
|

[jira] [Commented] (NET-437) TelnetInputStream doesn't support non-blocking IO when reader thread is not enabled

Alex D Herbert (Jira)
In reply to this post by Alex D Herbert (Jira)

    [ https://issues.apache.org/jira/browse/NET-437?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13183286#comment-13183286 ]

Gavin Camp commented on NET-437:
--------------------------------

Sure sounds good.
               

> TelnetInputStream doesn't support non-blocking IO when reader thread is not enabled
> -----------------------------------------------------------------------------------
>
>                 Key: NET-437
>                 URL: https://issues.apache.org/jira/browse/NET-437
>             Project: Commons Net
>          Issue Type: Bug
>          Components: Telnet
>    Affects Versions: 3.0.1
>         Environment: Java 6 + commons-net-3.0.1
>            Reporter: Gavin Camp
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> When the telnet client is used without allowing it to create it's own reader thread (i.e. setReaderThread(false)) then the TelnetInputStream.available() method will always return 0 bytes available.  This makes non-blocking IO impossible as you need to actualy call read to get the data without knowing if it will block or not.
> This fix to the available method in org.apache.commons.net.telnet.TelnetInputStream, seems to fix the issue, and should work for reader threads as well:
> {noformat}
>     @Override
>     public int available() throws IOException
>     {
>         // Critical section because run() may change __bytesAvailable
>         synchronized (__queue)
>         {
>         if (__bytesAvailable == 0 && !__threaded) {
>         return super.available();
>         } else {
>         return __bytesAvailable;
>         }
>         }
>     }
> {noformat}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       
Reply | Threaded
Open this post in threaded view
|

[jira] [Resolved] (NET-437) TelnetInputStream doesn't support non-blocking IO when reader thread is not enabled

Alex D Herbert (Jira)
In reply to this post by Alex D Herbert (Jira)

     [ https://issues.apache.org/jira/browse/NET-437?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Sebb resolved NET-437.
----------------------

       Resolution: Fixed
    Fix Version/s: 3.1

Fixed in SVN.

I've uploaded a SNAPSHOT build to

https://repository.apache.org/content/repositories/snapshots/commons-net/commons-net/3.1-SNAPSHOT/

if you want to try it out.
               

> TelnetInputStream doesn't support non-blocking IO when reader thread is not enabled
> -----------------------------------------------------------------------------------
>
>                 Key: NET-437
>                 URL: https://issues.apache.org/jira/browse/NET-437
>             Project: Commons Net
>          Issue Type: Bug
>          Components: Telnet
>    Affects Versions: 3.0.1
>         Environment: Java 6 + commons-net-3.0.1
>            Reporter: Gavin Camp
>             Fix For: 3.1
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> When the telnet client is used without allowing it to create it's own reader thread (i.e. setReaderThread(false)) then the TelnetInputStream.available() method will always return 0 bytes available.  This makes non-blocking IO impossible as you need to actualy call read to get the data without knowing if it will block or not.
> This fix to the available method in org.apache.commons.net.telnet.TelnetInputStream, seems to fix the issue, and should work for reader threads as well:
> {noformat}
>     @Override
>     public int available() throws IOException
>     {
>         // Critical section because run() may change __bytesAvailable
>         synchronized (__queue)
>         {
>         if (__bytesAvailable == 0 && !__threaded) {
>         return super.available();
>         } else {
>         return __bytesAvailable;
>         }
>         }
>     }
> {noformat}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira