Hi, I've been working on porting Java implementation of EngineIO and SocketIO to Kotlin Multiplatform recently.
During the development and test process, I have a question about Polling transport's close implementation:
https://github.com/socketio/engine.io-client-java/blob/main/src/main/java/io/socket/engineio/client/transports/Polling.java#L147C1-L167C6
protectedvoiddoClose() {
finalPollingself = this;
Emitter.Listenerclose = newEmitter.Listener() {
@Overridepublicvoidcall(Object... args) {
logger.fine("writing close packet");
self.write(newPacket[]{newPacket(Packet.CLOSE)});
}
};
if (this.readyState == ReadyState.OPEN) {
logger.fine("transport open - closing");
close.call();
} else {
// in case we're trying to close while// handshaking is in progress (engine.io-client GH-164)logger.fine("transport not open - deferring close");
this.once(EVENT_OPEN, close);
}
}https://github.com/socketio/engine.io-client-java/blob/main/src/main/java/io/socket/engineio/client/Transport.java#L83C1-L94C6
publicTransportclose() {
EventThread.exec(newRunnable() {
@Overridepublicvoidrun() {
if (Transport.this.readyState == ReadyState.OPENING || Transport.this.readyState == ReadyState.OPEN) {
Transport.this.doClose();
Transport.this.onClose();
}
}
});
returnthis;
}Actually if we call transport.close() while the polling transport is still opening, EVENT_OPEN won't be triggered, because doClose will return immediately, and Transport.this.onClose() will be called, then readyState will be CLOSED, and any further response of poll won't trigger EVENT_OPEN, because code logic below:
https://github.com/socketio/engine.io-client-java/blob/main/src/main/java/io/socket/engineio/client/transports/Polling.java#L109C1-L129C11
privatevoid_onData(Objectdata) {
finalPollingself = this;
if (logger.isLoggable(Level.FINE)) {
logger.fine(String.format("polling got data %s", data));
}
Parser.DecodePayloadCallbackcallback = newParser.DecodePayloadCallback() {
@Overridepublicbooleancall(Packetpacket, intindex, inttotal) {
if (self.readyState == ReadyState.OPENING && Packet.OPEN.equals(packet.type)) {
self.onOpen();
}
...
}
};I think the problem is we shouldn't call Transport.this.onClose() in Transport.this.close(), am I right?
Hi, I've been working on porting Java implementation of EngineIO and SocketIO to Kotlin Multiplatform recently.
During the development and test process, I have a question about Polling transport's close implementation:
https://github.com/socketio/engine.io-client-java/blob/main/src/main/java/io/socket/engineio/client/transports/Polling.java#L147C1-L167C6
https://github.com/socketio/engine.io-client-java/blob/main/src/main/java/io/socket/engineio/client/Transport.java#L83C1-L94C6
Actually if we call transport.close() while the polling transport is still opening,
EVENT_OPENwon't be triggered, becausedoClosewill return immediately, andTransport.this.onClose()will be called, thenreadyStatewill beCLOSED, and any further response of poll won't triggerEVENT_OPEN, because code logic below:https://github.com/socketio/engine.io-client-java/blob/main/src/main/java/io/socket/engineio/client/transports/Polling.java#L109C1-L129C11
I think the problem is we shouldn't call
Transport.this.onClose()inTransport.this.close(), am I right?