Updated task methods.

Instead of awaiting most tasks, changed to simply returning the tasks.
This commit is contained in:
Zazzmatazz
2017-06-02 16:20:48 -04:00
parent 2db289a658
commit 5c1eceb8a9
7 changed files with 52 additions and 55 deletions
@@ -30,11 +30,11 @@ namespace MQTTnet
_socket = socket ?? throw new ArgumentNullException(nameof(socket));
_cert = cert ?? throw new ArgumentNullException(nameof(cert));
if (_socket.Connected)
{
NetworkStream ns = new NetworkStream(_socket, true);
_sslStream = new SslStream(ns);
}
if (!_socket.Connected)
return;
NetworkStream ns = new NetworkStream(_socket, true);
_sslStream = new SslStream(ns);
}
public async Task Authenticate()
@@ -46,11 +46,11 @@ namespace MQTTnet
/// Asynchronously connects to the client described in the <see cref="MqttClientOptions"/>.
/// </summary>
/// <param name="options">The <see cref="MqttClientOptions"/> describing the connection.</param>
public async Task ConnectAsync(MqttClientOptions options)
public Task ConnectAsync(MqttClientOptions options)
{
try
{
await Task.Factory.FromAsync(_socket.BeginConnect, _socket.EndConnect, options.Server, options.Port,
return Task.Factory.FromAsync(_socket.BeginConnect, _socket.EndConnect, options.Server, options.Port,
null);
}
catch (SocketException exception)
@@ -62,11 +62,11 @@ namespace MQTTnet
/// <summary>
/// Asynchronously disconnects the client from the server.
/// </summary>
public async Task DisconnectAsync()
public Task DisconnectAsync()
{
try
{
await Task.Factory.FromAsync(_socket.BeginDisconnect, _socket.EndDisconnect, true, null);
return Task.Factory.FromAsync(_socket.BeginDisconnect, _socket.EndDisconnect, true, null);
}
catch (SocketException exception)
{
@@ -78,14 +78,14 @@ namespace MQTTnet
/// Asynchronously writes a sequence of bytes to the socket.
/// </summary>
/// <param name="buffer">The buffer to write data from.</param>
public async Task WriteAsync(byte[] buffer)
public Task WriteAsync(byte[] buffer)
{
if (buffer == null)
throw new ArgumentNullException(nameof(buffer));
try
{
await _sslStream.WriteAsync(buffer, 0, buffer.Length);
return _sslStream.WriteAsync(buffer, 0, buffer.Length);
}
catch (Exception ex)
when (ex is SocketException || ex is IOException)
@@ -98,11 +98,11 @@ namespace MQTTnet
/// Asynchronously reads a sequence of bytes from the socket.
/// </summary>
/// <param name="buffer">The buffer to write the data into.</param>
public async Task ReadAsync(byte[] buffer)
public Task ReadAsync(byte[] buffer)
{
try
{
await _sslStream.ReadAsync(buffer, 0, buffer.Length);
return _sslStream.ReadAsync(buffer, 0, buffer.Length);
}
catch (Exception ex)
when (ex is SocketException || ex is IOException)