diff --git a/DS4Windows/DS4Control/ControlService.cs b/DS4Windows/DS4Control/ControlService.cs index 6befb0a..4fa83b7 100644 --- a/DS4Windows/DS4Control/ControlService.cs +++ b/DS4Windows/DS4Control/ControlService.cs @@ -181,9 +181,9 @@ namespace DS4Windows { if (state && _udpServer == null) { + udpChangeStatus = true; TestQueueBus(() => { - udpChangeStatus = true; _udpServer = new UdpServer(GetPadDetailForIdx); var UDP_SERVER_PORT = Global.getUDPServerPortNum(); @@ -315,7 +315,7 @@ namespace DS4Windows ChangeUDPStatus(true); while (udpChangeStatus == true) { - Task.Delay(100); + Thread.SpinWait(500); } } @@ -426,25 +426,6 @@ namespace DS4Windows } running = true; - - if (_udpServer != null) - { - //var UDP_SERVER_PORT = 26760; - var UDP_SERVER_PORT = Global.getUDPServerPortNum(); - - try - { - _udpServer.Start(UDP_SERVER_PORT); - LogDebug("UDP server listening on port " + UDP_SERVER_PORT); - } - catch (System.Net.Sockets.SocketException ex) - { - var errMsg = String.Format("Couldn't start UDP server on port {0}, outside applications won't be able to access pad data ({1})", UDP_SERVER_PORT, ex.SocketErrorCode); - - LogDebug(errMsg, true); - AppLogger.LogToTray(errMsg, true, true); - } - } } else { diff --git a/DS4Windows/DS4Control/UdpServer.cs b/DS4Windows/DS4Control/UdpServer.cs index 1604680..76ad2aa 100644 --- a/DS4Windows/DS4Control/UdpServer.cs +++ b/DS4Windows/DS4Control/UdpServer.cs @@ -85,6 +85,7 @@ namespace DS4Windows for (int num = 0; num <= 19; num++) { SocketAsyncEventArgs args = new SocketAsyncEventArgs(); + args.SetBuffer(new byte[100], 0, 100); argsList[num] = args; } } @@ -186,13 +187,14 @@ namespace DS4Windows //try { udpSock.SendTo(packetData, clientEP); } int temp = 0; poolLock.EnterWriteLock(); - listInd = ++listInd % 20; temp = listInd; + listInd = ++listInd % 20; + SocketAsyncEventArgs args = argsList[temp]; poolLock.ExitWriteLock(); - SocketAsyncEventArgs args = argsList[temp]; args.RemoteEndPoint = clientEP; - args.SetBuffer(packetData, 0, packetData.Length); + Array.Copy(packetData, args.Buffer, packetData.Length); + //args.SetBuffer(packetData, 0, packetData.Length); try { udpSock.SendToAsync(args); } @@ -651,13 +653,13 @@ namespace DS4Windows //try { udpSock.SendTo(outputData, cl); } int temp = 0; poolLock.EnterWriteLock(); - listInd = ++listInd % 20; temp = listInd; + listInd = ++listInd % 20; + SocketAsyncEventArgs args = argsList[temp]; poolLock.ExitWriteLock(); - SocketAsyncEventArgs args = argsList[temp]; args.RemoteEndPoint = cl; - args.SetBuffer(outputData, 0, outputData.Length); + Array.Copy(outputData, args.Buffer, outputData.Length); try { udpSock.SendToAsync(args); } diff --git a/DS4Windows/DS4Forms/DS4Form.cs b/DS4Windows/DS4Forms/DS4Form.cs index 80f8149..c8791b7 100644 --- a/DS4Windows/DS4Forms/DS4Form.cs +++ b/DS4Windows/DS4Forms/DS4Form.cs @@ -2549,13 +2549,18 @@ Properties.Resources.DS4Update, MessageBoxButtons.YesNo, MessageBoxIcon.Question if (!state) { Program.rootHub.ChangeMotionEventStatus(state); - await TaskRunner.Delay(100); - Program.rootHub.ChangeUDPStatus(state); + await TaskRunner.Delay(100).ContinueWith((t) => + { + Program.rootHub.ChangeUDPStatus(state); + }); } else { Program.rootHub.ChangeUDPStatus(state); - Program.rootHub.ChangeMotionEventStatus(state); + await TaskRunner.Delay(100).ContinueWith((t) => + { + Program.rootHub.ChangeMotionEventStatus(state); + }); } nUDUdpPortNum.Enabled = state; diff --git a/DS4Windows/Properties/AssemblyInfo.cs b/DS4Windows/Properties/AssemblyInfo.cs index 8e260e4..a5b21be 100644 --- a/DS4Windows/Properties/AssemblyInfo.cs +++ b/DS4Windows/Properties/AssemblyInfo.cs @@ -33,7 +33,7 @@ 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.5.16")] -[assembly: AssemblyFileVersion("1.5.16")] +[assembly: AssemblyVersion("1.5.17")] +[assembly: AssemblyFileVersion("1.5.17")] [assembly: NeutralResourcesLanguage("en")]