Merge pull request #43 from Cimpress-MCP/udp_v4

Rolled Udp input listener support to ipv4 only.
This commit is contained in:
Eric Fontana
2015-04-13 06:46:17 -04:00
3 changed files with 23 additions and 27 deletions

View File

@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.3.20.0")]
[assembly: AssemblyFileVersion("1.3.20.0")]
[assembly: AssemblyVersion("1.3.21.0")]
[assembly: AssemblyFileVersion("1.3.21.0")]

View File

@@ -13,8 +13,8 @@ namespace TimberWinR.Inputs
{
public class UdpInputListener : InputListener
{
private UdpClient _udpListenerV6;
private readonly Thread _listenThreadV6;
private UdpClient _udpListenerV4;
private readonly Thread _listenThreadV4;
private readonly int _port;
private long _receivedMessages;
@@ -37,12 +37,10 @@ namespace TimberWinR.Inputs
: base(cancelToken, "Win32-Udp")
{
_port = port;
_receivedMessages = 0;
_listenThreadV6 = new Thread(StartListener);
_listenThreadV6.Start();
_listenThreadV4 = new Thread(StartListener);
_listenThreadV4.Start();
}
@@ -51,31 +49,21 @@ namespace TimberWinR.Inputs
LogManager.GetCurrentClassLogger().Info("Shutting Down {0}", InputType);
// close UDP listeners, which will end the listener threads
_udpListenerV6.Close();
_udpListenerV4.Close();
// wait for completion of the threads
_listenThreadV6.Join();
_listenThreadV4.Join();
base.Shutdown();
}
private void StartListener()
{
var groupV6 = new IPEndPoint(IPAddress.IPv6Any, _port);
// Create the socket as IPv6
var dualModeSocket = new Socket(AddressFamily.InterNetworkV6, SocketType.Dgram, ProtocolType.Udp);
var groupV4 = new IPEndPoint(IPAddress.Any, _port);
//
// Now, disable the IPV6only flag to make it compatable with both ipv4 and ipv6
// See: http://blogs.msdn.com/b/malarch/archive/2005/11/18/494769.aspx
//
dualModeSocket.SetSocketOption(SocketOptionLevel.IPv6, SocketOptionName.IPv6Only, 0);
dualModeSocket.Bind(groupV6);
_udpListenerV4 = new UdpClient(_port);
_udpListenerV6 = new UdpClient();
_udpListenerV6.Client = dualModeSocket;
LogManager.GetCurrentClassLogger().Info("Udp Input on Port {0} Ready", groupV6);
LogManager.GetCurrentClassLogger().Info("Udp Input on Port {0} Ready", groupV4);
string lastMessage = "";
try
@@ -84,13 +72,18 @@ namespace TimberWinR.Inputs
{
try
{
byte[] bytes = _udpListenerV6.Receive(ref groupV6);
byte[] bytes = _udpListenerV4.Receive(ref groupV4);
var data = Encoding.UTF8.GetString(bytes, 0, bytes.Length);
lastMessage = data;
var json = JObject.Parse(data);
ProcessJson(json);
Interlocked.Increment(ref _receivedMessages);
}
catch(ArgumentException aex)
{
LogManager.GetCurrentClassLogger().Error(aex);
break;
}
catch(SocketException)
{
break;
@@ -107,7 +100,7 @@ namespace TimberWinR.Inputs
Interlocked.Increment(ref _parsedErrors);
}
}
_udpListenerV6.Close();
_udpListenerV4.Close();
}
catch (Exception ex)
{

View File

@@ -3,6 +3,9 @@ TimberWinR Release Notes
A Native Windows to Redis/Elasticsearch Logstash Agent which runs as a service.
Version / Date
### 1.3.21.0 - 04/13/2015
1. Rolled Udp listener support to V4 only, too many issues with dual mode sockets
and hosts file. If we want to add this back, I will add a Udpv6 input.
### 1.3.20.0 - 2015-04-03