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

Unified Diff: webrtc/rtc_base/virtualsocketserver.cc

Issue 2989303002: Make Port (and subclasses) fully "Network"-based, instead of IP-based. (Closed)
Patch Set: Add back Port constructor that takes IP for backwards compatibility. Created 3 years, 4 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
« no previous file with comments | « webrtc/rtc_base/virtualsocketserver.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/rtc_base/virtualsocketserver.cc
diff --git a/webrtc/rtc_base/virtualsocketserver.cc b/webrtc/rtc_base/virtualsocketserver.cc
index e47b01bbcb59edf3bd3be27f3103ab94fbd46761..23e94a2d651495770b15036d541fde77c404d86c 100644
--- a/webrtc/rtc_base/virtualsocketserver.cc
+++ b/webrtc/rtc_base/virtualsocketserver.cc
@@ -127,8 +127,6 @@ VirtualSocket::~VirtualSocket() {
}
SocketAddress VirtualSocket::GetLocalAddress() const {
- if (!alternative_local_addr_.IsNil())
- return alternative_local_addr_;
return local_addr_;
}
@@ -140,10 +138,6 @@ void VirtualSocket::SetLocalAddress(const SocketAddress& addr) {
local_addr_ = addr;
}
-void VirtualSocket::SetAlternativeLocalAddress(const SocketAddress& addr) {
- alternative_local_addr_ = addr;
-}
-
int VirtualSocket::Bind(const SocketAddress& addr) {
if (!local_addr_.IsNil()) {
error_ = EINVAL;
@@ -642,6 +636,12 @@ void VirtualSocketServer::WakeUp() {
wakeup_.Set();
}
+void VirtualSocketServer::SetAlternativeLocalAddress(
+ const rtc::IPAddress& address,
+ const rtc::IPAddress& alternative) {
+ alternative_address_mapping_[address] = alternative;
+}
+
bool VirtualSocketServer::ProcessMessagesUntilIdle() {
RTC_DCHECK(msg_queue_ == Thread::Current());
stop_on_idle_ = true;
@@ -699,12 +699,22 @@ int VirtualSocketServer::Bind(VirtualSocket* socket,
int VirtualSocketServer::Bind(VirtualSocket* socket, SocketAddress* addr) {
RTC_DCHECK(nullptr != socket);
+ // Normalize the IP.
if (!IPIsUnspec(addr->ipaddr())) {
addr->SetIP(addr->ipaddr().Normalized());
} else {
RTC_NOTREACHED();
}
+ // If the IP appears in |alternative_address_mapping_|, meaning the test has
+ // configured sockets bound to this IP to actually use another IP, replace
+ // the IP here.
+ auto alternative = alternative_address_mapping_.find(addr->ipaddr());
+ if (alternative != alternative_address_mapping_.end()) {
+ addr->SetIP(alternative->second);
+ }
+
+ // Assign a port if not assigned.
if (addr->port() == 0) {
for (int i = 0; i < kEphemeralPortCount; ++i) {
addr->SetPort(GetNextPort());
« no previous file with comments | « webrtc/rtc_base/virtualsocketserver.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698