aboutsummaryrefslogtreecommitdiffstats
path: root/AndroidAsync
diff options
context:
space:
mode:
Diffstat (limited to 'AndroidAsync')
-rw-r--r--AndroidAsync/src/com/koushikdutta/async/http/socketio/SocketIOConnection.java11
-rw-r--r--AndroidAsync/src/com/koushikdutta/async/http/socketio/SocketIORequest.java35
2 files changed, 42 insertions, 4 deletions
diff --git a/AndroidAsync/src/com/koushikdutta/async/http/socketio/SocketIOConnection.java b/AndroidAsync/src/com/koushikdutta/async/http/socketio/SocketIOConnection.java
index 9b03541..c8381cb 100644
--- a/AndroidAsync/src/com/koushikdutta/async/http/socketio/SocketIOConnection.java
+++ b/AndroidAsync/src/com/koushikdutta/async/http/socketio/SocketIOConnection.java
@@ -30,6 +30,7 @@ import java.util.Hashtable;
class SocketIOConnection {
AsyncHttpClient httpClient;
int heartbeat;
+ long reconnectDelay;
ArrayList<SocketIOClient> clients = new ArrayList<SocketIOClient>();
SocketIOTransport transport;
SocketIORequest request;
@@ -37,6 +38,7 @@ class SocketIOConnection {
public SocketIOConnection(AsyncHttpClient httpClient, SocketIORequest request) {
this.httpClient = httpClient;
this.request = request;
+ this.reconnectDelay = this.request.config.reconnectDelay;
}
public boolean isConnected() {
@@ -157,7 +159,7 @@ class SocketIOConnection {
return;
}
- reconnectDelay = 1000L;
+ reconnectDelay = request.config.reconnectDelay;
SocketIOConnection.this.transport = result;
attach();
}
@@ -216,10 +218,13 @@ class SocketIOConnection {
reconnect(null);
}
}, reconnectDelay);
- reconnectDelay *= 2;
+
+ reconnectDelay = reconnectDelay * 2;
+ if (request.config.reconnectDelayMax > 0L) {
+ reconnectDelay = Math.min(reconnectDelay, request.config.reconnectDelayMax);
+ }
}
- long reconnectDelay = 1000L;
private void reportDisconnect(final Exception ex) {
if (ex != null) {
request.loge("socket.io disconnected", ex);
diff --git a/AndroidAsync/src/com/koushikdutta/async/http/socketio/SocketIORequest.java b/AndroidAsync/src/com/koushikdutta/async/http/socketio/SocketIORequest.java
index 49ff2da..f98407f 100644
--- a/AndroidAsync/src/com/koushikdutta/async/http/socketio/SocketIORequest.java
+++ b/AndroidAsync/src/com/koushikdutta/async/http/socketio/SocketIORequest.java
@@ -1,7 +1,6 @@
package com.koushikdutta.async.http.socketio;
import android.net.Uri;
-import android.text.TextUtils;
import com.koushikdutta.async.http.AsyncHttpPost;
@@ -10,6 +9,11 @@ public class SocketIORequest extends AsyncHttpPost {
this(uri, "");
}
+ Config config;
+ public Config getConfig() {
+ return config;
+ }
+
String endpoint;
public String getEndpoint() {
return endpoint;
@@ -25,8 +29,37 @@ public class SocketIORequest extends AsyncHttpPost {
}
public SocketIORequest(String uri, String endpoint, String query) {
+ this(uri, endpoint, query, null);
+ }
+
+ public SocketIORequest(String uri, String endpoint, String query, Config config) {
super(Uri.parse(uri + (query == null ? "" : "?" + query)).buildUpon().encodedPath("/socket.io/1/").build().toString());
+ this.config = (config != null) ? config : new Config();
this.endpoint = endpoint;
this.query = query;
}
+
+ public static class Config {
+ long reconnectDelay = 1000L;
+ public void setReconnectDelay(long reconnectDelay) {
+ if (reconnectDelay < 0L) {
+ throw new IllegalArgumentException("reconnectDelay must be >= 0");
+ }
+ this.reconnectDelay = reconnectDelay;
+ }
+ public long getReconnectDelay() {
+ return reconnectDelay;
+ }
+
+ long reconnectDelayMax = 0L;
+ public void setReconnectDelayMax(long reconnectDelayMax) {
+ if (reconnectDelay < 0L) {
+ throw new IllegalArgumentException("reconnectDelayMax must be >= 0");
+ }
+ this.reconnectDelayMax = reconnectDelayMax;
+ }
+ public long getReconnectDelayMax() {
+ return reconnectDelayMax;
+ }
+ }
}