Skip to content

Commit

Permalink
Update WebSocketSharp and WebSocket4Net clients
Browse files Browse the repository at this point in the history
Match DefaultWebSocketClient changes.
  • Loading branch information
sonvister committed Jan 30, 2018
1 parent 28fe77d commit 9a4f533
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Version>0.1.1</Version>
<AssemblyVersion>0.1.1.0</AssemblyVersion>
<FileVersion>0.1.1.0</FileVersion>
<Version>0.1.2</Version>
<AssemblyVersion>0.1.2.0</AssemblyVersion>
<FileVersion>0.1.2.0</FileVersion>
<Authors>sonvister</Authors>
<Company />
<Copyright>Copyright © 2018 sonvister</Copyright>
Expand Down
15 changes: 12 additions & 3 deletions samples/Binance.WebSocket.WebSocket4Net/WebSocket4NetClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ namespace Binance.WebSocket
{
public class WebSocket4NetClient : WebSocketClient
{
private volatile bool _isOpen;

public WebSocket4NetClient(ILogger<WebSocket4NetClient> logger)
: base(logger)
{ }
Expand All @@ -23,6 +25,11 @@ public override async Task StreamAsync(Uri uri, CancellationToken token)

token.ThrowIfCancellationRequested();

if (IsStreaming)
throw new InvalidOperationException($"{nameof(WebSocket4NetClient)}.{nameof(StreamAsync)}: Already streaming (this method is not reentrant).");

IsStreaming = true;

Exception exception = null;

var tcs = new TaskCompletionSource<object>();
Expand All @@ -32,7 +39,7 @@ public override async Task StreamAsync(Uri uri, CancellationToken token)

webSocket.Opened += (s, e) =>
{
IsStreaming = true;
_isOpen = true;
RaiseOpenEvent();
};

Expand Down Expand Up @@ -107,11 +114,13 @@ await tcs.Task

webSocket.Dispose();

if (IsStreaming)
if (_isOpen)
{
IsStreaming = false;
_isOpen = false;
RaiseCloseEvent();
}

IsStreaming = false;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Version>0.1.1</Version>
<Version>0.1.2</Version>
<Authors>sonvister</Authors>
<Company />
<AssemblyVersion>0.1.1.0</AssemblyVersion>
<FileVersion>0.1.1.0</FileVersion>
<AssemblyVersion>0.1.2.0</AssemblyVersion>
<FileVersion>0.1.2.0</FileVersion>
<Copyright>Copyright © 2018 sonvister</Copyright>
</PropertyGroup>

Expand Down
15 changes: 12 additions & 3 deletions samples/Binance.WebSocket.WebSocketSharp/WebSocketSharpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ namespace Binance.WebSocket
{
public class WebSocketSharpClient : WebSocketClient
{
private volatile bool _isOpen;

public WebSocketSharpClient(ILogger<WebSocketSharpClient> logger)
: base(logger)
{ }
Expand All @@ -25,6 +27,11 @@ public override async Task StreamAsync(Uri uri, CancellationToken token)

token.ThrowIfCancellationRequested();

if (IsStreaming)
throw new InvalidOperationException($"{nameof(WebSocketSharpClient)}.{nameof(StreamAsync)}: Already streaming (this method is not reentrant).");

IsStreaming = true;

Exception exception = null;

var tcs = new TaskCompletionSource<object>();
Expand All @@ -36,7 +43,7 @@ public override async Task StreamAsync(Uri uri, CancellationToken token)

webSocket.OnOpen += (s, e) =>
{
IsStreaming = true;
_isOpen = true;
RaiseOpenEvent();
};

Expand Down Expand Up @@ -114,11 +121,13 @@ await tcs.Task

((IDisposable) webSocket).Dispose();

if (IsStreaming)
if (_isOpen)
{
IsStreaming = false;
_isOpen = false;
RaiseCloseEvent();
}

IsStreaming = false;
}
}
}
Expand Down

0 comments on commit 9a4f533

Please sign in to comment.