2005-03-26 jrandom

* Added some error handling and fairly safe to cache data to the streaming
      lib (good call Tom!)
This commit is contained in:
jrandom
2005-03-26 07:13:38 +00:00
committed by zzz
parent 0626f714c6
commit ebac4df2d3
5 changed files with 56 additions and 16 deletions

View File

@ -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

View File

@ -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)
*/

View File

@ -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;

View File

@ -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

View File

@ -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);