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

SocketClient should ensure input and output streams are closed

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.0
    • Fix Version/s: 2.2
    • Component/s: None
    • Labels:
      None
    • Environment:

      All

      Description

      From the Java 6 SDK, the socket.close() method is responsible for also closing its input and output streams. But if socket.close() throws an IOException before the streams could be closed, the streams will remain open and they will also not be set to null. We need a way to ensure that the input and output streams are also closed. There are various ways to achieve this:

      Proposal 1:
      Implement a public SocketClient.paranoidDisconnect() method that makes sure the socket, input and output are closed:
      public void paranoidDisconnect() {
      try

      { this.disconnect(); }

      catch (IOException ioe) {
      // the first thing that SocketClient.disconnect() does is to close the socket
      // but if that fails, we have to manually close the input and output streams
      if (this.input != null) {
      try

      { this._input_.close(); }

      catch (IOException ioe2) {
      }
      }

      if (this.output != null) {
      try

      { this._output_.close(); }

      catch (IOException ioe3) {
      }
      }
      }
      finally

      { this._socket_ = null; this._input_ = null; this._output_ = null; }

      }

      Proposal 2:
      Expose the socket, input and output stream objects with getter methods at the SocketClient level, handing the responsibility over to the calling application. TelnetClient already exposes the input and output streams with getInputStream() and getOutputStream() methods respectively.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                theuns.cloete Theuns Cloete
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: