Added UDP socket factory function to UdpTransportImpl constructor
This is a refactoring in preparation for creating small unit tests for the udp_transport module. BUG= TEST=unittest Review URL: https://webrtc-codereview.appspot.com/482004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@2041 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
parent
c3eb178a0d
commit
52c0fec34c
@ -69,7 +69,8 @@ namespace webrtc {
|
|||||||
UdpTransport* UdpTransport::Create(const WebRtc_Word32 id,
|
UdpTransport* UdpTransport::Create(const WebRtc_Word32 id,
|
||||||
WebRtc_UWord8& numSocketThreads)
|
WebRtc_UWord8& numSocketThreads)
|
||||||
{
|
{
|
||||||
return new UdpTransportImpl(id, numSocketThreads);
|
return new UdpTransportImpl(id, numSocketThreads,
|
||||||
|
&UdpSocketWrapper::CreateSocket);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UdpTransport::Destroy(UdpTransport* module)
|
void UdpTransport::Destroy(UdpTransport* module)
|
||||||
@ -81,8 +82,10 @@ void UdpTransport::Destroy(UdpTransport* module)
|
|||||||
}
|
}
|
||||||
|
|
||||||
UdpTransportImpl::UdpTransportImpl(const WebRtc_Word32 id,
|
UdpTransportImpl::UdpTransportImpl(const WebRtc_Word32 id,
|
||||||
WebRtc_UWord8& numSocketThreads)
|
WebRtc_UWord8& numSocketThreads,
|
||||||
|
SocketMaker* maker)
|
||||||
: _id(id),
|
: _id(id),
|
||||||
|
_socket_creator(maker),
|
||||||
_crit(CriticalSectionWrapper::CreateCriticalSection()),
|
_crit(CriticalSectionWrapper::CreateCriticalSection()),
|
||||||
_critFilter(CriticalSectionWrapper::CreateCriticalSection()),
|
_critFilter(CriticalSectionWrapper::CreateCriticalSection()),
|
||||||
_critPacketCallback(CriticalSectionWrapper::CreateCriticalSection()),
|
_critPacketCallback(CriticalSectionWrapper::CreateCriticalSection()),
|
||||||
@ -349,13 +352,13 @@ WebRtc_Word32 UdpTransportImpl::InitializeReceiveSockets(
|
|||||||
_tos=0;
|
_tos=0;
|
||||||
_pcp=0;
|
_pcp=0;
|
||||||
|
|
||||||
_ptrRtpSocket = UdpSocketWrapper::CreateSocket(_id, _mgr, this,
|
_ptrRtpSocket = _socket_creator(_id, _mgr, this,
|
||||||
IncomingRTPCallback,
|
IncomingRTPCallback,
|
||||||
IpV6Enabled());
|
IpV6Enabled(), false);
|
||||||
|
|
||||||
_ptrRtcpSocket = UdpSocketWrapper::CreateSocket(_id, _mgr, this,
|
_ptrRtcpSocket = _socket_creator(_id, _mgr, this,
|
||||||
IncomingRTCPCallback,
|
IncomingRTCPCallback,
|
||||||
IpV6Enabled());
|
IpV6Enabled(), false);
|
||||||
|
|
||||||
ErrorCode retVal = BindLocalRTPSocket();
|
ErrorCode retVal = BindLocalRTPSocket();
|
||||||
if(retVal != kNoSocketError)
|
if(retVal != kNoSocketError)
|
||||||
@ -829,13 +832,13 @@ WebRtc_Word32 UdpTransportImpl::SetToS(WebRtc_Word32 DSCP, bool useSetSockOpt)
|
|||||||
{
|
{
|
||||||
CloseSendSockets();
|
CloseSendSockets();
|
||||||
_ptrSendRtpSocket =
|
_ptrSendRtpSocket =
|
||||||
UdpSocketWrapper::CreateSocket(_id, _mgr, NULL,
|
_socket_creator(_id, _mgr, NULL,
|
||||||
NULL, IpV6Enabled(),
|
NULL, IpV6Enabled(),
|
||||||
true);
|
true);
|
||||||
_ptrSendRtcpSocket =
|
_ptrSendRtcpSocket =
|
||||||
UdpSocketWrapper::CreateSocket(_id, _mgr, NULL,
|
_socket_creator(_id, _mgr, NULL,
|
||||||
NULL, IpV6Enabled(),
|
NULL, IpV6Enabled(),
|
||||||
true);
|
true);
|
||||||
rtpSock=_ptrSendRtpSocket;
|
rtpSock=_ptrSendRtpSocket;
|
||||||
rtcpSock=_ptrSendRtcpSocket;
|
rtcpSock=_ptrSendRtcpSocket;
|
||||||
ErrorCode retVal = BindRTPSendSocket();
|
ErrorCode retVal = BindRTPSendSocket();
|
||||||
@ -864,12 +867,12 @@ WebRtc_Word32 UdpTransportImpl::SetToS(WebRtc_Word32 DSCP, bool useSetSockOpt)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
CloseReceiveSockets();
|
CloseReceiveSockets();
|
||||||
_ptrRtpSocket = UdpSocketWrapper::CreateSocket(
|
_ptrRtpSocket = _socket_creator(_id, _mgr, this,
|
||||||
_id, _mgr, this, IncomingRTPCallback,
|
IncomingRTPCallback,
|
||||||
IpV6Enabled(), true);
|
IpV6Enabled(), true);
|
||||||
_ptrRtcpSocket = UdpSocketWrapper::CreateSocket(
|
_ptrRtcpSocket = _socket_creator(_id, _mgr, this,
|
||||||
_id, _mgr, this, IncomingRTCPCallback,
|
IncomingRTCPCallback,
|
||||||
IpV6Enabled(),true);
|
IpV6Enabled(),true);
|
||||||
rtpSock=_ptrRtpSocket;
|
rtpSock=_ptrRtpSocket;
|
||||||
rtcpSock=_ptrRtcpSocket;
|
rtcpSock=_ptrRtcpSocket;
|
||||||
ErrorCode retVal = BindLocalRTPSocket();
|
ErrorCode retVal = BindLocalRTPSocket();
|
||||||
@ -1527,10 +1530,10 @@ WebRtc_Word32 UdpTransportImpl::InitializeSourcePorts(WebRtc_UWord16 rtpPort,
|
|||||||
_tos=0;
|
_tos=0;
|
||||||
_pcp=0;
|
_pcp=0;
|
||||||
|
|
||||||
_ptrSendRtpSocket = UdpSocketWrapper::CreateSocket(_id, _mgr, NULL, NULL,
|
_ptrSendRtpSocket = _socket_creator(_id, _mgr, NULL, NULL,
|
||||||
IpV6Enabled());
|
IpV6Enabled(), false);
|
||||||
_ptrSendRtcpSocket = UdpSocketWrapper::CreateSocket(_id, _mgr, NULL, NULL,
|
_ptrSendRtcpSocket = _socket_creator(_id, _mgr, NULL, NULL,
|
||||||
IpV6Enabled());
|
IpV6Enabled(), false);
|
||||||
|
|
||||||
ErrorCode retVal = BindRTPSendSocket();
|
ErrorCode retVal = BindRTPSendSocket();
|
||||||
if(retVal != kNoSocketError)
|
if(retVal != kNoSocketError)
|
||||||
@ -1980,9 +1983,9 @@ int UdpTransportImpl::SendPacket(int /*channel*/, const void* data, int length)
|
|||||||
"Creating RTP socket since no receive or source socket is\
|
"Creating RTP socket since no receive or source socket is\
|
||||||
configured");
|
configured");
|
||||||
|
|
||||||
_ptrRtpSocket = UdpSocketWrapper::CreateSocket(_id, _mgr, this,
|
_ptrRtpSocket = _socket_creator(_id, _mgr, this,
|
||||||
IncomingRTPCallback,
|
IncomingRTPCallback,
|
||||||
IpV6Enabled());
|
IpV6Enabled(), false);
|
||||||
|
|
||||||
// Don't bind to a specific IP address.
|
// Don't bind to a specific IP address.
|
||||||
if(! IpV6Enabled())
|
if(! IpV6Enabled())
|
||||||
@ -2046,9 +2049,9 @@ int UdpTransportImpl::SendRTCPPacket(int /*channel*/, const void* data,
|
|||||||
"Creating RTCP socket since no receive or source socket is\
|
"Creating RTCP socket since no receive or source socket is\
|
||||||
configured");
|
configured");
|
||||||
|
|
||||||
_ptrRtcpSocket = UdpSocketWrapper::CreateSocket(_id, _mgr, this,
|
_ptrRtcpSocket = _socket_creator(_id, _mgr, this,
|
||||||
IncomingRTCPCallback,
|
IncomingRTCPCallback,
|
||||||
IpV6Enabled());
|
IpV6Enabled(), false);
|
||||||
|
|
||||||
// Don't bind to a specific IP address.
|
// Don't bind to a specific IP address.
|
||||||
if(! IpV6Enabled())
|
if(! IpV6Enabled())
|
||||||
|
@ -22,8 +22,17 @@ class UdpSocketManager;
|
|||||||
class UdpTransportImpl : public UdpTransport
|
class UdpTransportImpl : public UdpTransport
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// Factory method. Constructor disabled.
|
// A function that returns a wrapped UDP socket or equivalent.
|
||||||
UdpTransportImpl(const WebRtc_Word32 id, WebRtc_UWord8& numSocketThreads);
|
typedef UdpSocketWrapper* (SocketMaker)(const WebRtc_Word32 id,
|
||||||
|
UdpSocketManager* mgr,
|
||||||
|
CallbackObj obj,
|
||||||
|
IncomingSocketCallback cb,
|
||||||
|
bool ipV6Enable,
|
||||||
|
bool disableGQOS);
|
||||||
|
|
||||||
|
// Constructor, only called by UdpTransport::Create and tests.
|
||||||
|
UdpTransportImpl(const WebRtc_Word32 id, WebRtc_UWord8& numSocketThreads,
|
||||||
|
SocketMaker* maker);
|
||||||
virtual ~UdpTransportImpl();
|
virtual ~UdpTransportImpl();
|
||||||
|
|
||||||
// Module functions
|
// Module functions
|
||||||
@ -174,6 +183,7 @@ private:
|
|||||||
WebRtc_UWord16& sourcePort);
|
WebRtc_UWord16& sourcePort);
|
||||||
|
|
||||||
WebRtc_Word32 _id;
|
WebRtc_Word32 _id;
|
||||||
|
SocketMaker* _socket_creator;
|
||||||
// Protects the sockets from being re-configured while receiving packets.
|
// Protects the sockets from being re-configured while receiving packets.
|
||||||
CriticalSectionWrapper* _crit;
|
CriticalSectionWrapper* _crit;
|
||||||
CriticalSectionWrapper* _critFilter;
|
CriticalSectionWrapper* _critFilter;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
|
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
||||||
*
|
*
|
||||||
* Use of this source code is governed by a BSD-style license
|
* Use of this source code is governed by a BSD-style license
|
||||||
* that can be found in the LICENSE file in the root of the source
|
* that can be found in the LICENSE file in the root of the source
|
||||||
@ -13,5 +13,23 @@
|
|||||||
*/
|
*/
|
||||||
#include "udp_transport.h"
|
#include "udp_transport.h"
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
|
// We include the implementation header file to get at the dependency-injecting
|
||||||
|
// constructor.
|
||||||
|
#include "udp_transport_impl.h"
|
||||||
|
|
||||||
TEST(UDPTransportTest, EmptyTestToGetCodeCoverage) {}
|
TEST(UDPTransportTest, CreateTransport) {
|
||||||
|
WebRtc_Word32 id = 0;
|
||||||
|
WebRtc_UWord8 threads = 0;
|
||||||
|
webrtc::UdpTransport* transport = webrtc::UdpTransport::Create(id, threads);
|
||||||
|
webrtc::UdpTransport::Destroy(transport);
|
||||||
|
}
|
||||||
|
|
||||||
|
// This test verifies that the mock_socket is not called from the constructor.
|
||||||
|
TEST(UDPTransportTest, ConstructorDoesNotCreateSocket) {
|
||||||
|
WebRtc_Word32 id = 0;
|
||||||
|
WebRtc_UWord8 threads = 0;
|
||||||
|
webrtc::UdpTransportImpl::SocketMaker* null_maker = NULL;
|
||||||
|
webrtc::UdpTransport* transport = new webrtc::UdpTransportImpl(id, threads,
|
||||||
|
null_maker);
|
||||||
|
webrtc::UdpTransport::Destroy(transport);
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user