diff --git a/apps/ministreaming/java/src/net/i2p/client/streaming/I2PSocket.java b/apps/ministreaming/java/src/net/i2p/client/streaming/I2PSocket.java index cb021ed48..a7cc07e9d 100644 --- a/apps/ministreaming/java/src/net/i2p/client/streaming/I2PSocket.java +++ b/apps/ministreaming/java/src/net/i2p/client/streaming/I2PSocket.java @@ -62,6 +62,8 @@ public interface I2PSocket { */ public void close() throws IOException; + public boolean isClosed(); + public void setSocketErrorListener(SocketErrorListener lsnr); /** * Allow notification of underlying errors communicating across I2P without diff --git a/apps/ministreaming/java/src/net/i2p/client/streaming/I2PSocketImpl.java b/apps/ministreaming/java/src/net/i2p/client/streaming/I2PSocketImpl.java index be8241c31..5662f4ce8 100644 --- a/apps/ministreaming/java/src/net/i2p/client/streaming/I2PSocketImpl.java +++ b/apps/ministreaming/java/src/net/i2p/client/streaming/I2PSocketImpl.java @@ -233,6 +233,8 @@ class I2PSocketImpl implements I2PSocket { in.notifyClosed(); } + public boolean isClosed() { return _closedOn > 0; } + /** * Close the socket from the I2P side (by a close packet) */ diff --git a/apps/streaming/java/src/net/i2p/client/streaming/I2PSocketFull.java b/apps/streaming/java/src/net/i2p/client/streaming/I2PSocketFull.java index e97a86f52..c2f412693 100644 --- a/apps/streaming/java/src/net/i2p/client/streaming/I2PSocketFull.java +++ b/apps/streaming/java/src/net/i2p/client/streaming/I2PSocketFull.java @@ -13,9 +13,15 @@ import net.i2p.data.Destination; public class I2PSocketFull implements I2PSocket { private Connection _connection; private I2PSocket.SocketErrorListener _listener; + private Destination _remotePeer; + private Destination _localPeer; public I2PSocketFull(Connection con) { _connection = con; + if (con != null) { + _remotePeer = con.getRemotePeer(); + _localPeer = con.getSession().getMyDestination(); + } } public void close() throws IOException { @@ -35,44 +41,70 @@ public class I2PSocketFull implements I2PSocket { Connection getConnection() { return _connection; } public InputStream getInputStream() { - return _connection.getInputStream(); + Connection c = _connection; + if (c != null) + return c.getInputStream(); + else + return null; } public I2PSocketOptions getOptions() { - return _connection.getOptions(); + Connection c = _connection; + if (c != null) + return c.getOptions(); + else + return null; } public OutputStream getOutputStream() throws IOException { - return _connection.getOutputStream(); + Connection c = _connection; + if (c != null) + return c.getOutputStream(); + else + return null; } - public Destination getPeerDestination() { - return _connection.getRemotePeer(); - } + public Destination getPeerDestination() { return _remotePeer; } public long getReadTimeout() { - return _connection.getOptions().getReadTimeout(); + I2PSocketOptions opts = getOptions(); + if (opts != null) + return opts.getReadTimeout(); + else + return -1; } - public Destination getThisDestination() { - return _connection.getSession().getMyDestination(); - } + public Destination getThisDestination() { return _localPeer; } public void setOptions(I2PSocketOptions options) { + Connection c = _connection; + if (c == null) return; + if (options instanceof ConnectionOptions) - _connection.setOptions((ConnectionOptions)options); + c.setOptions((ConnectionOptions)options); else - _connection.setOptions(new ConnectionOptions(options)); + c.setOptions(new ConnectionOptions(options)); } public void setReadTimeout(long ms) { - _connection.getOptions().setReadTimeout(ms); + Connection c = _connection; + if (c == null) return; + + c.getOptions().setReadTimeout(ms); } public void setSocketErrorListener(I2PSocket.SocketErrorListener lsnr) { _listener = lsnr; } + public boolean isClosed() { + Connection c = _connection; + return ((c == null) || + (!c.getIsConnected()) || + (c.getResetReceived()) || + (c.getResetSent())); + } + void destroy() { _connection = null; _listener = null; diff --git a/history.txt b/history.txt index 2d7017bec..5af5f9ff1 100644 --- a/history.txt +++ b/history.txt @@ -1,4 +1,8 @@ -$Id: history.txt,v 1.180 2005/03/24 02:29:27 jrandom Exp $ +$Id: history.txt,v 1.181 2005/03/24 23:07:06 jrandom Exp $ + +2005-03-26 jrandom + * Added some error handling and fairly safe to cache data to the streaming + lib (good call Tom!) 2005-03-25 jrandom * Fixed up building dependencies for the routerconsole on some more diff --git a/router/java/src/net/i2p/router/RouterVersion.java b/router/java/src/net/i2p/router/RouterVersion.java index c80fc0f81..2a93e5091 100644 --- a/router/java/src/net/i2p/router/RouterVersion.java +++ b/router/java/src/net/i2p/router/RouterVersion.java @@ -15,9 +15,9 @@ import net.i2p.CoreVersion; * */ public class RouterVersion { - public final static String ID = "$Revision: 1.173 $ $Date: 2005/03/24 02:29:27 $"; + public final static String ID = "$Revision: 1.174 $ $Date: 2005/03/24 23:07:06 $"; public final static String VERSION = "0.5.0.4"; - public final static long BUILD = 1; + public final static long BUILD = 2; public static void main(String args[]) { System.out.println("I2P Router version: " + VERSION); System.out.println("Router ID: " + RouterVersion.ID);