Uploaded image for project: 'Commons Net'
  1. Commons Net
  2. NET-437

TelnetInputStream doesn't support non-blocking IO when reader thread is not enabled

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 3.0.1
    • 3.1
    • Telnet
    • None
    • Java 6 + commons-net-3.0.1

    Description

      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:

       
          @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;
              	}
              }
          }
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            gcamp Gavin Camp
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - 1h
                1h
                Remaining:
                Remaining Estimate - 1h
                1h
                Logged:
                Time Spent - Not Specified
                Not Specified