1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-09-15 03:59:38 +02:00

Don't throw an IOException if IBBStream got closed by the remote

Smack should not throw an IOException in case a stream got closed by
the remote peer and the user is trying to read() from the stream. This
commit fixes that, by making Smack return '-1' if the stream got
closed by the remote. An IOException will only be thrown if the user
tries to read from a stream that got already closed by *himself*.

SMACK-468
This commit is contained in:
Florian Schmaus 2014-05-20 14:18:47 +02:00
parent a19181ce04
commit d790db5729
2 changed files with 4 additions and 56 deletions

View file

@ -609,59 +609,6 @@ public class InBandBytestreamSessionTest {
}
/**
* If the session is closed the input stream and output stream should be closed as well.
*
* @throws Exception should not happen
*/
@Test
public void shouldCloseBothStreamsIfSessionIsClosed() throws Exception {
// acknowledgment for data packet
IQ resultIQ = IBBPacketUtils.createResultIQ(initiatorJID, targetJID);
protocol.addResponse(resultIQ);
// acknowledgment for close request
protocol.addResponse(resultIQ, Verification.correspondingSenderReceiver,
Verification.requestTypeSET);
// get IBB sessions data packet listener
InBandBytestreamSession session = new InBandBytestreamSession(connection, initBytestream,
initiatorJID);
InputStream inputStream = session.getInputStream();
PacketListener listener = Whitebox.getInternalState(inputStream, PacketListener.class);
// build data packet
String base64Data = StringUtils.encodeBase64("Data");
DataPacketExtension dpe = new DataPacketExtension(sessionID, 0, base64Data);
Data data = new Data(dpe);
// add data packets
listener.processPacket(data);
session.close();
protocol.verifyAll();
try {
while (inputStream.read() != -1) {
}
inputStream.read();
fail("should throw an exception");
}
catch (IOException e) {
assertTrue(e.getMessage().contains("closed"));
}
try {
session.getOutputStream().flush();
fail("should throw an exception");
}
catch (IOException e) {
assertTrue(e.getMessage().contains("closed"));
}
}
/**
* If the input stream is closed concurrently there should be no deadlock.
*