private async Task SendAsyncInternal(CoapMessage message, ICoapEndpoint remoteEndpoint, CancellationToken token) { if (Endpoint == null) { return; } if (remoteEndpoint == null) { remoteEndpoint = new CoapEndpoint { BaseUri = new UriBuilder(message.GetUri()) { Path = "/", Fragment = "", Query = "" }.Uri, IsMulticast = message.IsMulticast, } } ; else if (message.IsMulticast && !remoteEndpoint.IsMulticast) { throw new CoapClientException("Can not send CoAP multicast message to a non-multicast endpoint"); } await Task.Run(async() => await Endpoint.SendAsync(new CoapPacket { Payload = message.Serialise(), Endpoint = remoteEndpoint }), token).ConfigureAwait(false); }
private async Task SendAsyncInternal(CoapMessage message, ICoapEndpoint remoteEndpoint, CancellationToken token) { if (remoteEndpoint == null) { remoteEndpoint = new CoapEndpoint { BaseUri = new UriBuilder(message.GetUri()) { Path = "/", Fragment = "", Query = "" }.Uri, IsMulticast = message.IsMulticast, } } ; else if (message.IsMulticast && !remoteEndpoint.IsMulticast) { throw new CoapClientException("Can not send CoAP multicast message to a non-multicast endpoint"); } Task task; lock (this) { task = (Endpoint == null) ? Task.CompletedTask : Endpoint.SendAsync(new CoapPacket { Payload = message.ToBytes(), Endpoint = remoteEndpoint }, token); } await task.ConfigureAwait(false); }