SachinPuthran / bluecove

Automatically exported from code.google.com/p/bluecove
0 stars 0 forks source link

Closing a connection stream also closes the connection #20

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. conn = Connector.open("btspp:...");
2. out = conn.openOutputStream();
3. out.close();
4. in = conn.openInputStream();

What is the expected output? What do you see instead?
  This should result in a valid input stream but instead an IOException is
thrown.  The IOException is correct behavior only if conn.close() was
called first.

What version of the product are you using? On what operating system?
  BlueCove 2.0.1 on the Microsoft stack.  Other stacks probably have the
same problem since they use the same connection classes.

Please provide any additional information below.
  This is easy to fix.  Just remove the line of code that closes the
connection when the stream is closed.  In
com.intel.bluetooth.BluetoothInputStream and BluetoothOutputStream there
are close() methods that look like:

    public void close() throws IOException {
        // Function is not synchronized
        BluetoothRFCommConnection c = conn;
        if (c != null) {
            c.in = null;
            conn = null;
            c.closeConnection();
        }
    }

Just remove the c.closeConnection() line from both methods.  As you can see
the connection's reference to an input stream is cleared and this object
removes its reference to the connection.  So the stream is severed from the
connection which is all the behavior closing the stream should have.

Original issue reported on code.google.com by deanbro...@gmail.com on 8 Sep 2007 at 12:25

GoogleCodeExporter commented 9 years ago
The solution is not so simple. I will do investigation

Original comment by skarzhev...@gmail.com on 9 Sep 2007 at 1:36

GoogleCodeExporter commented 9 years ago
Fixed close() functions according to specification. In version 2.0.2-SNAPSHOT

     * When a connection has been closed, access to any of
     * its methods except this close() will cause an an IOException to be
     * thrown. Closing an already closed connection has no effect. Streams
     * derived from the connection may be open when method is called. Any open
     * streams will cause the connection to be held open until they themselves
     * are closed. In this latter case access to the open streams is permitted,
     * but access to the connection is not.

----
Closing a connection stream also closes the connection only when 
connection.close()
was called already.

Original comment by skarzhev...@gmail.com on 9 Sep 2007 at 5:12

GoogleCodeExporter commented 9 years ago

Original comment by skarzhev...@gmail.com on 9 Sep 2007 at 5:29