You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Sebb (JIRA)" <ji...@apache.org> on 2010/07/10 18:08:51 UTC

[jira] Resolved: (NET-283) SocketClient should ensure input and output streams are closed

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

Sebb resolved NET-283.
----------------------

    Fix Version/s: 2.1
       Resolution: Fixed

> SocketClient should ensure input and output streams are closed
> --------------------------------------------------------------
>
>                 Key: NET-283
>                 URL: https://issues.apache.org/jira/browse/NET-283
>             Project: Commons Net
>          Issue Type: Improvement
>    Affects Versions: 2.0
>         Environment: All
>            Reporter: Theuns Cloete
>             Fix For: 2.1
>
>
> 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.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.