Use SendToAsync and uncheck to improve UDP server performance

This commit is contained in:
Travis Nickles 2018-08-03 20:05:44 -05:00
parent 24403394ad
commit 4c70b7a8f0

View File

@ -413,6 +413,8 @@ namespace DS4Windows
} }
private bool ReportToBuffer(DS4State hidReport, byte[] outputData, ref int outIdx) private bool ReportToBuffer(DS4State hidReport, byte[] outputData, ref int outIdx)
{
unchecked
{ {
outputData[outIdx] = 0; outputData[outIdx] = 0;
@ -522,6 +524,7 @@ namespace DS4Windows
Array.Clear(outputData, outIdx, 12); Array.Clear(outputData, outIdx, 12);
outIdx += 12; outIdx += 12;
} }
}
return true; return true;
} }
@ -621,7 +624,11 @@ namespace DS4Windows
foreach (var cl in clientsList) foreach (var cl in clientsList)
{ {
try { udpSock.SendTo(outputData, cl); } //try { udpSock.SendTo(outputData, cl); }
SocketAsyncEventArgs args = new SocketAsyncEventArgs();
args.RemoteEndPoint = cl;
args.SetBuffer(outputData, 0, outputData.Length);
try { udpSock.SendToAsync(args); }
catch (SocketException ex) { } catch (SocketException ex) { }
} }
clientsList.Clear(); clientsList.Clear();