OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/test/channel_transport/udp_socket2_win.h" | 11 #include "webrtc/test/channel_transport/udp_socket2_win.h" |
12 | 12 |
13 #include <assert.h> | 13 #include <assert.h> |
14 #include <stdlib.h> | 14 #include <stdlib.h> |
15 #include <winsock2.h> | 15 #include <winsock2.h> |
16 | 16 |
| 17 #include "webrtc/base/atomicops.h" |
17 #include "webrtc/base/format_macros.h" | 18 #include "webrtc/base/format_macros.h" |
18 #include "webrtc/system_wrappers/interface/sleep.h" | 19 #include "webrtc/system_wrappers/interface/sleep.h" |
19 #include "webrtc/test/channel_transport/traffic_control_win.h" | 20 #include "webrtc/test/channel_transport/traffic_control_win.h" |
20 #include "webrtc/test/channel_transport/udp_socket2_manager_win.h" | 21 #include "webrtc/test/channel_transport/udp_socket2_manager_win.h" |
21 | 22 |
22 #pragma warning(disable : 4311) | 23 #pragma warning(disable : 4311) |
23 | 24 |
24 namespace webrtc { | 25 namespace webrtc { |
25 namespace test { | 26 namespace test { |
26 | 27 |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 | 277 |
277 bool UdpSocket2Windows::StartReceiving(uint32_t receiveBuffers) | 278 bool UdpSocket2Windows::StartReceiving(uint32_t receiveBuffers) |
278 { | 279 { |
279 WEBRTC_TRACE(kTraceDebug, kTraceTransport, _id, | 280 WEBRTC_TRACE(kTraceDebug, kTraceTransport, _id, |
280 "UdpSocket2Windows(%d)::StartReceiving(%d)", (int32_t)this, | 281 "UdpSocket2Windows(%d)::StartReceiving(%d)", (int32_t)this, |
281 receiveBuffers); | 282 receiveBuffers); |
282 | 283 |
283 _wantsIncoming = true; | 284 _wantsIncoming = true; |
284 | 285 |
285 int32_t numberOfReceiveBuffersToCreate = | 286 int32_t numberOfReceiveBuffersToCreate = |
286 receiveBuffers - _receiveBuffers.Value(); | 287 receiveBuffers - rtc::AtomicOps::AcquireLoad(&_receiveBuffers); |
287 numberOfReceiveBuffersToCreate = (numberOfReceiveBuffersToCreate < 0) ? | 288 numberOfReceiveBuffersToCreate = (numberOfReceiveBuffersToCreate < 0) ? |
288 0 : numberOfReceiveBuffersToCreate; | 289 0 : numberOfReceiveBuffersToCreate; |
289 | 290 |
290 int32_t error = 0; | 291 int32_t error = 0; |
291 for(int32_t i = 0; | 292 for(int32_t i = 0; |
292 i < numberOfReceiveBuffersToCreate; | 293 i < numberOfReceiveBuffersToCreate; |
293 i++) | 294 i++) |
294 { | 295 { |
295 if(PostRecv()) | 296 if(PostRecv()) |
296 { | 297 { |
297 WEBRTC_TRACE(kTraceError, kTraceTransport, _id, | 298 WEBRTC_TRACE(kTraceError, kTraceTransport, _id, |
298 "UdpSocket2Windows::StartReceiving() i=%d", i); | 299 "UdpSocket2Windows::StartReceiving() i=%d", i); |
299 error = -1; | 300 error = -1; |
300 break; | 301 break; |
301 } | 302 } |
302 ++_receiveBuffers; | 303 rtc::AtomicOps::Increment(&_receiveBuffers); |
303 } | 304 } |
304 if(error == -1) | 305 if(error == -1) |
305 { | 306 { |
306 return false; | 307 return false; |
307 } | 308 } |
308 | 309 |
309 WEBRTC_TRACE(kTraceDebug, kTraceTransport, _id, | 310 WEBRTC_TRACE(kTraceDebug, kTraceTransport, _id, |
310 "Socket receiving using:%d number of buffers", | 311 "Socket receiving using:%d number of buffers", |
311 _receiveBuffers.Value()); | 312 rtc::AtomicOps::AcquireLoad(&_receiveBuffers)); |
312 return true; | 313 return true; |
313 } | 314 } |
314 | 315 |
315 bool UdpSocket2Windows::StopReceiving() | 316 bool UdpSocket2Windows::StopReceiving() |
316 { | 317 { |
317 WEBRTC_TRACE(kTraceDebug, kTraceTransport, _id, | 318 WEBRTC_TRACE(kTraceDebug, kTraceTransport, _id, |
318 "UdpSocket2Windows::StopReceiving()"); | 319 "UdpSocket2Windows::StopReceiving()"); |
319 _wantsIncoming = false; | 320 _wantsIncoming = false; |
320 return true; | 321 return true; |
321 } | 322 } |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 pIOContext ? (int32_t)pIOContext->ioOperation : -1); | 467 pIOContext ? (int32_t)pIOContext->ioOperation : -1); |
467 } else { | 468 } else { |
468 WEBRTC_TRACE( | 469 WEBRTC_TRACE( |
469 kTraceDebug, | 470 kTraceDebug, |
470 kTraceTransport, | 471 kTraceTransport, |
471 _id, | 472 _id, |
472 "UdpSocket2Windows::IOCompleted() Operation aborted"); | 473 "UdpSocket2Windows::IOCompleted() Operation aborted"); |
473 } | 474 } |
474 if(pIOContext) | 475 if(pIOContext) |
475 { | 476 { |
476 int32_t remainingReceiveBuffers = --_receiveBuffers; | 477 int32_t remainingReceiveBuffers = |
| 478 rtc::AtomicOps::Decrement(&_receiveBuffers); |
477 if(remainingReceiveBuffers < 0) | 479 if(remainingReceiveBuffers < 0) |
478 { | 480 { |
479 assert(false); | 481 assert(false); |
480 } | 482 } |
481 int32_t err = _mgr->PushIoContext(pIOContext); | 483 int32_t err = _mgr->PushIoContext(pIOContext); |
482 if(err) | 484 if(err) |
483 { | 485 { |
484 WEBRTC_TRACE( | 486 WEBRTC_TRACE( |
485 kTraceError, | 487 kTraceError, |
486 kTraceTransport, | 488 kTraceTransport, |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
621 postingSucessfull = true; | 623 postingSucessfull = true; |
622 break; | 624 break; |
623 } | 625 } |
624 } | 626 } |
625 ReleaseSocket(); | 627 ReleaseSocket(); |
626 | 628 |
627 if(postingSucessfull) | 629 if(postingSucessfull) |
628 { | 630 { |
629 return 0; | 631 return 0; |
630 } | 632 } |
631 int32_t remainingReceiveBuffers = --_receiveBuffers; | 633 int32_t remainingReceiveBuffers = |
| 634 rtc::AtomicOps::Decrement(&_receiveBuffers); |
632 if(remainingReceiveBuffers < 0) | 635 if(remainingReceiveBuffers < 0) |
633 { | 636 { |
634 assert(false); | 637 assert(false); |
635 } | 638 } |
636 int32_t error = _mgr->PushIoContext(pIoContext); | 639 int32_t error = _mgr->PushIoContext(pIoContext); |
637 if(error) | 640 if(error) |
638 { | 641 { |
639 WEBRTC_TRACE( | 642 WEBRTC_TRACE( |
640 kTraceError, | 643 kTraceError, |
641 kTraceTransport, | 644 kTraceTransport, |
(...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1251 f->Latency = QOS_NOT_SPECIFIED; | 1254 f->Latency = QOS_NOT_SPECIFIED; |
1252 f->MaxSduSize = QOS_NOT_SPECIFIED; | 1255 f->MaxSduSize = QOS_NOT_SPECIFIED; |
1253 f->MinimumPolicedSize = QOS_NOT_SPECIFIED; | 1256 f->MinimumPolicedSize = QOS_NOT_SPECIFIED; |
1254 return 0; | 1257 return 0; |
1255 } | 1258 } |
1256 | 1259 |
1257 bool UdpSocket2Windows::NewOutstandingCall() | 1260 bool UdpSocket2Windows::NewOutstandingCall() |
1258 { | 1261 { |
1259 assert(!_outstandingCallsDisabled); | 1262 assert(!_outstandingCallsDisabled); |
1260 | 1263 |
1261 ++_outstandingCalls; | 1264 rtc::AtomicOps::Increment(&_outstandingCalls); |
1262 return true; | 1265 return true; |
1263 } | 1266 } |
1264 | 1267 |
1265 void UdpSocket2Windows::OutstandingCallCompleted() | 1268 void UdpSocket2Windows::OutstandingCallCompleted() |
1266 { | 1269 { |
1267 _ptrDestRWLock->AcquireLockShared(); | 1270 _ptrDestRWLock->AcquireLockShared(); |
1268 ++_outstandingCallComplete; | 1271 rtc::AtomicOps::Increment(&_outstandingCallComplete); |
1269 if((--_outstandingCalls == 0) && _outstandingCallsDisabled) | 1272 if ((rtc::AtomicOps::Decrement(&_outstandingCalls) == 0) && |
1270 { | 1273 _outstandingCallsDisabled) { |
1271 // When there are no outstanding calls and new outstanding calls are | 1274 // When there are no outstanding calls and new outstanding calls are |
1272 // disabled it is time to terminate. | 1275 // disabled it is time to terminate. |
1273 _terminate = true; | 1276 _terminate = true; |
1274 } | 1277 } |
1275 _ptrDestRWLock->ReleaseLockShared(); | 1278 _ptrDestRWLock->ReleaseLockShared(); |
1276 | 1279 |
1277 if((--_outstandingCallComplete == 0) && | 1280 if ((rtc::AtomicOps::Decrement(&_outstandingCallComplete) == 0) && |
1278 (_terminate)) | 1281 (_terminate)) { |
1279 { | |
1280 // Only one thread will enter here. The thread with the last outstanding | 1282 // Only one thread will enter here. The thread with the last outstanding |
1281 // call. | 1283 // call. |
1282 CriticalSectionScoped cs(_ptrDeleteCrit); | 1284 CriticalSectionScoped cs(_ptrDeleteCrit); |
1283 _safeTodelete = true; | 1285 _safeTodelete = true; |
1284 _ptrDeleteCond->Wake(); | 1286 _ptrDeleteCond->Wake(); |
1285 } | 1287 } |
1286 } | 1288 } |
1287 | 1289 |
1288 void UdpSocket2Windows::DisableNewOutstandingCalls() | 1290 void UdpSocket2Windows::DisableNewOutstandingCalls() |
1289 { | 1291 { |
1290 _ptrDestRWLock->AcquireLockExclusive(); | 1292 _ptrDestRWLock->AcquireLockExclusive(); |
1291 if(_outstandingCallsDisabled) | 1293 if(_outstandingCallsDisabled) |
1292 { | 1294 { |
1293 // Outstandning calls are already disabled. | 1295 // Outstandning calls are already disabled. |
1294 _ptrDestRWLock->ReleaseLockExclusive(); | 1296 _ptrDestRWLock->ReleaseLockExclusive(); |
1295 return; | 1297 return; |
1296 } | 1298 } |
1297 _outstandingCallsDisabled = true; | 1299 _outstandingCallsDisabled = true; |
1298 const bool noOutstandingCalls = (_outstandingCalls.Value() == 0); | 1300 const bool noOutstandingCalls = |
| 1301 (rtc::AtomicOps::AcquireLoad(&_outstandingCalls) == 0); |
1299 _ptrDestRWLock->ReleaseLockExclusive(); | 1302 _ptrDestRWLock->ReleaseLockExclusive(); |
1300 | 1303 |
1301 RemoveSocketFromManager(); | 1304 RemoveSocketFromManager(); |
1302 | 1305 |
1303 if(noOutstandingCalls) | 1306 if(noOutstandingCalls) |
1304 { | 1307 { |
1305 CriticalSectionScoped cs(_ptrDeleteCrit); | 1308 CriticalSectionScoped cs(_ptrDeleteCrit); |
1306 _safeTodelete = true; | 1309 _safeTodelete = true; |
1307 _ptrDeleteCond->Wake(); | 1310 _ptrDeleteCond->Wake(); |
1308 } | 1311 } |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1365 "UdpSocket2Windows(%d)::InvalidateSocket() WSAerror: %d", | 1368 "UdpSocket2Windows(%d)::InvalidateSocket() WSAerror: %d", |
1366 (int32_t)this, WSAGetLastError()); | 1369 (int32_t)this, WSAGetLastError()); |
1367 } | 1370 } |
1368 _socket = INVALID_SOCKET; | 1371 _socket = INVALID_SOCKET; |
1369 _ptrSocketRWLock->ReleaseLockExclusive(); | 1372 _ptrSocketRWLock->ReleaseLockExclusive(); |
1370 return true; | 1373 return true; |
1371 } | 1374 } |
1372 | 1375 |
1373 } // namespace test | 1376 } // namespace test |
1374 } // namespace webrtc | 1377 } // namespace webrtc |
OLD | NEW |