Change udp port opening routine for some scenarios

Experimental
This commit is contained in:
Travis Nickles 2018-12-05 05:16:54 -06:00
parent 0f3d6e379a
commit ea3787eef2

View File

@ -177,7 +177,7 @@ namespace DS4Windows
Monitor.Pulse(busThrLck); Monitor.Pulse(busThrLck);
} }
public void ChangeUDPStatus(bool state) public void ChangeUDPStatus(bool state, bool openPort=true)
{ {
if (state && _udpServer == null) if (state && _udpServer == null)
{ {
@ -185,6 +185,10 @@ namespace DS4Windows
TestQueueBus(() => TestQueueBus(() =>
{ {
_udpServer = new UdpServer(GetPadDetailForIdx); _udpServer = new UdpServer(GetPadDetailForIdx);
if (openPort)
{
Task.Run(() =>
{
var UDP_SERVER_PORT = Global.getUDPServerPortNum(); var UDP_SERVER_PORT = Global.getUDPServerPortNum();
try try
@ -199,6 +203,8 @@ namespace DS4Windows
LogDebug(errMsg, true); LogDebug(errMsg, true);
AppLogger.LogToTray(errMsg, true, true); AppLogger.LogToTray(errMsg, true, true);
} }
}).Wait();
}
udpChangeStatus = false; udpChangeStatus = false;
}); });
@ -312,7 +318,7 @@ namespace DS4Windows
if (isUsingUDPServer() && _udpServer == null) if (isUsingUDPServer() && _udpServer == null)
{ {
ChangeUDPStatus(true); ChangeUDPStatus(true, false);
while (udpChangeStatus == true) while (udpChangeStatus == true)
{ {
Thread.SpinWait(500); Thread.SpinWait(500);
@ -426,6 +432,25 @@ namespace DS4Windows
} }
running = true; 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 else
{ {