2004-04-08 04:41:54 +00:00
|
|
|
package net.i2p.client.streaming;
|
|
|
|
|
2004-11-10 12:33:01 +00:00
|
|
|
import java.util.Iterator;
|
2004-10-24 01:42:34 +00:00
|
|
|
import java.util.Properties;
|
|
|
|
|
2004-04-08 04:41:54 +00:00
|
|
|
/**
|
|
|
|
* Define the configuration for streaming and verifying data on the socket.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public class I2PSocketOptions {
|
|
|
|
private long _connectTimeout;
|
2004-08-01 18:34:02 +00:00
|
|
|
private long _readTimeout;
|
|
|
|
private long _writeTimeout;
|
|
|
|
private int _maxBufferSize;
|
2004-04-10 11:50:11 +00:00
|
|
|
|
2004-08-06 22:24:56 +00:00
|
|
|
public static final int DEFAULT_BUFFER_SIZE = 1024*64;
|
|
|
|
public static final int DEFAULT_WRITE_TIMEOUT = 60*1000;
|
2004-11-10 12:33:01 +00:00
|
|
|
public static final int DEFAULT_CONNECT_TIMEOUT = 60*1000;
|
|
|
|
|
|
|
|
public static final String PROP_BUFFER_SIZE = "i2p.streaming.bufferSize";
|
|
|
|
public static final String PROP_CONNECT_TIMEOUT = "i2p.streaming.connectTimeout";
|
|
|
|
public static final String PROP_READ_TIMEOUT = "i2p.streaming.readTimeout";
|
|
|
|
public static final String PROP_WRITE_TIMEOUT = "i2p.streaming.writeTimeout";
|
2004-08-01 18:34:02 +00:00
|
|
|
|
2004-04-08 04:41:54 +00:00
|
|
|
public I2PSocketOptions() {
|
2004-11-10 12:33:01 +00:00
|
|
|
this(System.getProperties());
|
2004-04-08 04:41:54 +00:00
|
|
|
}
|
2004-10-24 01:42:34 +00:00
|
|
|
|
|
|
|
public I2PSocketOptions(I2PSocketOptions opts) {
|
2004-11-10 12:33:01 +00:00
|
|
|
this(System.getProperties());
|
2004-10-24 01:42:34 +00:00
|
|
|
_connectTimeout = opts.getConnectTimeout();
|
|
|
|
_readTimeout = opts.getReadTimeout();
|
|
|
|
_writeTimeout = opts.getWriteTimeout();
|
|
|
|
_maxBufferSize = opts.getMaxBufferSize();
|
|
|
|
}
|
2004-04-10 11:50:11 +00:00
|
|
|
|
2004-10-24 01:42:34 +00:00
|
|
|
public I2PSocketOptions(Properties opts) {
|
2004-11-10 12:33:01 +00:00
|
|
|
init(opts);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void init(Properties opts) {
|
|
|
|
_maxBufferSize = getInt(opts, PROP_BUFFER_SIZE, DEFAULT_BUFFER_SIZE);
|
|
|
|
_connectTimeout = getInt(opts, PROP_CONNECT_TIMEOUT, DEFAULT_CONNECT_TIMEOUT);
|
|
|
|
_readTimeout = getInt(opts, PROP_READ_TIMEOUT, -1);
|
|
|
|
_writeTimeout = getInt(opts, PROP_WRITE_TIMEOUT, DEFAULT_WRITE_TIMEOUT);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected int getInt(Properties opts, String name, int defaultVal) {
|
|
|
|
if (opts == null) return defaultVal;
|
|
|
|
String val = opts.getProperty(name);
|
|
|
|
if (val == null) {
|
|
|
|
return defaultVal;
|
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
return Integer.parseInt(val);
|
|
|
|
} catch (NumberFormatException nfe) {
|
|
|
|
return defaultVal;
|
|
|
|
}
|
|
|
|
}
|
2004-10-24 01:42:34 +00:00
|
|
|
}
|
|
|
|
|
2004-04-08 04:41:54 +00:00
|
|
|
/**
|
|
|
|
* How long we will wait for the ACK from a SYN, in milliseconds.
|
|
|
|
*
|
|
|
|
* @return milliseconds to wait, or -1 if we will wait indefinitely
|
|
|
|
*/
|
2004-04-10 11:50:11 +00:00
|
|
|
public long getConnectTimeout() {
|
|
|
|
return _connectTimeout;
|
|
|
|
}
|
|
|
|
|
2004-04-21 17:56:16 +00:00
|
|
|
/**
|
|
|
|
* Define how long we will wait for the ACK from a SYN, in milliseconds.
|
|
|
|
*
|
|
|
|
*/
|
2004-04-10 11:50:11 +00:00
|
|
|
public void setConnectTimeout(long ms) {
|
|
|
|
_connectTimeout = ms;
|
|
|
|
}
|
2004-08-01 18:34:02 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* What is the longest we'll block on the input stream while waiting
|
2004-08-01 20:25:25 +00:00
|
|
|
* for more data. If this value is exceeded, the read() throws
|
2004-08-01 18:34:02 +00:00
|
|
|
* InterruptedIOException
|
|
|
|
*/
|
|
|
|
public long getReadTimeout() {
|
|
|
|
return _readTimeout;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* What is the longest we'll block on the input stream while waiting
|
2004-08-01 20:25:25 +00:00
|
|
|
* for more data. If this value is exceeded, the read() throws
|
2004-08-01 18:34:02 +00:00
|
|
|
* InterruptedIOException
|
|
|
|
*/
|
|
|
|
public void setReadTimeout(long ms) {
|
|
|
|
_readTimeout = ms;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* How much data will we accept that hasn't been written out yet. After
|
|
|
|
* this amount has been exceeded, subsequent .write calls will block until
|
|
|
|
* either some data is removed or the connection is closed. If this is
|
|
|
|
* less than or equal to zero, there is no limit (warning: can eat ram)
|
|
|
|
*
|
|
|
|
* @return buffer size limit, in bytes
|
|
|
|
*/
|
|
|
|
public int getMaxBufferSize() {
|
|
|
|
return _maxBufferSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* How much data will we accept that hasn't been written out yet. After
|
|
|
|
* this amount has been exceeded, subsequent .write calls will block until
|
|
|
|
* either some data is removed or the connection is closed. If this is
|
|
|
|
* less than or equal to zero, there is no limit (warning: can eat ram)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public void setMaxBufferSize(int numBytes) {
|
|
|
|
_maxBufferSize = numBytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* What is the longest we'll block on the output stream while waiting
|
2004-08-01 20:25:25 +00:00
|
|
|
* for the data to flush. If this value is exceeded, the write() throws
|
2004-08-01 18:34:02 +00:00
|
|
|
* InterruptedIOException. If this is less than or equal to zero, there
|
|
|
|
* is no timeout.
|
|
|
|
*/
|
|
|
|
public long getWriteTimeout() {
|
|
|
|
return _writeTimeout;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* What is the longest we'll block on the output stream while waiting
|
2004-08-01 20:25:25 +00:00
|
|
|
* for the data to flush. If this value is exceeded, the write() throws
|
2004-08-01 18:34:02 +00:00
|
|
|
* InterruptedIOException. If this is less than or equal to zero, there
|
|
|
|
* is no timeout.
|
|
|
|
*/
|
|
|
|
public void setWriteTimeout(long ms) {
|
|
|
|
_writeTimeout = ms;
|
|
|
|
}
|
2004-04-21 17:56:16 +00:00
|
|
|
}
|