Version 1.2.1.0 - don't resolve hostname if it's an IP already.

This commit is contained in:
Luke Venediger
2013-10-30 23:24:01 +02:00
parent bb0fa0befa
commit 174de459fc
4 changed files with 32 additions and 8 deletions

View File

@@ -1,5 +1,10 @@
# statsd-csharp-client Changelog
## v1.2.1.0
* Fixed a bug in the tcp output channel's retry logic
* Skip DNS resolution on the UDP client if already an IP Address
* Fall back to the Null Output Channel if the client is created with an empty host name.
## v1.2.0.0
* Support the Raw metric format
* A few more unit tests

View File

@@ -12,12 +12,17 @@ namespace StatsdClient
private UdpClient _udpClient;
public Socket ClientSocket { get { return _udpClient.Client; } }
public UdpOutputChannel(string host, int port)
public UdpOutputChannel(string hostOrIPAddress, int port)
{
// Convert to ipv4 address
var ipv4Address = Dns.GetHostAddresses(host).First(p => p.AddressFamily == AddressFamily.InterNetwork);
IPAddress ipAddress;
// Is this an IP address already?
if (!IPAddress.TryParse(hostOrIPAddress, out ipAddress))
{
// Convert to ipv4 address
ipAddress = Dns.GetHostAddresses(hostOrIPAddress).First(p => p.AddressFamily == AddressFamily.InterNetwork);
}
_udpClient = new UdpClient();
_udpClient.Connect(ipv4Address, port);
_udpClient.Connect(ipAddress, port);
}
public void Send(string line)

View File

@@ -168,5 +168,19 @@ namespace StatsdClientTests
var statsd = new Statsd("nowhere.here.or.anywhere", 12000);
statsd.LogCount("test.stat");
}
[TestMethod]
public void CreateClient_WithIPAddress_DoesNotError()
{
var statsd = new Statsd("127.0.0.1", 12000);
statsd.LogCount("test.stat");
}
[TestMethod]
public void CreateClient_WithInvalidCharactersInHostName_DoesNotError()
{
var statsd = new Statsd("@%)(F(FSDLKDEQ423t0-vbdfb", 12000);
statsd.LogCount("test.foo");
}
}
}

View File

@@ -2,7 +2,7 @@
<package >
<metadata>
<id>StatsdCsharpClient</id>
<version>1.2.0.0</version>
<version>1.2.1.0</version>
<title>Simple Statsd Client for .Net 3.5, 4.0 and 4.5</title>
<authors>Luke Venediger</authors>
<owners>Luke Venediger</owners>
@@ -27,9 +27,9 @@
Licence: MIT
</description>
<releaseNotes>
* Support the Raw metric format
* A few more unit tests
* Fixed a bug where you couldn't start up if the host could not be resolved
* Fixed a bug in the tcp output channel's retry logic
* Skip DNS resolution on the UDP client if already an IP Address
* Fall back to the Null Output Channel if the client is created with an empty host name.
</releaseNotes>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<copyright>Copyright 2013 Luke Venediger</copyright>