mirror of
https://github.com/JKorf/CryptoExchange.Net
synced 2025-06-07 16:06:15 +00:00
Update socket Close to return Task, removed eventhandlers after opening socket
This commit is contained in:
parent
e5f5125f8f
commit
7996fa4c20
@ -7,7 +7,7 @@
|
||||
<PropertyGroup>
|
||||
<PackageId>CryptoExchange.Net</PackageId>
|
||||
<Authors>JKorf</Authors>
|
||||
<PackageVersion>0.0.9</PackageVersion>
|
||||
<PackageVersion>0.0.10</PackageVersion>
|
||||
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
|
||||
<PackageProjectUrl>https://github.com/JKorf/CryptoExchange.Net</PackageProjectUrl>
|
||||
<PackageLicenseUrl>https://github.com/JKorf/CryptoExchange.Net/blob/master/LICENSE</PackageLicenseUrl>
|
||||
|
@ -9,7 +9,7 @@ using CryptoExchange.Net.Interfaces;
|
||||
using SuperSocket.ClientEngine.Proxy;
|
||||
using WebSocket4Net;
|
||||
|
||||
namespace CryptoExchange.Net
|
||||
namespace CryptoExchange.Net.Implementation
|
||||
{
|
||||
public class BaseSocket: IWebsocket
|
||||
{
|
||||
@ -69,9 +69,17 @@ namespace CryptoExchange.Net
|
||||
handle(data);
|
||||
}
|
||||
|
||||
public void Close()
|
||||
public async Task Close()
|
||||
{
|
||||
socket.Close();
|
||||
await Task.Run(() =>
|
||||
{
|
||||
ManualResetEvent evnt = new ManualResetEvent(false);
|
||||
var handler = new EventHandler((o, a) => evnt.Set());
|
||||
socket.Closed += handler;
|
||||
socket.Close();
|
||||
evnt.WaitOne();
|
||||
socket.Closed -= handler;
|
||||
});
|
||||
}
|
||||
|
||||
public void Send(string data)
|
||||
@ -84,10 +92,13 @@ namespace CryptoExchange.Net
|
||||
return await Task.Run(() =>
|
||||
{
|
||||
ManualResetEvent evnt = new ManualResetEvent(false);
|
||||
socket.Opened += (o, s) => evnt.Set();
|
||||
socket.Closed += (o, s) => evnt.Set();
|
||||
var handler = new EventHandler((o, a) => evnt.Set());
|
||||
socket.Opened += handler;
|
||||
socket.Closed += handler;
|
||||
socket.Open();
|
||||
evnt.WaitOne();
|
||||
socket.Opened -= handler;
|
||||
socket.Closed -= handler;
|
||||
return socket.State == WebSocketState.Open;
|
||||
});
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
using CryptoExchange.Net.Interfaces;
|
||||
|
||||
namespace CryptoExchange.Net
|
||||
namespace CryptoExchange.Net.Implementation
|
||||
{
|
||||
public class WebsocketFactory : IWebsocketFactory
|
||||
{
|
||||
|
@ -18,7 +18,7 @@ namespace CryptoExchange.Net.Interfaces
|
||||
|
||||
Task<bool> Connect();
|
||||
void Send(string data);
|
||||
void Close();
|
||||
Task Close();
|
||||
void SetProxy(string host, int port);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user