Skip to content

Commit

Permalink
[dht] Allow exceptions from DhtListener to propagate
Browse files Browse the repository at this point in the history
If we propagate exceptions when sending dht messages
we can immediately time out requests when we fail to
send them.
  • Loading branch information
alanmcgovern committed Oct 30, 2021
1 parent a80e09c commit 1858b63
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ protected UdpListener (IPEndPoint endpoint)

public async Task SendAsync (byte[] buffer, IPEndPoint endpoint)
{
try {
if (endpoint.Address != IPAddress.Any)
await Client.SendAsync (buffer, buffer.Length, endpoint).ConfigureAwait (false);
} catch (Exception ex) {
//logger.Exception (ex, "UdpListener could not send message");
}
if (Status == ListenerStatus.NotListening)
throw new InvalidOperationException ("You must invoke StartAsync before sending or receiving a message with this listener.");
if (Status == ListenerStatus.PortNotFree)
throw new InvalidOperationException ($"The listener could not bind to ${EndPoint}. Choose a new listening endpoint.");

await Client.SendAsync (buffer, buffer.Length, endpoint).ConfigureAwait (false);
}

protected override void Start (CancellationToken token)
Expand Down

0 comments on commit 1858b63

Please sign in to comment.