From d8c3f617aa277c8c7491e1d504bcdc754f25c5ec Mon Sep 17 00:00:00 2001 From: zzz <zzz@mail.i2p> Date: Sat, 20 Jan 2018 11:34:16 +0000 Subject: [PATCH] Streaming: Consistent exception message on socket close --- .../src/net/i2p/client/streaming/impl/Connection.java | 6 +++--- .../i2p/client/streaming/impl/MessageInputStream.java | 8 ++++---- .../i2p/client/streaming/impl/MessageOutputStream.java | 10 +++++----- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/apps/streaming/java/src/net/i2p/client/streaming/impl/Connection.java b/apps/streaming/java/src/net/i2p/client/streaming/impl/Connection.java index f9bac0dc06..d10325f14b 100644 --- a/apps/streaming/java/src/net/i2p/client/streaming/impl/Connection.java +++ b/apps/streaming/java/src/net/i2p/client/streaming/impl/Connection.java @@ -203,10 +203,10 @@ class Connection { if (!_connected.get()) { if (getResetReceived()) throw new I2PSocketException(I2PSocketException.STATUS_CONNECTION_RESET); - throw new IOException("disconnected"); + throw new IOException("Socket closed"); } if (_outputStream.getClosed()) - throw new IOException("output stream closed"); + throw new IOException("Output stream closed"); started = true; // Try to keep things moving even during NACKs and retransmissions... // Limit unacked packets to the window @@ -785,7 +785,7 @@ class Connection { _outputStream.destroy(); _receiver.destroy(); _activityTimer.cancel(); - _inputStream.streamErrorOccurred(new IOException("disconnected")); + _inputStream.streamErrorOccurred(new IOException("Socket closed")); if (_log.shouldLog(Log.INFO)) _log.info("Connection disconnect complete: " diff --git a/apps/streaming/java/src/net/i2p/client/streaming/impl/MessageInputStream.java b/apps/streaming/java/src/net/i2p/client/streaming/impl/MessageInputStream.java index 7b7a0a59d8..e772beb18c 100644 --- a/apps/streaming/java/src/net/i2p/client/streaming/impl/MessageInputStream.java +++ b/apps/streaming/java/src/net/i2p/client/streaming/impl/MessageInputStream.java @@ -298,7 +298,7 @@ class MessageInputStream extends InputStream { buf.append("not ready bytes: ").append(notAvailable); buf.append(" highest ready block: ").append(_highestReadyBlockId); - _log.debug(buf.toString(), new Exception("closed")); + _log.debug(buf.toString(), new Exception("Input stream closed")); } _closeReceived = true; _dataLock.notifyAll(); @@ -410,7 +410,7 @@ class MessageInputStream extends InputStream { else expiration = -1; synchronized (_dataLock) { - if (_locallyClosed) throw new IOException("Already locally closed"); + if (_locallyClosed) throw new IOException("Input stream closed"); throwAnyError(); for (int i = 0; i < length; i++) { if ( (_readyDataBlocks.isEmpty()) && (i == 0) ) { @@ -419,7 +419,7 @@ class MessageInputStream extends InputStream { while (_readyDataBlocks.isEmpty()) { if (_locallyClosed) - throw new IOException("Already closed"); + throw new IOException("Input stream closed"); if ( (_notYetReadyBlocks.isEmpty()) && (_closeReceived) ) { if (_log.shouldLog(Log.INFO)) @@ -524,7 +524,7 @@ class MessageInputStream extends InputStream { public int available() throws IOException { int numBytes = 0; synchronized (_dataLock) { - if (_locallyClosed) throw new IOException("Already closed"); + if (_locallyClosed) throw new IOException("Input stream closed"); throwAnyError(); for (int i = 0; i < _readyDataBlocks.size(); i++) { ByteArray cur = _readyDataBlocks.get(i); diff --git a/apps/streaming/java/src/net/i2p/client/streaming/impl/MessageOutputStream.java b/apps/streaming/java/src/net/i2p/client/streaming/impl/MessageOutputStream.java index b8889c9725..21183fdf32 100644 --- a/apps/streaming/java/src/net/i2p/client/streaming/impl/MessageOutputStream.java +++ b/apps/streaming/java/src/net/i2p/client/streaming/impl/MessageOutputStream.java @@ -114,7 +114,7 @@ class MessageOutputStream extends OutputStream { @Override public void write(byte b[], int off, int len) throws IOException { - if (_closed.get()) throw new IOException("Already closed"); + if (_closed.get()) throw new IOException("Output stream closed"); if (_log.shouldLog(Log.DEBUG)) _log.debug("write(b[], " + off + ", " + len + ") "); int cur = off; @@ -122,7 +122,7 @@ class MessageOutputStream extends OutputStream { long begin = _context.clock().now(); while (remaining > 0) { WriteStatus ws = null; - if (_closed.get()) throw new IOException("closed underneath us"); + if (_closed.get()) throw new IOException("Output stream closed"); // we do any waiting outside the synchronized() block because we // want to allow other threads to flushAvailable() whenever they want. // this is the only method that *adds* to the _buf, and all @@ -131,7 +131,7 @@ class MessageOutputStream extends OutputStream { // To simplify the code, and avoid losing data from shrinking the max size, // we only update max size when current buffer is empty final int maxBuffer = (_valid == 0) ? locked_updateBufferSize() : _currentBufferSize; - if (_buf == null) throw new IOException("closed (buffer went away)"); + if (_buf == null) throw new IOException("Output stream closed"); if (_valid + remaining < maxBuffer) { // simply buffer the data, no flush System.arraycopy(b, cur, _buf, _valid, remaining); @@ -342,7 +342,7 @@ class MessageOutputStream extends OutputStream { synchronized (_dataLock) { if (_buf == null) { _dataLock.notifyAll(); - throw new IOException("closed (buffer went away)"); + throw new IOException("Output stream closed"); } // if valid == 0 return ??? - no, this could flush a CLOSE packet too. @@ -443,7 +443,7 @@ class MessageOutputStream extends OutputStream { return; } _flusher.cancel(); - _streamError.compareAndSet(null,new IOException("Closed internally")); + _streamError.compareAndSet(null, new IOException("Output stream closed")); clearData(true); } -- GitLab