Skip to content

Commit 641e761

Browse files
committed
Proposed fix for Issue 53 - use bool OnDataReceived signal to avoid indefinite recursion
1 parent 58b954f commit 641e761

File tree

1 file changed

+32
-18
lines changed
  • Src/EngineIoClientDotNet.mono/Client/Transports

1 file changed

+32
-18
lines changed

Src/EngineIoClientDotNet.mono/Client/Transports/Polling.cs

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,38 @@ public Polling(Options opts) : base(opts)
2222
Name = NAME;
2323
}
2424

25-
25+
private bool FirstTimePoll = true;
26+
private bool OnDataReceived = false;
2627
protected override void DoOpen()
2728
{
28-
Poll();
29+
var log = LogManager.GetLogger(Global.CallerName());
30+
log.Info("DoOpen: Entry");
31+
32+
do
33+
{
34+
if (FirstTimePoll)
35+
{
36+
log.Info("DoOpen: Initial Poll - ReadyState=" + ReadyState.ToString());
37+
FirstTimePoll = false;
38+
Poll();
39+
IsPolling = false;
40+
Emit(EVENT_POLL_COMPLETE);
41+
}
42+
else if (OnDataReceived && ReadyState == ReadyStateEnum.OPEN)
43+
{
44+
log.Info("DoOpen: General Poll - ReadyState=" + ReadyState.ToString());
45+
OnDataReceived = false;// Don't poll again, unless signaled by _onData
46+
Poll();
47+
IsPolling = false;
48+
Emit(EVENT_POLL_COMPLETE);
49+
}
50+
else
51+
{
52+
log.Info(string.Format("DoOpen: ignoring poll - transport state {0}", ReadyState));
53+
}
54+
System.Threading.Thread.Sleep(100);
55+
}
56+
while (ReadyState != ReadyStateEnum.CLOSED);
2957
}
3058

3159
public void Pause(Action onPause)
@@ -208,22 +236,8 @@ private void _onData(object data)
208236
Parser.Parser.DecodePayload((byte[])data, callback);
209237
}
210238

211-
if (ReadyState != ReadyStateEnum.CLOSED)
212-
{
213-
IsPolling = false;
214-
log.Info("ReadyState != ReadyStateEnum.CLOSED");
215-
Emit(EVENT_POLL_COMPLETE);
216-
217-
if (ReadyState == ReadyStateEnum.OPEN)
218-
{
219-
Poll();
220-
}
221-
else
222-
{
223-
log.Info(string.Format("ignoring poll - transport state {0}", ReadyState));
224-
}
225-
}
226-
239+
// Signal that data was received
240+
OnDataReceived = true;
227241
}
228242

229243
private class CloseListener : IListener

0 commit comments

Comments
 (0)