compatible with engine.io 0.7.9

This commit is contained in:
Naoyuki Kanezawa
2013-10-18 02:01:44 +09:00
parent d4e2e28ace
commit 803ee3bb25
2 changed files with 4 additions and 29 deletions

View File

@@ -15,19 +15,12 @@ import java.net.URISyntaxException;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
public class WebSocket extends Transport { public class WebSocket extends Transport {
public static final String NAME = "websocket"; public static final String NAME = "websocket";
private WebSocketClient socket; private WebSocketClient socket;
private Future bufferedAmountId;
private ScheduledExecutorService drainScheduler = Executors.newSingleThreadScheduledExecutor();
public WebSocket(Options opts) { public WebSocket(Options opts) {
@@ -101,31 +94,13 @@ public class WebSocket extends Transport {
} }
}; };
if (this.socket.getConnection().hasBufferedData()) { // fake drain
this.bufferedAmountId = this.drainScheduler.scheduleAtFixedRate(new Runnable() { // defer to next tick to allow Socket to clear writeBuffer
@Override EventThread.nextTick(ondrain);
public void run() {
EventThread.exec(new Runnable() {
@Override
public void run() {
if (!self.socket.getConnection().hasBufferedData()) {
self.bufferedAmountId.cancel(true);
ondrain.run();
}
}
});
}
}, 50, 50, TimeUnit.MILLISECONDS);
} else {
EventThread.nextTick(ondrain);
}
} }
@Override @Override
protected void onClose() { protected void onClose() {
if (this.bufferedAmountId != null) {
this.bufferedAmountId.cancel(true);
}
super.onClose(); super.onClose();
} }

View File

@@ -3,6 +3,6 @@
"version": "0.0.0", "version": "0.0.0",
"private": true, "private": true,
"dependencies": { "dependencies": {
"engine.io": "0.7.3" "engine.io": "0.7.9"
} }
} }