Skip to content

Commit bf40e3d

Browse files
author
Elad Zelingher
committed
Autoping framework 4.0 implementation
1 parent dc51977 commit bf40e3d

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

src/net45/Default/WampSharp.Fleck/Fleck/FleckWampConnection.cs

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
using System;
22
using System.Reactive;
33
using System.Reactive.Linq;
4+
using System.Reactive.Threading.Tasks;
45
using System.Threading.Tasks;
56
using Fleck;
67
using WampSharp.Core.Listener;
8+
using WampSharp.Logging;
79

810
namespace WampSharp.Fleck
911
{
@@ -33,16 +35,25 @@ private void OnConnectionOpen()
3335
#if NET40
3436
private void StartPing()
3537
{
36-
Observable.Generate(0, x => true, x => x, x => x)
37-
.Select(x =>
38-
Observable.FromAsync(() =>
39-
{
40-
byte[] ticks = GetCurrentTicks();
41-
return mWebSocketConnection.SendPing(ticks);
42-
}).Concat(Observable.Timer(mAutoSendPingInterval)
43-
.Select(y => Unit.Default))
38+
Observable.Defer
39+
(() => Observable.FromAsync
40+
(() =>
41+
{
42+
byte[] ticks = GetCurrentTicks();
43+
return mWebSocketConnection.SendPing(ticks);
44+
})
45+
.Concat(Observable.Timer(mAutoSendPingInterval)
46+
.Select(y => Unit.Default))
4447
)
45-
.Merge(1);
48+
.Repeat()
49+
.ToTask()
50+
.ContinueWith(x =>
51+
{
52+
if (x.Exception != null)
53+
{
54+
mLogger.WarnException("Failed pinging remote peer", x.Exception);
55+
}
56+
});
4657
}
4758

4859
#elif NET45
@@ -63,8 +74,9 @@ private async void Ping()
6374
await mWebSocketConnection.SendPing(ticks);
6475
await Task.Delay(mAutoSendPingInterval);
6576
}
66-
catch (Exception)
77+
catch (Exception ex)
6778
{
79+
mLogger.WarnException("Failed pinging remote peer", ex);
6880
}
6981
}
7082
}

0 commit comments

Comments
 (0)