|
@@ -10,6 +10,8 @@ namespace MQTTnet.Implementations |
|
|
{ |
|
|
{ |
|
|
readonly Socket _socket; |
|
|
readonly Socket _socket; |
|
|
|
|
|
|
|
|
|
|
|
NetworkStream _networkStream; |
|
|
|
|
|
|
|
|
public CrossPlatformSocket(AddressFamily addressFamily) |
|
|
public CrossPlatformSocket(AddressFamily addressFamily) |
|
|
{ |
|
|
{ |
|
|
_socket = new Socket(addressFamily, SocketType.Stream, ProtocolType.Tcp); |
|
|
_socket = new Socket(addressFamily, SocketType.Stream, ProtocolType.Tcp); |
|
@@ -137,6 +139,8 @@ namespace MQTTnet.Implementations |
|
|
|
|
|
|
|
|
try |
|
|
try |
|
|
{ |
|
|
{ |
|
|
|
|
|
_networkStream?.Dispose(); |
|
|
|
|
|
|
|
|
// Workaround for: workaround for https://github.com/dotnet/corefx/issues/24430 |
|
|
// Workaround for: workaround for https://github.com/dotnet/corefx/issues/24430 |
|
|
using (cancellationToken.Register(() => _socket.Dispose())) |
|
|
using (cancellationToken.Register(() => _socket.Dispose())) |
|
|
{ |
|
|
{ |
|
@@ -148,6 +152,8 @@ namespace MQTTnet.Implementations |
|
|
await _socket.ConnectAsync(host, port).ConfigureAwait(false); |
|
|
await _socket.ConnectAsync(host, port).ConfigureAwait(false); |
|
|
#endif |
|
|
#endif |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
_networkStream = new NetworkStream(_socket, true); |
|
|
} |
|
|
} |
|
|
catch (ObjectDisposedException) |
|
|
catch (ObjectDisposedException) |
|
|
{ |
|
|
{ |
|
@@ -190,11 +196,12 @@ namespace MQTTnet.Implementations |
|
|
|
|
|
|
|
|
public NetworkStream GetStream() |
|
|
public NetworkStream GetStream() |
|
|
{ |
|
|
{ |
|
|
return new NetworkStream(_socket, true); |
|
|
|
|
|
|
|
|
return _networkStream; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void Dispose() |
|
|
public void Dispose() |
|
|
{ |
|
|
{ |
|
|
|
|
|
_networkStream?.Dispose(); |
|
|
_socket?.Dispose(); |
|
|
_socket?.Dispose(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|