Skip to content

Commit 7c55a69

Browse files
author
Elad Zelingher
committed
Fixing reconnector issues
1 parent dc6b466 commit 7c55a69

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/net45/Extensions/WampSharp.WebSockets/WebSockets/WebSocketWrapperConnection.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ await mWebSocket.CloseAsync(WebSocketCloseStatus.NormalClosure,
129129
catch (Exception ex)
130130
{
131131
RaiseConnectionError(ex);
132+
RaiseConnectionClosed();
132133
}
133134
}
134135

src/net45/WampSharp/WAMP2/V2/Api/WampChannelReconnector.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public class WampChannelReconnector : IDisposable
1717
private IDisposable mDisposable = Disposable.Empty;
1818
private bool mStarted = false;
1919
private readonly object mLock = new object();
20+
private IDisposable mConnectionBrokenDisposable;
2021

2122
/// <summary>
2223
/// Initializes a new instance of <see cref="WampChannelReconnector"/>.
@@ -29,20 +30,22 @@ public WampChannelReconnector(IWampChannel channel, Func<Task> connector)
2930

3031
var connectionBrokenObservable =
3132
Observable.FromEventPattern<WampSessionCloseEventArgs>
32-
(x => monitor.ConnectionBroken += x,
33-
x => monitor.ConnectionBroken -= x)
34-
.Select(x => Unit.Default);
33+
(x => monitor.ConnectionBroken += x,
34+
x => monitor.ConnectionBroken -= x)
35+
.Select(x => Unit.Default)
36+
.Replay(1);
3537

3638
var onceAndConnectionBroken =
37-
Observable.Return(Unit.Default).Concat
38-
(connectionBrokenObservable);
39+
connectionBrokenObservable.StartWith(Unit.Default);
3940

4041
IObservable<IObservable<Unit>> reconnect =
4142
from connectionBroke in onceAndConnectionBroken
4243
let tryReconnect = Observable.FromAsync(connector)
4344
.Catch<Unit, Exception>(x => Observable.Empty<Unit>())
4445
select tryReconnect;
4546

47+
mConnectionBrokenDisposable = connectionBrokenObservable.Connect();
48+
4649
mMerged = reconnect.Concat();
4750
}
4851

@@ -78,6 +81,7 @@ public void Dispose()
7881
{
7982
mMerged = null;
8083
mDisposable.Dispose();
84+
mConnectionBrokenDisposable.Dispose();
8185
}
8286
}
8387
}

0 commit comments

Comments
 (0)