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 |
(...skipping 23 matching lines...) Expand all Loading... |
34 typedef const QOS_DESTADDR* LPCQOS_DESTADDR; | 34 typedef const QOS_DESTADDR* LPCQOS_DESTADDR; |
35 | 35 |
36 // TODO (patrikw): seems to be defined in ws2ipdef.h as 3. How come it's | 36 // TODO (patrikw): seems to be defined in ws2ipdef.h as 3. How come it's |
37 // redefined here (as a different value)? | 37 // redefined here (as a different value)? |
38 #define IP_TOS 8 | 38 #define IP_TOS 8 |
39 | 39 |
40 #define QOS_GENERAL_ID_BASE 2000 | 40 #define QOS_GENERAL_ID_BASE 2000 |
41 #define QOS_OBJECT_DESTADDR (0x00000004 + QOS_GENERAL_ID_BASE) | 41 #define QOS_OBJECT_DESTADDR (0x00000004 + QOS_GENERAL_ID_BASE) |
42 | 42 |
43 UdpSocket2Windows::UdpSocket2Windows(const int32_t id, | 43 UdpSocket2Windows::UdpSocket2Windows(const int32_t id, |
44 UdpSocketManager* mgr, bool ipV6Enable, | 44 UdpSocketManager* mgr, |
| 45 bool ipV6Enable, |
45 bool disableGQOS) | 46 bool disableGQOS) |
46 : _id(id), | 47 : _id(id), |
47 _qos(true), | 48 _qos(true), |
48 _iProtocol(0), | 49 _iProtocol(0), |
49 _outstandingCalls(0), | 50 _outstandingCalls(0), |
50 _outstandingCallComplete(0), | 51 _outstandingCallComplete(0), |
51 _terminate(false), | 52 _terminate(false), |
52 _addedToMgr(false), | 53 _addedToMgr(false), |
53 delete_event_(true, false), | 54 delete_event_(true, false), |
54 _outstandingCallsDisabled(false), | 55 _outstandingCallsDisabled(false), |
55 _clientHandle(NULL), | 56 _clientHandle(nullptr), |
56 _flowHandle(NULL), | 57 _flowHandle(nullptr), |
57 _filterHandle(NULL), | 58 _filterHandle(nullptr), |
58 _flow(NULL), | 59 _flow(nullptr), |
59 _gtc(NULL), | 60 _gtc(nullptr), |
60 _pcp(-2), | 61 _pcp(-2), |
61 _receiveBuffers(0) | 62 _receiveBuffers(0) { |
62 { | 63 WEBRTC_TRACE(kTraceMemory, kTraceTransport, _id, |
63 WEBRTC_TRACE(kTraceMemory, kTraceTransport, _id, | 64 "UdpSocket2Windows::UdpSocket2Windows()"); |
64 "UdpSocket2Windows::UdpSocket2Windows()"); | |
65 | 65 |
66 _wantsIncoming = false; | 66 _wantsIncoming = false; |
67 _mgr = static_cast<UdpSocket2ManagerWindows *>(mgr); | 67 _mgr = static_cast<UdpSocket2ManagerWindows*>(mgr); |
68 | 68 |
69 _obj = NULL; | 69 _obj = nullptr; |
70 _incomingCb = NULL; | 70 _incomingCb = nullptr; |
71 _socket = INVALID_SOCKET; | 71 _socket = INVALID_SOCKET; |
72 _ptrCbRWLock = RWLockWrapper::CreateRWLock(); | 72 _ptrCbRWLock = RWLockWrapper::CreateRWLock(); |
73 _ptrDestRWLock = RWLockWrapper::CreateRWLock(); | 73 _ptrDestRWLock = RWLockWrapper::CreateRWLock(); |
74 _ptrSocketRWLock = RWLockWrapper::CreateRWLock(); | 74 _ptrSocketRWLock = RWLockWrapper::CreateRWLock(); |
75 | 75 |
76 // Check if QoS is supported. | 76 // Check if QoS is supported. |
77 BOOL bProtocolFound = FALSE; | 77 BOOL bProtocolFound = FALSE; |
78 WSAPROTOCOL_INFO *lpProtocolBuf = NULL; | 78 WSAPROTOCOL_INFO* lpProtocolBuf = nullptr; |
79 WSAPROTOCOL_INFO pProtocolInfo; | 79 WSAPROTOCOL_INFO pProtocolInfo; |
80 | 80 |
81 if(!disableGQOS) | 81 if (!disableGQOS) { |
82 { | 82 DWORD dwBufLen = 0; |
83 DWORD dwBufLen = 0; | 83 // Set dwBufLen to the size needed to retreive all the requested |
84 // Set dwBufLen to the size needed to retreive all the requested | 84 // information from WSAEnumProtocols. |
85 // information from WSAEnumProtocols. | 85 int32_t nRet = WSAEnumProtocols(nullptr, lpProtocolBuf, &dwBufLen); |
86 int32_t nRet = WSAEnumProtocols(NULL, lpProtocolBuf, &dwBufLen); | 86 lpProtocolBuf = (WSAPROTOCOL_INFO*)malloc(dwBufLen); |
87 lpProtocolBuf = (WSAPROTOCOL_INFO*)malloc(dwBufLen); | 87 nRet = WSAEnumProtocols(nullptr, lpProtocolBuf, &dwBufLen); |
88 nRet = WSAEnumProtocols(NULL, lpProtocolBuf, &dwBufLen); | |
89 | 88 |
90 if (ipV6Enable) | 89 if (ipV6Enable) { |
91 { | 90 _iProtocol = AF_INET6; |
92 _iProtocol=AF_INET6; | 91 } else { |
93 } else { | 92 _iProtocol = AF_INET; |
94 _iProtocol=AF_INET; | |
95 } | |
96 | |
97 for (int32_t i=0; i<nRet; i++) | |
98 { | |
99 if (_iProtocol == lpProtocolBuf[i].iAddressFamily && | |
100 IPPROTO_UDP == lpProtocolBuf[i].iProtocol) | |
101 { | |
102 if ((XP1_QOS_SUPPORTED == | |
103 (XP1_QOS_SUPPORTED & lpProtocolBuf[i].dwServiceFlags1))) | |
104 { | |
105 pProtocolInfo = lpProtocolBuf[i]; | |
106 bProtocolFound = TRUE; | |
107 break; | |
108 } | |
109 } | |
110 } | |
111 } | 93 } |
112 | 94 |
113 if(!bProtocolFound) | 95 for (int32_t i = 0; i < nRet; i++) { |
114 { | 96 if (_iProtocol == lpProtocolBuf[i].iAddressFamily && |
115 free(lpProtocolBuf); | 97 IPPROTO_UDP == lpProtocolBuf[i].iProtocol) { |
116 _qos=false; | 98 if ((XP1_QOS_SUPPORTED == |
117 WEBRTC_TRACE( | 99 (XP1_QOS_SUPPORTED & lpProtocolBuf[i].dwServiceFlags1))) { |
118 kTraceError, | 100 pProtocolInfo = lpProtocolBuf[i]; |
119 kTraceTransport, | 101 bProtocolFound = TRUE; |
120 _id, | 102 break; |
121 "UdpSocket2Windows::UdpSocket2Windows(), SOCKET_ERROR_NO_QOS,\ | 103 } |
| 104 } |
| 105 } |
| 106 } |
| 107 |
| 108 if (!bProtocolFound) { |
| 109 free(lpProtocolBuf); |
| 110 _qos = false; |
| 111 WEBRTC_TRACE(kTraceError, kTraceTransport, _id, |
| 112 "UdpSocket2Windows::UdpSocket2Windows(), SOCKET_ERROR_NO_QOS,\ |
122 !bProtocolFound"); | 113 !bProtocolFound"); |
| 114 } else { |
| 115 _socket = |
| 116 WSASocket(FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO, |
| 117 &pProtocolInfo, 0, WSA_FLAG_OVERLAPPED); |
| 118 free(lpProtocolBuf); |
| 119 |
| 120 if (_socket != INVALID_SOCKET) { |
| 121 return; |
123 } else { | 122 } else { |
| 123 _qos = false; |
| 124 WEBRTC_TRACE( |
| 125 kTraceError, kTraceTransport, _id, |
| 126 "UdpSocket2Windows::UdpSocket2Windows(), SOCKET_ERROR_NO_QOS"); |
| 127 } |
| 128 } |
| 129 // QoS not supported. |
| 130 if (ipV6Enable) { |
| 131 _socket = |
| 132 WSASocket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP, 0, 0, WSA_FLAG_OVERLAPPED); |
| 133 } else { |
| 134 _socket = |
| 135 WSASocket(AF_INET, SOCK_DGRAM, IPPROTO_UDP, 0, 0, WSA_FLAG_OVERLAPPED); |
| 136 } |
| 137 if (_socket == INVALID_SOCKET) { |
| 138 WEBRTC_TRACE(kTraceError, kTraceTransport, _id, |
| 139 "UdpSocket2Windows::UdpSocket2Windows(), INVALID_SOCKET,\ |
| 140 WSAerror: %d", |
| 141 WSAGetLastError()); |
| 142 } |
124 | 143 |
125 _socket = WSASocket(FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO, | 144 // Disable send buffering on the socket to improve CPU usage. |
126 FROM_PROTOCOL_INFO,&pProtocolInfo, 0, | 145 // This is done by setting SO_SNDBUF to 0. |
127 WSA_FLAG_OVERLAPPED); | 146 int32_t nZero = 0; |
128 free(lpProtocolBuf); | 147 int32_t nRet = |
129 | 148 setsockopt(_socket, SOL_SOCKET, SO_SNDBUF, (char*)&nZero, sizeof(nZero)); |
130 if (_socket != INVALID_SOCKET) | 149 if (nRet == SOCKET_ERROR) { |
131 { | 150 WEBRTC_TRACE(kTraceError, kTraceTransport, _id, |
132 return; | 151 "UdpSocket2Windows::UdpSocket2Windows(), SOCKET_ERROR,\ |
133 } else { | |
134 _qos = false; | |
135 WEBRTC_TRACE( | |
136 kTraceError, | |
137 kTraceTransport, | |
138 _id, | |
139 "UdpSocket2Windows::UdpSocket2Windows(), SOCKET_ERROR_NO_QOS"); | |
140 } | |
141 } | |
142 // QoS not supported. | |
143 if(ipV6Enable) | |
144 { | |
145 _socket = WSASocket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP, 0 , 0, | |
146 WSA_FLAG_OVERLAPPED); | |
147 }else | |
148 { | |
149 _socket = WSASocket(AF_INET, SOCK_DGRAM, IPPROTO_UDP, 0 , 0, | |
150 WSA_FLAG_OVERLAPPED); | |
151 } | |
152 if (_socket == INVALID_SOCKET) | |
153 { | |
154 WEBRTC_TRACE( | |
155 kTraceError, | |
156 kTraceTransport, | |
157 _id, | |
158 "UdpSocket2Windows::UdpSocket2Windows(), INVALID_SOCKET,\ | |
159 WSAerror: %d", | 152 WSAerror: %d", |
160 WSAGetLastError()); | 153 WSAGetLastError()); |
161 } | 154 } |
162 | |
163 // Disable send buffering on the socket to improve CPU usage. | |
164 // This is done by setting SO_SNDBUF to 0. | |
165 int32_t nZero = 0; | |
166 int32_t nRet = setsockopt(_socket, SOL_SOCKET, SO_SNDBUF, | |
167 (char*)&nZero, sizeof(nZero)); | |
168 if( nRet == SOCKET_ERROR ) | |
169 { | |
170 WEBRTC_TRACE( | |
171 kTraceError, | |
172 kTraceTransport, | |
173 _id, | |
174 "UdpSocket2Windows::UdpSocket2Windows(), SOCKET_ERROR,\ | |
175 WSAerror: %d", | |
176 WSAGetLastError()); | |
177 } | |
178 } | 155 } |
179 | 156 |
180 UdpSocket2Windows::~UdpSocket2Windows() | 157 UdpSocket2Windows::~UdpSocket2Windows() |
181 { | 158 { |
182 WEBRTC_TRACE(kTraceMemory, kTraceTransport, _id, | 159 WEBRTC_TRACE(kTraceMemory, kTraceTransport, _id, |
183 "UdpSocket2Windows::~UdpSocket2Windows()"); | 160 "UdpSocket2Windows::~UdpSocket2Windows()"); |
184 | 161 |
185 delete_event_.Wait(rtc::Event::kForever); | 162 delete_event_.Wait(rtc::Event::kForever); |
186 | 163 |
187 | 164 |
188 delete _ptrCbRWLock; | 165 delete _ptrCbRWLock; |
189 delete _ptrDestRWLock; | 166 delete _ptrDestRWLock; |
190 delete _ptrSocketRWLock; | 167 delete _ptrSocketRWLock; |
191 | 168 |
192 if (_flow) | 169 if (_flow) |
193 { | 170 { |
194 free(_flow); | 171 free(_flow); |
195 _flow = NULL; | 172 _flow = nullptr; |
196 } | 173 } |
197 | 174 |
198 if (_gtc) | 175 if (_gtc) |
199 { | 176 { |
200 if(_filterHandle) | 177 if(_filterHandle) |
201 { | 178 { |
202 _gtc->TcDeleteFilter(_filterHandle); | 179 _gtc->TcDeleteFilter(_filterHandle); |
203 } | 180 } |
204 if(_flowHandle) | 181 if(_flowHandle) |
205 { | 182 { |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 } | 392 } |
416 | 393 |
417 // Roll back. | 394 // Roll back. |
418 OutstandingCallCompleted(); | 395 OutstandingCallCompleted(); |
419 return -1; | 396 return -1; |
420 } | 397 } |
421 | 398 |
422 void UdpSocket2Windows::IOCompleted(PerIoContext* pIOContext, | 399 void UdpSocket2Windows::IOCompleted(PerIoContext* pIOContext, |
423 uint32_t ioSize, uint32_t error) | 400 uint32_t ioSize, uint32_t error) |
424 { | 401 { |
425 if(pIOContext == NULL || error == ERROR_OPERATION_ABORTED) | 402 if (pIOContext == nullptr || error == ERROR_OPERATION_ABORTED) { |
426 { | 403 if ((pIOContext != nullptr) && !pIOContext->ioInitiatedByPlatformThread && |
427 if ((pIOContext != NULL) && | 404 (error == ERROR_OPERATION_ABORTED) && |
428 !pIOContext->ioInitiatedByPlatformThread && | 405 (pIOContext->ioOperation == OP_READ) && _outstandingCallsDisabled) { |
429 (error == ERROR_OPERATION_ABORTED) && | 406 // !pIOContext->initiatedIOByPlatformThread indicate that the I/O |
430 (pIOContext->ioOperation == OP_READ) && | 407 // was not initiated by a PlatformThread thread. |
431 _outstandingCallsDisabled) | 408 // This may happen if the thread that initiated receiving (e.g. |
432 { | 409 // by calling StartListen())) is deleted before any packets have |
433 // !pIOContext->initiatedIOByPlatformThread indicate that the I/O | 410 // been received. |
434 // was not initiated by a PlatformThread thread. | 411 // In this case there is no packet in the PerIoContext. Re-use it |
435 // This may happen if the thread that initiated receiving (e.g. | 412 // to post a new PostRecv(..). |
436 // by calling StartListen())) is deleted before any packets have | 413 // Note 1: the PerIoContext will henceforth be posted by a thread |
437 // been received. | 414 // that is controlled by the socket implementation. |
438 // In this case there is no packet in the PerIoContext. Re-use it | 415 // Note 2: This is more likely to happen to RTCP packets as |
439 // to post a new PostRecv(..). | 416 // they are less frequent than RTP packets. |
440 // Note 1: the PerIoContext will henceforth be posted by a thread | 417 // Note 3: _outstandingCallsDisabled being false indicates |
441 // that is controlled by the socket implementation. | 418 // that the socket isn't being shut down. |
442 // Note 2: This is more likely to happen to RTCP packets as | 419 // Note 4: This should only happen buffers set to receive packets |
443 // they are less frequent than RTP packets. | 420 // (OP_READ). |
444 // Note 3: _outstandingCallsDisabled being false indicates | 421 } else { |
445 // that the socket isn't being shut down. | 422 if (pIOContext == nullptr) { |
446 // Note 4: This should only happen buffers set to receive packets | 423 WEBRTC_TRACE(kTraceError, kTraceTransport, _id, |
447 // (OP_READ). | 424 "UdpSocket2Windows::IOCompleted(%d,%d,%d), %d", |
448 } else { | 425 (int32_t)pIOContext, ioSize, error, |
449 if(pIOContext == NULL) | 426 pIOContext ? (int32_t)pIOContext->ioOperation : -1); |
450 { | 427 } else { |
451 WEBRTC_TRACE( | 428 WEBRTC_TRACE(kTraceDebug, kTraceTransport, _id, |
452 kTraceError, | 429 "UdpSocket2Windows::IOCompleted() Operation aborted"); |
453 kTraceTransport, | 430 } |
454 _id, | 431 if (pIOContext) { |
455 "UdpSocket2Windows::IOCompleted(%d,%d,%d), %d", | 432 int32_t remainingReceiveBuffers = --_receiveBuffers; |
456 (int32_t)pIOContext, | 433 if (remainingReceiveBuffers < 0) { |
457 ioSize, | 434 assert(false); |
458 error, | 435 } |
459 pIOContext ? (int32_t)pIOContext->ioOperation : -1); | 436 int32_t err = _mgr->PushIoContext(pIOContext); |
460 } else { | 437 if (err) { |
461 WEBRTC_TRACE( | 438 WEBRTC_TRACE(kTraceError, kTraceTransport, _id, |
462 kTraceDebug, | 439 "UdpSocket2Windows::IOCompleted(), err = %d, when\ |
463 kTraceTransport, | |
464 _id, | |
465 "UdpSocket2Windows::IOCompleted() Operation aborted"); | |
466 } | |
467 if(pIOContext) | |
468 { | |
469 int32_t remainingReceiveBuffers = --_receiveBuffers; | |
470 if(remainingReceiveBuffers < 0) | |
471 { | |
472 assert(false); | |
473 } | |
474 int32_t err = _mgr->PushIoContext(pIOContext); | |
475 if(err) | |
476 { | |
477 WEBRTC_TRACE( | |
478 kTraceError, | |
479 kTraceTransport, | |
480 _id, | |
481 "UdpSocket2Windows::IOCompleted(), err = %d, when\ | |
482 pushing ioContext after error", | 440 pushing ioContext after error", |
483 err); | 441 err); |
484 } | |
485 } | |
486 OutstandingCallCompleted(); | |
487 return; | |
488 } | 442 } |
489 } // if (pIOContext == NULL || error == ERROR_OPERATION_ABORTED) | 443 } |
| 444 OutstandingCallCompleted(); |
| 445 return; |
| 446 } |
| 447 } // if (pIOContext == nullptr || error == ERROR_OPERATION_ABORTED) |
490 | 448 |
491 if(pIOContext->ioOperation == OP_WRITE) | 449 if (pIOContext->ioOperation == OP_WRITE) { |
492 { | 450 _mgr->PushIoContext(pIOContext); |
493 _mgr->PushIoContext(pIOContext); | |
494 } | 451 } |
495 else if(pIOContext->ioOperation == OP_READ) | 452 else if(pIOContext->ioOperation == OP_READ) |
496 { | 453 { |
497 if(!error && ioSize != 0) | 454 if(!error && ioSize != 0) |
498 { | 455 { |
499 _ptrCbRWLock->AcquireLockShared(); | 456 _ptrCbRWLock->AcquireLockShared(); |
500 if(_wantsIncoming && _incomingCb) | 457 if(_wantsIncoming && _incomingCb) |
501 { | 458 { |
502 _incomingCb(_obj, | 459 _incomingCb(_obj, |
503 reinterpret_cast<const int8_t*>( | 460 reinterpret_cast<const int8_t*>( |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
727 Qos.ReceivingFlowspec.TokenRate = QOS_NOT_SPECIFIED; | 684 Qos.ReceivingFlowspec.TokenRate = QOS_NOT_SPECIFIED; |
728 Qos.ReceivingFlowspec.TokenBucketSize = QOS_NOT_SPECIFIED; | 685 Qos.ReceivingFlowspec.TokenBucketSize = QOS_NOT_SPECIFIED; |
729 Qos.ReceivingFlowspec.PeakBandwidth = QOS_NOT_SPECIFIED; | 686 Qos.ReceivingFlowspec.PeakBandwidth = QOS_NOT_SPECIFIED; |
730 Qos.ReceivingFlowspec.Latency = QOS_NOT_SPECIFIED; | 687 Qos.ReceivingFlowspec.Latency = QOS_NOT_SPECIFIED; |
731 Qos.ReceivingFlowspec.DelayVariation = QOS_NOT_SPECIFIED; | 688 Qos.ReceivingFlowspec.DelayVariation = QOS_NOT_SPECIFIED; |
732 Qos.ReceivingFlowspec.MinimumPolicedSize = QOS_NOT_SPECIFIED; | 689 Qos.ReceivingFlowspec.MinimumPolicedSize = QOS_NOT_SPECIFIED; |
733 Qos.ReceivingFlowspec.MaxSduSize = QOS_NOT_SPECIFIED; | 690 Qos.ReceivingFlowspec.MaxSduSize = QOS_NOT_SPECIFIED; |
734 | 691 |
735 Qos.ProviderSpecific.len = 0; | 692 Qos.ProviderSpecific.len = 0; |
736 | 693 |
737 Qos.ProviderSpecific.buf = NULL; | 694 Qos.ProviderSpecific.buf = nullptr; |
738 | 695 |
739 ZeroMemory((int8_t *)&QosDestaddr, sizeof(QosDestaddr)); | 696 ZeroMemory((int8_t *)&QosDestaddr, sizeof(QosDestaddr)); |
740 | 697 |
741 OSVERSIONINFOEX osvie; | 698 OSVERSIONINFOEX osvie; |
742 osvie.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); | 699 osvie.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); |
743 GetVersionEx((LPOSVERSIONINFO)&osvie); | 700 GetVersionEx((LPOSVERSIONINFO)&osvie); |
744 | 701 |
745 // Operating system Version number dwMajorVersion dwMinorVersion | 702 // Operating system Version number dwMajorVersion dwMinorVersion |
746 // Windows 7 6.1 6 1 | 703 // Windows 7 6.1 6 1 |
747 // Windows Server 2008 R2 6.1 6 1 | 704 // Windows Server 2008 R2 6.1 6 1 |
(...skipping 29 matching lines...) Expand all Loading... |
777 | 734 |
778 Qos.ProviderSpecific.len = QosDestaddr.ObjectHdr.ObjectLength; | 735 Qos.ProviderSpecific.len = QosDestaddr.ObjectHdr.ObjectLength; |
779 Qos.ProviderSpecific.buf = (char*)&QosDestaddr; | 736 Qos.ProviderSpecific.buf = (char*)&QosDestaddr; |
780 } | 737 } |
781 | 738 |
782 if(!AquireSocket()) { | 739 if(!AquireSocket()) { |
783 return false; | 740 return false; |
784 } | 741 } |
785 // To set QoS with SIO_SET_QOS the socket must be locally bound first | 742 // To set QoS with SIO_SET_QOS the socket must be locally bound first |
786 // or the call will fail with error code 10022. | 743 // or the call will fail with error code 10022. |
787 int32_t result = WSAIoctl(GetFd(), SIO_SET_QOS, &Qos, sizeof(QOS), | 744 int32_t result = WSAIoctl(GetFd(), SIO_SET_QOS, &Qos, sizeof(QOS), nullptr, |
788 NULL, 0, &BytesRet, NULL,NULL); | 745 0, &BytesRet, nullptr, nullptr); |
789 ReleaseSocket(); | 746 ReleaseSocket(); |
790 if (result == SOCKET_ERROR) | 747 if (result == SOCKET_ERROR) |
791 { | 748 { |
792 WEBRTC_TRACE(kTraceError, kTraceTransport, _id, | 749 WEBRTC_TRACE(kTraceError, kTraceTransport, _id, |
793 "UdpSocket2Windows::SetQos() WSAerror : %d", | 750 "UdpSocket2Windows::SetQos() WSAerror : %d", |
794 WSAGetLastError()); | 751 WSAGetLastError()); |
795 return false; | 752 return false; |
796 } | 753 } |
797 return true; | 754 return true; |
798 } | 755 } |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
862 { | 819 { |
863 _gtc = TrafficControlWindows::GetInstance(_id); | 820 _gtc = TrafficControlWindows::GetInstance(_id); |
864 } | 821 } |
865 if (!_gtc) | 822 if (!_gtc) |
866 { | 823 { |
867 return -1; | 824 return -1; |
868 } | 825 } |
869 if(_filterHandle) | 826 if(_filterHandle) |
870 { | 827 { |
871 _gtc->TcDeleteFilter(_filterHandle); | 828 _gtc->TcDeleteFilter(_filterHandle); |
872 _filterHandle = NULL; | 829 _filterHandle = nullptr; |
873 } | 830 } |
874 if(_flowHandle) | 831 if(_flowHandle) |
875 { | 832 { |
876 _gtc->TcDeleteFlow(_flowHandle); | 833 _gtc->TcDeleteFlow(_flowHandle); |
877 _flowHandle = NULL; | 834 _flowHandle = nullptr; |
878 } | 835 } |
879 if(_clientHandle) | 836 if(_clientHandle) |
880 { | 837 { |
881 _gtc->TcDeregisterClient(_clientHandle); | 838 _gtc->TcDeregisterClient(_clientHandle); |
882 _clientHandle = NULL; | 839 _clientHandle = nullptr; |
883 } | 840 } |
884 if ((0 == dscp) && (-2 == _pcp) && (-1 == pcp)) | 841 if ((0 == dscp) && (-2 == _pcp) && (-1 == pcp)) |
885 { | 842 { |
886 // TODO (pwestin): why is this not done before deleting old filter and | 843 // TODO (pwestin): why is this not done before deleting old filter and |
887 // flow? This scenario should probably be documented in | 844 // flow? This scenario should probably be documented in |
888 // the function declaration. | 845 // the function declaration. |
889 return 0; | 846 return 0; |
890 } | 847 } |
891 | 848 |
892 TCI_CLIENT_FUNC_LIST QoSFunctions; | 849 TCI_CLIENT_FUNC_LIST QoSFunctions; |
893 QoSFunctions.ClAddFlowCompleteHandler = NULL; | 850 QoSFunctions.ClAddFlowCompleteHandler = nullptr; |
894 QoSFunctions.ClDeleteFlowCompleteHandler = NULL; | 851 QoSFunctions.ClDeleteFlowCompleteHandler = nullptr; |
895 QoSFunctions.ClModifyFlowCompleteHandler = NULL; | 852 QoSFunctions.ClModifyFlowCompleteHandler = nullptr; |
896 QoSFunctions.ClNotifyHandler = (TCI_NOTIFY_HANDLER)MyClNotifyHandler; | 853 QoSFunctions.ClNotifyHandler = (TCI_NOTIFY_HANDLER)MyClNotifyHandler; |
897 // Register the client with Traffic control interface. | 854 // Register the client with Traffic control interface. |
898 HANDLE ClientHandle; | 855 HANDLE ClientHandle; |
899 ULONG result = _gtc->TcRegisterClient(CURRENT_TCI_VERSION, NULL, | 856 ULONG result = _gtc->TcRegisterClient(CURRENT_TCI_VERSION, nullptr, |
900 &QoSFunctions,&ClientHandle); | 857 &QoSFunctions, &ClientHandle); |
901 if(result != NO_ERROR) | 858 if(result != NO_ERROR) |
902 { | 859 { |
903 // This is likely caused by the application not being run as | 860 // This is likely caused by the application not being run as |
904 // administrator. | 861 // administrator. |
905 WEBRTC_TRACE(kTraceError, kTraceTransport, _id, | 862 WEBRTC_TRACE(kTraceError, kTraceTransport, _id, |
906 "TcRegisterClient returned %d", result); | 863 "TcRegisterClient returned %d", result); |
907 return result; | 864 return result; |
908 } | 865 } |
909 | 866 |
910 // Find traffic control-enabled network interfaces that matches this | 867 // Find traffic control-enabled network interfaces that matches this |
911 // socket's IP address. | 868 // socket's IP address. |
912 ULONG BufferSize = 0; | 869 ULONG BufferSize = 0; |
913 result = _gtc->TcEnumerateInterfaces(ClientHandle, &BufferSize, NULL); | 870 result = _gtc->TcEnumerateInterfaces(ClientHandle, &BufferSize, nullptr); |
914 | 871 |
915 if(result != NO_ERROR && result != ERROR_INSUFFICIENT_BUFFER) | 872 if(result != NO_ERROR && result != ERROR_INSUFFICIENT_BUFFER) |
916 { | 873 { |
917 _gtc->TcDeregisterClient(ClientHandle); | 874 _gtc->TcDeregisterClient(ClientHandle); |
918 return result; | 875 return result; |
919 } | 876 } |
920 | 877 |
921 if(result != ERROR_INSUFFICIENT_BUFFER) | 878 if(result != ERROR_INSUFFICIENT_BUFFER) |
922 { | 879 { |
923 // Empty buffer contains all control-enabled network interfaces. I.e. | 880 // Empty buffer contains all control-enabled network interfaces. I.e. |
924 // QoS is not enabled. | 881 // QoS is not enabled. |
925 WEBRTC_TRACE(kTraceError, kTraceTransport, _id, | 882 WEBRTC_TRACE(kTraceError, kTraceTransport, _id, |
926 "QOS faild since QOS is not installed on the interface"); | 883 "QOS faild since QOS is not installed on the interface"); |
927 | 884 |
928 _gtc->TcDeregisterClient(ClientHandle); | 885 _gtc->TcDeregisterClient(ClientHandle); |
929 return -1; | 886 return -1; |
930 } | 887 } |
931 | 888 |
932 PTC_IFC_DESCRIPTOR pInterfaceBuffer = | 889 PTC_IFC_DESCRIPTOR pInterfaceBuffer = |
933 (PTC_IFC_DESCRIPTOR)malloc(BufferSize); | 890 (PTC_IFC_DESCRIPTOR)malloc(BufferSize); |
934 if(pInterfaceBuffer == NULL) | 891 if (pInterfaceBuffer == nullptr) { |
935 { | 892 WEBRTC_TRACE(kTraceError, kTraceTransport, _id, "Out ot memory failure"); |
936 WEBRTC_TRACE(kTraceError, kTraceTransport, _id, | 893 _gtc->TcDeregisterClient(ClientHandle); |
937 "Out ot memory failure"); | 894 return ERROR_NOT_ENOUGH_MEMORY; |
938 _gtc->TcDeregisterClient(ClientHandle); | |
939 return ERROR_NOT_ENOUGH_MEMORY; | |
940 } | 895 } |
941 | 896 |
942 result = _gtc->TcEnumerateInterfaces(ClientHandle, &BufferSize, | 897 result = _gtc->TcEnumerateInterfaces(ClientHandle, &BufferSize, |
943 pInterfaceBuffer); | 898 pInterfaceBuffer); |
944 | 899 |
945 if(result != NO_ERROR) | 900 if(result != NO_ERROR) |
946 { | 901 { |
947 WEBRTC_TRACE( | 902 WEBRTC_TRACE( |
948 kTraceError, | 903 kTraceError, |
949 kTraceTransport, | 904 kTraceTransport, |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1002 } | 957 } |
1003 if(!addrFound) | 958 if(!addrFound) |
1004 { | 959 { |
1005 WEBRTC_TRACE(kTraceError, kTraceTransport, _id, | 960 WEBRTC_TRACE(kTraceError, kTraceTransport, _id, |
1006 "QOS faild since address is not found"); | 961 "QOS faild since address is not found"); |
1007 _gtc->TcDeregisterClient(ClientHandle); | 962 _gtc->TcDeregisterClient(ClientHandle); |
1008 free(pInterfaceBuffer); | 963 free(pInterfaceBuffer); |
1009 return -1; | 964 return -1; |
1010 } | 965 } |
1011 result = _gtc->TcOpenInterfaceW(oneinterface->pInterfaceName, ClientHandle, | 966 result = _gtc->TcOpenInterfaceW(oneinterface->pInterfaceName, ClientHandle, |
1012 NULL, &ifcHandle); | 967 nullptr, &ifcHandle); |
1013 if(result != NO_ERROR) | 968 if(result != NO_ERROR) |
1014 { | 969 { |
1015 WEBRTC_TRACE(kTraceError, kTraceTransport, _id, | 970 WEBRTC_TRACE(kTraceError, kTraceTransport, _id, |
1016 "Error opening interface: %d", result); | 971 "Error opening interface: %d", result); |
1017 _gtc->TcDeregisterClient(ClientHandle); | 972 _gtc->TcDeregisterClient(ClientHandle); |
1018 free(pInterfaceBuffer); | 973 free(pInterfaceBuffer); |
1019 return result; | 974 return result; |
1020 } | 975 } |
1021 | 976 |
1022 // Create flow if one doesn't exist. | 977 // Create flow if one doesn't exist. |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1158 | 1113 |
1159 // Setup PCP (802.1p priority in 802.1Q/VLAN tagging) | 1114 // Setup PCP (802.1p priority in 802.1Q/VLAN tagging) |
1160 if (pcp >= 0) | 1115 if (pcp >= 0) |
1161 { | 1116 { |
1162 // DS is always first object. | 1117 // DS is always first object. |
1163 QOS_DS_CLASS* dsClass = (QOS_DS_CLASS*)_flow->TcObjects; | 1118 QOS_DS_CLASS* dsClass = (QOS_DS_CLASS*)_flow->TcObjects; |
1164 QOS_TRAFFIC_CLASS* trafficClass = (QOS_TRAFFIC_CLASS*)(dsClass + 1); | 1119 QOS_TRAFFIC_CLASS* trafficClass = (QOS_TRAFFIC_CLASS*)(dsClass + 1); |
1165 trafficClass->TrafficClass = pcp; | 1120 trafficClass->TrafficClass = pcp; |
1166 } | 1121 } |
1167 | 1122 |
1168 result = _gtc->TcAddFlow(ifcHandle, NULL, 0, _flow, &iflowHandle); | 1123 result = _gtc->TcAddFlow(ifcHandle, nullptr, 0, _flow, &iflowHandle); |
1169 if(result != NO_ERROR) | 1124 if(result != NO_ERROR) |
1170 { | 1125 { |
1171 _gtc->TcCloseInterface(ifcHandle); | 1126 _gtc->TcCloseInterface(ifcHandle); |
1172 _gtc->TcDeregisterClient(ClientHandle); | 1127 _gtc->TcDeregisterClient(ClientHandle); |
1173 free(pInterfaceBuffer); | 1128 free(pInterfaceBuffer); |
1174 return -1; | 1129 return -1; |
1175 } | 1130 } |
1176 | 1131 |
1177 IP_PATTERN filterPattern, mask; | 1132 IP_PATTERN filterPattern, mask; |
1178 | 1133 |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1344 "UdpSocket2Windows(%d)::InvalidateSocket() WSAerror: %d", | 1299 "UdpSocket2Windows(%d)::InvalidateSocket() WSAerror: %d", |
1345 (int32_t)this, WSAGetLastError()); | 1300 (int32_t)this, WSAGetLastError()); |
1346 } | 1301 } |
1347 _socket = INVALID_SOCKET; | 1302 _socket = INVALID_SOCKET; |
1348 _ptrSocketRWLock->ReleaseLockExclusive(); | 1303 _ptrSocketRWLock->ReleaseLockExclusive(); |
1349 return true; | 1304 return true; |
1350 } | 1305 } |
1351 | 1306 |
1352 } // namespace test | 1307 } // namespace test |
1353 } // namespace webrtc | 1308 } // namespace webrtc |
OLD | NEW |