mirror of
https://github.com/cemu-project/DS4Windows.git
synced 2025-02-16 16:09:13 +01:00
Added Semaphore to UDP server class
This commit is contained in:
parent
40b63c9853
commit
dd9804e0bc
@ -73,6 +73,7 @@ namespace DS4Windows
|
|||||||
private SocketAsyncEventArgs[] argsList;
|
private SocketAsyncEventArgs[] argsList;
|
||||||
private int listInd = 0;
|
private int listInd = 0;
|
||||||
private ReaderWriterLockSlim poolLock = new ReaderWriterLockSlim();
|
private ReaderWriterLockSlim poolLock = new ReaderWriterLockSlim();
|
||||||
|
private SemaphoreSlim _pool;
|
||||||
private const int ARG_BUFFER_LEN = 80;
|
private const int ARG_BUFFER_LEN = 80;
|
||||||
|
|
||||||
public delegate void GetPadDetail(int padIdx, ref DualShockPadMeta meta);
|
public delegate void GetPadDetail(int padIdx, ref DualShockPadMeta meta);
|
||||||
@ -82,6 +83,7 @@ namespace DS4Windows
|
|||||||
public UdpServer(GetPadDetail getPadDetailDel)
|
public UdpServer(GetPadDetail getPadDetailDel)
|
||||||
{
|
{
|
||||||
portInfoGet = getPadDetailDel;
|
portInfoGet = getPadDetailDel;
|
||||||
|
_pool = new SemaphoreSlim(ARG_BUFFER_LEN);
|
||||||
argsList = new SocketAsyncEventArgs[ARG_BUFFER_LEN];
|
argsList = new SocketAsyncEventArgs[ARG_BUFFER_LEN];
|
||||||
for (int num = 0; num < ARG_BUFFER_LEN; num++)
|
for (int num = 0; num < ARG_BUFFER_LEN; num++)
|
||||||
{
|
{
|
||||||
@ -193,6 +195,7 @@ namespace DS4Windows
|
|||||||
SocketAsyncEventArgs args = argsList[temp];
|
SocketAsyncEventArgs args = argsList[temp];
|
||||||
poolLock.ExitWriteLock();
|
poolLock.ExitWriteLock();
|
||||||
|
|
||||||
|
_pool.Wait();
|
||||||
args.RemoteEndPoint = clientEP;
|
args.RemoteEndPoint = clientEP;
|
||||||
Array.Copy(packetData, args.Buffer, packetData.Length);
|
Array.Copy(packetData, args.Buffer, packetData.Length);
|
||||||
//args.SetBuffer(packetData, 0, packetData.Length);
|
//args.SetBuffer(packetData, 0, packetData.Length);
|
||||||
@ -200,6 +203,7 @@ namespace DS4Windows
|
|||||||
udpSock.SendToAsync(args);
|
udpSock.SendToAsync(args);
|
||||||
}
|
}
|
||||||
catch (Exception e) { }
|
catch (Exception e) { }
|
||||||
|
_pool.Release();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ProcessIncoming(byte[] localMsg, IPEndPoint clientEP)
|
private void ProcessIncoming(byte[] localMsg, IPEndPoint clientEP)
|
||||||
@ -687,12 +691,14 @@ namespace DS4Windows
|
|||||||
SocketAsyncEventArgs args = argsList[temp];
|
SocketAsyncEventArgs args = argsList[temp];
|
||||||
poolLock.ExitWriteLock();
|
poolLock.ExitWriteLock();
|
||||||
|
|
||||||
|
_pool.Wait();
|
||||||
args.RemoteEndPoint = cl;
|
args.RemoteEndPoint = cl;
|
||||||
Array.Copy(outputData, args.Buffer, outputData.Length);
|
Array.Copy(outputData, args.Buffer, outputData.Length);
|
||||||
try {
|
try {
|
||||||
udpSock.SendToAsync(args);
|
udpSock.SendToAsync(args);
|
||||||
}
|
}
|
||||||
catch (SocketException ex) { }
|
catch (SocketException ex) { }
|
||||||
|
_pool.Release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user