11using System ;
22using System . Reactive ;
33using System . Reactive . Linq ;
4+ using System . Reactive . Threading . Tasks ;
45using System . Threading . Tasks ;
56using Fleck ;
67using WampSharp . Core . Listener ;
8+ using WampSharp . Logging ;
79
810namespace 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