Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1468)

Unified Diff: webrtc/voice_engine/test/channel_transport/udp_socket2_win.cc

Issue 2685783014: Replace NULL with nullptr in all C++ files. (Closed)
Patch Set: Fixing android. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/voice_engine/test/channel_transport/udp_socket2_win.cc
diff --git a/webrtc/voice_engine/test/channel_transport/udp_socket2_win.cc b/webrtc/voice_engine/test/channel_transport/udp_socket2_win.cc
index ffe71390935b17ed107c32920eccb5a75792814e..07080cfd27832ea2f768e22c899d21480e1f9e0a 100644
--- a/webrtc/voice_engine/test/channel_transport/udp_socket2_win.cc
+++ b/webrtc/voice_engine/test/channel_transport/udp_socket2_win.cc
@@ -41,7 +41,8 @@ typedef const QOS_DESTADDR* LPCQOS_DESTADDR;
#define QOS_OBJECT_DESTADDR (0x00000004 + QOS_GENERAL_ID_BASE)
UdpSocket2Windows::UdpSocket2Windows(const int32_t id,
- UdpSocketManager* mgr, bool ipV6Enable,
+ UdpSocketManager* mgr,
+ bool ipV6Enable,
bool disableGQOS)
: _id(id),
_qos(true),
@@ -52,129 +53,105 @@ UdpSocket2Windows::UdpSocket2Windows(const int32_t id,
_addedToMgr(false),
delete_event_(true, false),
_outstandingCallsDisabled(false),
- _clientHandle(NULL),
- _flowHandle(NULL),
- _filterHandle(NULL),
- _flow(NULL),
- _gtc(NULL),
+ _clientHandle(nullptr),
+ _flowHandle(nullptr),
+ _filterHandle(nullptr),
+ _flow(nullptr),
+ _gtc(nullptr),
_pcp(-2),
- _receiveBuffers(0)
-{
- WEBRTC_TRACE(kTraceMemory, kTraceTransport, _id,
- "UdpSocket2Windows::UdpSocket2Windows()");
-
- _wantsIncoming = false;
- _mgr = static_cast<UdpSocket2ManagerWindows *>(mgr);
-
- _obj = NULL;
- _incomingCb = NULL;
- _socket = INVALID_SOCKET;
- _ptrCbRWLock = RWLockWrapper::CreateRWLock();
- _ptrDestRWLock = RWLockWrapper::CreateRWLock();
- _ptrSocketRWLock = RWLockWrapper::CreateRWLock();
-
- // Check if QoS is supported.
- BOOL bProtocolFound = FALSE;
- WSAPROTOCOL_INFO *lpProtocolBuf = NULL;
- WSAPROTOCOL_INFO pProtocolInfo;
-
- if(!disableGQOS)
- {
- DWORD dwBufLen = 0;
- // Set dwBufLen to the size needed to retreive all the requested
- // information from WSAEnumProtocols.
- int32_t nRet = WSAEnumProtocols(NULL, lpProtocolBuf, &dwBufLen);
- lpProtocolBuf = (WSAPROTOCOL_INFO*)malloc(dwBufLen);
- nRet = WSAEnumProtocols(NULL, lpProtocolBuf, &dwBufLen);
+ _receiveBuffers(0) {
+ WEBRTC_TRACE(kTraceMemory, kTraceTransport, _id,
+ "UdpSocket2Windows::UdpSocket2Windows()");
+
+ _wantsIncoming = false;
+ _mgr = static_cast<UdpSocket2ManagerWindows*>(mgr);
+
+ _obj = nullptr;
+ _incomingCb = nullptr;
+ _socket = INVALID_SOCKET;
+ _ptrCbRWLock = RWLockWrapper::CreateRWLock();
+ _ptrDestRWLock = RWLockWrapper::CreateRWLock();
+ _ptrSocketRWLock = RWLockWrapper::CreateRWLock();
+
+ // Check if QoS is supported.
+ BOOL bProtocolFound = FALSE;
+ WSAPROTOCOL_INFO* lpProtocolBuf = nullptr;
+ WSAPROTOCOL_INFO pProtocolInfo;
+
+ if (!disableGQOS) {
+ DWORD dwBufLen = 0;
+ // Set dwBufLen to the size needed to retreive all the requested
+ // information from WSAEnumProtocols.
+ int32_t nRet = WSAEnumProtocols(nullptr, lpProtocolBuf, &dwBufLen);
+ lpProtocolBuf = (WSAPROTOCOL_INFO*)malloc(dwBufLen);
+ nRet = WSAEnumProtocols(nullptr, lpProtocolBuf, &dwBufLen);
+
+ if (ipV6Enable) {
+ _iProtocol = AF_INET6;
+ } else {
+ _iProtocol = AF_INET;
+ }
- if (ipV6Enable)
- {
- _iProtocol=AF_INET6;
- } else {
- _iProtocol=AF_INET;
+ for (int32_t i = 0; i < nRet; i++) {
+ if (_iProtocol == lpProtocolBuf[i].iAddressFamily &&
+ IPPROTO_UDP == lpProtocolBuf[i].iProtocol) {
+ if ((XP1_QOS_SUPPORTED ==
+ (XP1_QOS_SUPPORTED & lpProtocolBuf[i].dwServiceFlags1))) {
+ pProtocolInfo = lpProtocolBuf[i];
+ bProtocolFound = TRUE;
+ break;
}
-
- for (int32_t i=0; i<nRet; i++)
- {
- if (_iProtocol == lpProtocolBuf[i].iAddressFamily &&
- IPPROTO_UDP == lpProtocolBuf[i].iProtocol)
- {
- if ((XP1_QOS_SUPPORTED ==
- (XP1_QOS_SUPPORTED & lpProtocolBuf[i].dwServiceFlags1)))
- {
- pProtocolInfo = lpProtocolBuf[i];
- bProtocolFound = TRUE;
- break;
- }
- }
- }
+ }
}
+ }
- if(!bProtocolFound)
- {
- free(lpProtocolBuf);
- _qos=false;
- WEBRTC_TRACE(
- kTraceError,
- kTraceTransport,
- _id,
- "UdpSocket2Windows::UdpSocket2Windows(), SOCKET_ERROR_NO_QOS,\
+ if (!bProtocolFound) {
+ free(lpProtocolBuf);
+ _qos = false;
+ WEBRTC_TRACE(kTraceError, kTraceTransport, _id,
+ "UdpSocket2Windows::UdpSocket2Windows(), SOCKET_ERROR_NO_QOS,\
!bProtocolFound");
+ } else {
+ _socket =
+ WSASocket(FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO,
+ &pProtocolInfo, 0, WSA_FLAG_OVERLAPPED);
+ free(lpProtocolBuf);
+
+ if (_socket != INVALID_SOCKET) {
+ return;
} else {
-
- _socket = WSASocket(FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO,
- FROM_PROTOCOL_INFO,&pProtocolInfo, 0,
- WSA_FLAG_OVERLAPPED);
- free(lpProtocolBuf);
-
- if (_socket != INVALID_SOCKET)
- {
- return;
- } else {
- _qos = false;
- WEBRTC_TRACE(
- kTraceError,
- kTraceTransport,
- _id,
- "UdpSocket2Windows::UdpSocket2Windows(), SOCKET_ERROR_NO_QOS");
- }
- }
- // QoS not supported.
- if(ipV6Enable)
- {
- _socket = WSASocket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP, 0 , 0,
- WSA_FLAG_OVERLAPPED);
- }else
- {
- _socket = WSASocket(AF_INET, SOCK_DGRAM, IPPROTO_UDP, 0 , 0,
- WSA_FLAG_OVERLAPPED);
- }
- if (_socket == INVALID_SOCKET)
- {
- WEBRTC_TRACE(
- kTraceError,
- kTraceTransport,
- _id,
- "UdpSocket2Windows::UdpSocket2Windows(), INVALID_SOCKET,\
+ _qos = false;
+ WEBRTC_TRACE(
+ kTraceError, kTraceTransport, _id,
+ "UdpSocket2Windows::UdpSocket2Windows(), SOCKET_ERROR_NO_QOS");
+ }
+ }
+ // QoS not supported.
+ if (ipV6Enable) {
+ _socket =
+ WSASocket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP, 0, 0, WSA_FLAG_OVERLAPPED);
+ } else {
+ _socket =
+ WSASocket(AF_INET, SOCK_DGRAM, IPPROTO_UDP, 0, 0, WSA_FLAG_OVERLAPPED);
+ }
+ if (_socket == INVALID_SOCKET) {
+ WEBRTC_TRACE(kTraceError, kTraceTransport, _id,
+ "UdpSocket2Windows::UdpSocket2Windows(), INVALID_SOCKET,\
WSAerror: %d",
- WSAGetLastError());
- }
-
- // Disable send buffering on the socket to improve CPU usage.
- // This is done by setting SO_SNDBUF to 0.
- int32_t nZero = 0;
- int32_t nRet = setsockopt(_socket, SOL_SOCKET, SO_SNDBUF,
- (char*)&nZero, sizeof(nZero));
- if( nRet == SOCKET_ERROR )
- {
- WEBRTC_TRACE(
- kTraceError,
- kTraceTransport,
- _id,
- "UdpSocket2Windows::UdpSocket2Windows(), SOCKET_ERROR,\
+ WSAGetLastError());
+ }
+
+ // Disable send buffering on the socket to improve CPU usage.
+ // This is done by setting SO_SNDBUF to 0.
+ int32_t nZero = 0;
+ int32_t nRet =
+ setsockopt(_socket, SOL_SOCKET, SO_SNDBUF, (char*)&nZero, sizeof(nZero));
+ if (nRet == SOCKET_ERROR) {
+ WEBRTC_TRACE(kTraceError, kTraceTransport, _id,
+ "UdpSocket2Windows::UdpSocket2Windows(), SOCKET_ERROR,\
WSAerror: %d",
- WSAGetLastError());
- }
+ WSAGetLastError());
+ }
}
UdpSocket2Windows::~UdpSocket2Windows()
@@ -192,7 +169,7 @@ UdpSocket2Windows::~UdpSocket2Windows()
if (_flow)
{
free(_flow);
- _flow = NULL;
+ _flow = nullptr;
}
if (_gtc)
@@ -422,75 +399,55 @@ int32_t UdpSocket2Windows::SendTo(const int8_t* buf, size_t len,
void UdpSocket2Windows::IOCompleted(PerIoContext* pIOContext,
uint32_t ioSize, uint32_t error)
{
- if(pIOContext == NULL || error == ERROR_OPERATION_ABORTED)
- {
- if ((pIOContext != NULL) &&
- !pIOContext->ioInitiatedByPlatformThread &&
- (error == ERROR_OPERATION_ABORTED) &&
- (pIOContext->ioOperation == OP_READ) &&
- _outstandingCallsDisabled)
- {
- // !pIOContext->initiatedIOByPlatformThread indicate that the I/O
- // was not initiated by a PlatformThread thread.
- // This may happen if the thread that initiated receiving (e.g.
- // by calling StartListen())) is deleted before any packets have
- // been received.
- // In this case there is no packet in the PerIoContext. Re-use it
- // to post a new PostRecv(..).
- // Note 1: the PerIoContext will henceforth be posted by a thread
- // that is controlled by the socket implementation.
- // Note 2: This is more likely to happen to RTCP packets as
- // they are less frequent than RTP packets.
- // Note 3: _outstandingCallsDisabled being false indicates
- // that the socket isn't being shut down.
- // Note 4: This should only happen buffers set to receive packets
- // (OP_READ).
- } else {
- if(pIOContext == NULL)
- {
- WEBRTC_TRACE(
- kTraceError,
- kTraceTransport,
- _id,
- "UdpSocket2Windows::IOCompleted(%d,%d,%d), %d",
- (int32_t)pIOContext,
- ioSize,
- error,
- pIOContext ? (int32_t)pIOContext->ioOperation : -1);
- } else {
- WEBRTC_TRACE(
- kTraceDebug,
- kTraceTransport,
- _id,
- "UdpSocket2Windows::IOCompleted() Operation aborted");
- }
- if(pIOContext)
- {
- int32_t remainingReceiveBuffers = --_receiveBuffers;
- if(remainingReceiveBuffers < 0)
- {
- assert(false);
- }
- int32_t err = _mgr->PushIoContext(pIOContext);
- if(err)
- {
- WEBRTC_TRACE(
- kTraceError,
- kTraceTransport,
- _id,
- "UdpSocket2Windows::IOCompleted(), err = %d, when\
+ if (pIOContext == nullptr || error == ERROR_OPERATION_ABORTED) {
+ if ((pIOContext != nullptr) && !pIOContext->ioInitiatedByPlatformThread &&
+ (error == ERROR_OPERATION_ABORTED) &&
+ (pIOContext->ioOperation == OP_READ) && _outstandingCallsDisabled) {
+ // !pIOContext->initiatedIOByPlatformThread indicate that the I/O
+ // was not initiated by a PlatformThread thread.
+ // This may happen if the thread that initiated receiving (e.g.
+ // by calling StartListen())) is deleted before any packets have
+ // been received.
+ // In this case there is no packet in the PerIoContext. Re-use it
+ // to post a new PostRecv(..).
+ // Note 1: the PerIoContext will henceforth be posted by a thread
+ // that is controlled by the socket implementation.
+ // Note 2: This is more likely to happen to RTCP packets as
+ // they are less frequent than RTP packets.
+ // Note 3: _outstandingCallsDisabled being false indicates
+ // that the socket isn't being shut down.
+ // Note 4: This should only happen buffers set to receive packets
+ // (OP_READ).
+ } else {
+ if (pIOContext == nullptr) {
+ WEBRTC_TRACE(kTraceError, kTraceTransport, _id,
+ "UdpSocket2Windows::IOCompleted(%d,%d,%d), %d",
+ (int32_t)pIOContext, ioSize, error,
+ pIOContext ? (int32_t)pIOContext->ioOperation : -1);
+ } else {
+ WEBRTC_TRACE(kTraceDebug, kTraceTransport, _id,
+ "UdpSocket2Windows::IOCompleted() Operation aborted");
+ }
+ if (pIOContext) {
+ int32_t remainingReceiveBuffers = --_receiveBuffers;
+ if (remainingReceiveBuffers < 0) {
+ assert(false);
+ }
+ int32_t err = _mgr->PushIoContext(pIOContext);
+ if (err) {
+ WEBRTC_TRACE(kTraceError, kTraceTransport, _id,
+ "UdpSocket2Windows::IOCompleted(), err = %d, when\
pushing ioContext after error",
- err);
- }
- }
- OutstandingCallCompleted();
- return;
+ err);
}
- } // if (pIOContext == NULL || error == ERROR_OPERATION_ABORTED)
+ }
+ OutstandingCallCompleted();
+ return;
+ }
+ } // if (pIOContext == nullptr || error == ERROR_OPERATION_ABORTED)
- if(pIOContext->ioOperation == OP_WRITE)
- {
- _mgr->PushIoContext(pIOContext);
+ if (pIOContext->ioOperation == OP_WRITE) {
+ _mgr->PushIoContext(pIOContext);
}
else if(pIOContext->ioOperation == OP_READ)
{
@@ -734,7 +691,7 @@ bool UdpSocket2Windows::SetQos(int32_t serviceType,
Qos.ProviderSpecific.len = 0;
- Qos.ProviderSpecific.buf = NULL;
+ Qos.ProviderSpecific.buf = nullptr;
ZeroMemory((int8_t *)&QosDestaddr, sizeof(QosDestaddr));
@@ -784,8 +741,8 @@ bool UdpSocket2Windows::SetQos(int32_t serviceType,
}
// To set QoS with SIO_SET_QOS the socket must be locally bound first
// or the call will fail with error code 10022.
- int32_t result = WSAIoctl(GetFd(), SIO_SET_QOS, &Qos, sizeof(QOS),
- NULL, 0, &BytesRet, NULL,NULL);
+ int32_t result = WSAIoctl(GetFd(), SIO_SET_QOS, &Qos, sizeof(QOS), nullptr,
+ 0, &BytesRet, nullptr, nullptr);
ReleaseSocket();
if (result == SOCKET_ERROR)
{
@@ -869,17 +826,17 @@ int32_t UdpSocket2Windows::SetTrafficControl(
if(_filterHandle)
{
_gtc->TcDeleteFilter(_filterHandle);
- _filterHandle = NULL;
+ _filterHandle = nullptr;
}
if(_flowHandle)
{
_gtc->TcDeleteFlow(_flowHandle);
- _flowHandle = NULL;
+ _flowHandle = nullptr;
}
if(_clientHandle)
{
_gtc->TcDeregisterClient(_clientHandle);
- _clientHandle = NULL;
+ _clientHandle = nullptr;
}
if ((0 == dscp) && (-2 == _pcp) && (-1 == pcp))
{
@@ -890,14 +847,14 @@ int32_t UdpSocket2Windows::SetTrafficControl(
}
TCI_CLIENT_FUNC_LIST QoSFunctions;
- QoSFunctions.ClAddFlowCompleteHandler = NULL;
- QoSFunctions.ClDeleteFlowCompleteHandler = NULL;
- QoSFunctions.ClModifyFlowCompleteHandler = NULL;
+ QoSFunctions.ClAddFlowCompleteHandler = nullptr;
+ QoSFunctions.ClDeleteFlowCompleteHandler = nullptr;
+ QoSFunctions.ClModifyFlowCompleteHandler = nullptr;
QoSFunctions.ClNotifyHandler = (TCI_NOTIFY_HANDLER)MyClNotifyHandler;
// Register the client with Traffic control interface.
HANDLE ClientHandle;
- ULONG result = _gtc->TcRegisterClient(CURRENT_TCI_VERSION, NULL,
- &QoSFunctions,&ClientHandle);
+ ULONG result = _gtc->TcRegisterClient(CURRENT_TCI_VERSION, nullptr,
+ &QoSFunctions, &ClientHandle);
if(result != NO_ERROR)
{
// This is likely caused by the application not being run as
@@ -910,7 +867,7 @@ int32_t UdpSocket2Windows::SetTrafficControl(
// Find traffic control-enabled network interfaces that matches this
// socket's IP address.
ULONG BufferSize = 0;
- result = _gtc->TcEnumerateInterfaces(ClientHandle, &BufferSize, NULL);
+ result = _gtc->TcEnumerateInterfaces(ClientHandle, &BufferSize, nullptr);
if(result != NO_ERROR && result != ERROR_INSUFFICIENT_BUFFER)
{
@@ -931,12 +888,10 @@ int32_t UdpSocket2Windows::SetTrafficControl(
PTC_IFC_DESCRIPTOR pInterfaceBuffer =
(PTC_IFC_DESCRIPTOR)malloc(BufferSize);
- if(pInterfaceBuffer == NULL)
- {
- WEBRTC_TRACE(kTraceError, kTraceTransport, _id,
- "Out ot memory failure");
- _gtc->TcDeregisterClient(ClientHandle);
- return ERROR_NOT_ENOUGH_MEMORY;
+ if (pInterfaceBuffer == nullptr) {
+ WEBRTC_TRACE(kTraceError, kTraceTransport, _id, "Out ot memory failure");
+ _gtc->TcDeregisterClient(ClientHandle);
+ return ERROR_NOT_ENOUGH_MEMORY;
}
result = _gtc->TcEnumerateInterfaces(ClientHandle, &BufferSize,
@@ -1009,7 +964,7 @@ int32_t UdpSocket2Windows::SetTrafficControl(
return -1;
}
result = _gtc->TcOpenInterfaceW(oneinterface->pInterfaceName, ClientHandle,
- NULL, &ifcHandle);
+ nullptr, &ifcHandle);
if(result != NO_ERROR)
{
WEBRTC_TRACE(kTraceError, kTraceTransport, _id,
@@ -1165,7 +1120,7 @@ int32_t UdpSocket2Windows::SetTrafficControl(
trafficClass->TrafficClass = pcp;
}
- result = _gtc->TcAddFlow(ifcHandle, NULL, 0, _flow, &iflowHandle);
+ result = _gtc->TcAddFlow(ifcHandle, nullptr, 0, _flow, &iflowHandle);
if(result != NO_ERROR)
{
_gtc->TcCloseInterface(ifcHandle);

Powered by Google App Engine
This is Rietveld 408576698