Skip to content

Commit a563f36

Browse files
committed
- CS104 slave: use ConcurrentQueue to store received ASDUs
1 parent cfe9e66 commit a563f36

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

lib60870/CS104/ClientConnection.cs

+12-5
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
using lib60870;
3333
using lib60870.CS101;
34+
using System.Collections.Concurrent;
3435

3536
namespace lib60870.CS104
3637
{
@@ -78,7 +79,7 @@ private void DebugLog(string msg)
7879

7980
private Server server;
8081

81-
private Queue<ASDU> receivedASDUs = null;
82+
private ConcurrentQueue<ASDU> receivedASDUs = null;
8283
private Thread callbackThread = null;
8384
private bool callbackThreadRunning = false;
8485

@@ -118,8 +119,15 @@ private void ProcessASDUs()
118119

119120
while (callbackThreadRunning) {
120121

121-
while ((receivedASDUs.Count > 0) && (callbackThreadRunning) && (running))
122-
HandleASDU (receivedASDUs.Dequeue ());
122+
while ((receivedASDUs.Count > 0) && (callbackThreadRunning) && (running)) {
123+
124+
ASDU asdu;
125+
126+
if (receivedASDUs.TryDequeue (out asdu)) {
127+
HandleASDU (asdu);
128+
}
129+
130+
}
123131

124132
Thread.Sleep (50);
125133
}
@@ -158,8 +166,7 @@ internal ClientConnection(Socket socket, TlsSecurityInformation tlsSecInfo, APCI
158166
maxSentASDUs = apciParameters.K;
159167
this.sentASDUs = new SentASDU[maxSentASDUs];
160168

161-
//TODO only needed when connection is activated
162-
receivedASDUs = new Queue<ASDU> ();
169+
receivedASDUs = new ConcurrentQueue<ASDU> ();
163170
waitingASDUsHighPrio = new Queue<BufferFrame> ();
164171

165172
socketStream = new NetworkStream (socket);

tests/Test.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ public void TestStepPositionInformation()
239239
}
240240

241241
[Test()]
242-
[Ignore("Ignore to save execution time")]
242+
//[Ignore("Ignore to save execution time")]
243243
public void TestConnectWhileAlreadyConnected()
244244
{
245245
ApplicationLayerParameters parameters = new ApplicationLayerParameters ();
@@ -284,7 +284,7 @@ public void TestConnectWhileAlreadyConnected()
284284

285285

286286
[Test()]
287-
[Ignore("Ignore to save execution time")]
287+
//[Ignore("Ignore to save execution time")]
288288
public void TestConnectSameConnectionMultipleTimes()
289289
{
290290
ApplicationLayerParameters parameters = new ApplicationLayerParameters ();
@@ -946,7 +946,7 @@ public void TestEncodeASDUsWithManyInformationObjectsSequenceOfIO() {
946946
}
947947

948948
[Test()]
949-
[Ignore("Ignore to save execution time")]
949+
//[Ignore("Ignore to save execution time")]
950950
public void TestSendTestFR() {
951951
ApplicationLayerParameters clientParameters = new ApplicationLayerParameters ();
952952
APCIParameters clientApciParamters = new APCIParameters ();
@@ -1002,7 +1002,7 @@ private static bool testSendTestFRTimeoutMasterRawMessageHandler(object param, b
10021002
/// doesn't receive the TESTFR_CON messages
10031003
/// </summary>
10041004
[Test()]
1005-
[Ignore("Ignore to save execution time")]
1005+
//[Ignore("Ignore to save execution time")]
10061006
public void TestSendTestFRTimeoutMaster() {
10071007
ApplicationLayerParameters clientParameters = new ApplicationLayerParameters ();
10081008
APCIParameters clientApciParamters = new APCIParameters ();
@@ -1075,7 +1075,7 @@ private static bool testSendTestFRTimeoutSlaveRawMessageHandler(object param, by
10751075
/// doesn't send the TESTFR_CON messages
10761076
/// </summary>
10771077
[Test()]
1078-
[Ignore("Ignore to save execution time")]
1078+
//[Ignore("Ignore to save execution time")]
10791079
public void TestSendTestFRTimeoutSlave() {
10801080
ApplicationLayerParameters clientParameters = new ApplicationLayerParameters ();
10811081
APCIParameters clientApciParamters = new APCIParameters ();

0 commit comments

Comments
 (0)