@@ -38,8 +38,8 @@ public NetPacket GetAndClear()
38
38
private readonly double _resendDelay ;
39
39
private readonly bool _ordered ;
40
40
private readonly int _windowSize ;
41
- private readonly AutoResetEvent _pendingPacketsAccess = new AutoResetEvent ( true ) ;
42
- private readonly AutoResetEvent _outgoingAcksAccess = new AutoResetEvent ( true ) ;
41
+ private readonly object _pendingPacketsAccess = new object ( ) ;
42
+ private readonly object _outgoingAcksAccess = new object ( ) ;
43
43
private const int BitsInByte = 8 ;
44
44
45
45
private int _queueIndex ;
@@ -97,7 +97,7 @@ public void ProcessAck(NetPacket packet)
97
97
_peer . DebugWrite ( "[PA]AcksStart: {0}" , ackWindowStart ) ;
98
98
int startByte = NetConstants . SequencedHeaderSize ;
99
99
100
- _pendingPacketsAccess . WaitOne ( ) ;
100
+ Monitor . Enter ( _pendingPacketsAccess ) ;
101
101
for ( int i = 0 ; i < _windowSize ; i ++ )
102
102
{
103
103
int ackSequence = ( ackWindowStart + i ) % NetConstants . MaxSequence ;
@@ -135,7 +135,7 @@ public void ProcessAck(NetPacket packet)
135
135
_peer . DebugWrite ( "[PA]Removing reliableInOrder ack: {0} - false" , ackSequence ) ;
136
136
}
137
137
}
138
- _pendingPacketsAccess . Set ( ) ;
138
+ Monitor . Exit ( _pendingPacketsAccess ) ;
139
139
}
140
140
141
141
public void AddToQueue ( NetPacket packet )
@@ -176,7 +176,7 @@ public bool SendNextPacket()
176
176
//check sending acks
177
177
DateTime currentTime = DateTime . UtcNow ;
178
178
179
- _pendingPacketsAccess . WaitOne ( ) ;
179
+ Monitor . Enter ( _pendingPacketsAccess ) ;
180
180
ProcessQueuedPackets ( ) ;
181
181
182
182
//send
@@ -214,7 +214,7 @@ public bool SendNextPacket()
214
214
sendResult = _peer . SendRawData ( currentPacket . Packet . RawData ) ;
215
215
_peer . DebugWrite ( "[RR]Sended: {0}" , sendResult ) ;
216
216
}
217
- _pendingPacketsAccess . Set ( ) ;
217
+ Monitor . Exit ( _pendingPacketsAccess ) ;
218
218
return sendResult ;
219
219
}
220
220
@@ -235,7 +235,7 @@ public void SendAcks()
235
235
byte [ ] data = acksPacket . RawData ; //window start + acks size
236
236
237
237
//Put window start
238
- _outgoingAcksAccess . WaitOne ( ) ;
238
+ Monitor . Enter ( _outgoingAcksAccess ) ;
239
239
acksPacket . Sequence = ( ushort ) _remoteWindowStart ;
240
240
241
241
//Put acks
@@ -258,7 +258,7 @@ public void SendAcks()
258
258
}
259
259
currentAckIndex = ( currentAckIndex + 1 ) % _windowSize ;
260
260
} while ( currentAckIndex != startAckIndex ) ;
261
- _outgoingAcksAccess . Set ( ) ;
261
+ Monitor . Exit ( _outgoingAcksAccess ) ;
262
262
263
263
_peer . SendRawData ( acksPacket . RawData ) ;
264
264
_peer . Recycle ( acksPacket ) ;
@@ -297,7 +297,7 @@ public void ProcessPacket(NetPacket packet)
297
297
}
298
298
299
299
//If very new - move window
300
- _outgoingAcksAccess . WaitOne ( ) ;
300
+ Monitor . Enter ( _outgoingAcksAccess ) ;
301
301
if ( relate >= _windowSize )
302
302
{
303
303
//New window position
@@ -318,13 +318,13 @@ public void ProcessPacket(NetPacket packet)
318
318
if ( _outgoingAcks [ packet . Sequence % _windowSize ] )
319
319
{
320
320
_peer . DebugWrite ( "[RR]ReliableInOrder duplicate" ) ;
321
- _outgoingAcksAccess . Set ( ) ;
321
+ Monitor . Exit ( _outgoingAcksAccess ) ;
322
322
return ;
323
323
}
324
324
325
325
//save ack
326
326
_outgoingAcks [ packet . Sequence % _windowSize ] = true ;
327
- _outgoingAcksAccess . Set ( ) ;
327
+ Monitor . Exit ( _outgoingAcksAccess ) ;
328
328
329
329
//detailed check
330
330
if ( packet . Sequence == _remoteSequence )
0 commit comments