This repository has been archived by the owner on Feb 12, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
8bc28f4
commit c74c74a
Showing
10 changed files
with
139 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Licensed under the BSD license | ||
// See the LICENSE file in the project root for more information | ||
|
||
using System.Net.Sockets; | ||
|
||
namespace NLog.Targets.Syslog.Extensions | ||
{ | ||
internal static class SocketExtensions | ||
{ | ||
public static bool IsConnected(this Socket socket, int timeout) | ||
{ | ||
if (timeout <= 0) | ||
return true; | ||
|
||
var isDisconnected = socket?.Poll(timeout, SelectMode.SelectRead) == true && socket?.Available == 0; | ||
return !isDisconnected; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,47 @@ | ||
// Licensed under the BSD license | ||
// See the LICENSE file in the project root for more information | ||
|
||
using System; | ||
using System.Net.Sockets; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using NLog.Targets.Syslog.Extensions; | ||
using NLog.Targets.Syslog.Settings; | ||
|
||
namespace NLog.Targets.Syslog.MessageSend | ||
{ | ||
internal class Udp : MessageTransmitter | ||
{ | ||
private readonly UdpClient udp; | ||
private volatile bool disposed; | ||
private readonly int connectionCheckTimeout; | ||
private UdpClient udp; | ||
|
||
public Udp(UdpConfig udpConfig) : base(udpConfig.Server, udpConfig.Port) | ||
protected override bool Ready | ||
{ | ||
get { return udp?.Client?.IsConnected(connectionCheckTimeout) == true; } | ||
} | ||
|
||
public Udp(UdpConfig udpConfig) : base(udpConfig.Server, udpConfig.Port, udpConfig.ReconnectInterval) | ||
{ | ||
connectionCheckTimeout = udpConfig.ConnectionCheckTimeout; | ||
} | ||
|
||
protected override Task Setup() | ||
{ | ||
TearDown(); | ||
udp = new UdpClient(IpAddress, Port); | ||
return Task.FromResult<object>(null); | ||
} | ||
|
||
public override Task SendMessageAsync(ByteArray message, CancellationToken token) | ||
protected override Task SendAsync(ByteArray message, CancellationToken token) | ||
{ | ||
if (token.IsCancellationRequested) | ||
return Task.FromResult<object>(null); | ||
|
||
return udp.SendAsync(message, message.Length); | ||
} | ||
|
||
public override void Dispose() | ||
protected override void TearDown() | ||
{ | ||
if (disposed) | ||
return; | ||
disposed = true; | ||
udp.Close(); | ||
udp?.Close(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.