Bug 1053650 - Part 3: Make use of gonk-specific per-interface DNS lookup. r=mcmanus, a=bajaj
authorHenry Chang <hchang@mozilla.com>
Wed, 28 Jan 2015 11:21:37 +0800
changeset 238137 dc0fce2633ddbf39143a98344af36155afc900a9
parent 238136 4a91d189b58c3d1e92a1b272c9ae651b42780a02
child 238138 9197f5c1dd5139ac7ad0c65b0d4b339f29d2b5e8
push id488
push userryanvm@gmail.com
push dateMon, 13 Apr 2015 20:29:57 +0000
treeherdermozilla-b2g37_v2_2@85ea1be9ac7d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmcmanus, bajaj
bugs1053650
milestone37.0
Bug 1053650 - Part 3: Make use of gonk-specific per-interface DNS lookup. r=mcmanus, a=bajaj
netwerk/base/public/nsISocketTransport.idl
netwerk/base/src/nsSocketTransport2.cpp
netwerk/base/src/nsSocketTransport2.h
netwerk/protocol/http/TunnelUtils.cpp
--- a/netwerk/base/public/nsISocketTransport.idl
+++ b/netwerk/base/public/nsISocketTransport.idl
@@ -23,33 +23,40 @@ native NetAddr(mozilla::net::NetAddr);
  *
  * NOTE: Connection setup is triggered by opening an input or output stream,
  * it does not start on its own. Completion of the connection setup is
  * indicated by a STATUS_CONNECTED_TO notification to the event sink (if set).
  *
  * NOTE: This is a free-threaded interface, meaning that the methods on
  * this interface may be called from any thread.
  */
-[scriptable, uuid(a0b3b547-d6f0-4b65-a3de-a99ffa368840)]
+[scriptable, uuid(79221831-85e2-43a8-8152-05d77d6fde31)]
 interface nsISocketTransport : nsITransport 
 {
     /**
      * Get the peer's host for the underlying socket connection.
      * For Unix domain sockets, this is a pathname, or the empty string for
      * unnamed and abstract socket addresses.
      */
     readonly attribute AUTF8String host;
 
     /**
      * Get the port for the underlying socket connection.
      * For Unix domain sockets, this is zero.
      */
     readonly attribute long port;
 
     /**
+     * The platform-specific network interface id that this socket
+     * associated with. Note that this attribute can be only accessed
+     * in the socket thread.
+     */
+    attribute ACString networkInterfaceId;
+
+    /**
      * Returns the IP address of the socket connection peer. This
      * attribute is defined only once a connection has been established.
      */
     [noscript] NetAddr getPeerAddr();
 
     /**
      * Returns the IP address of the initiating end. This attribute
      * is defined only once a connection has been established.
@@ -202,13 +209,15 @@ interface nsISocketTransport : nsITransp
      * TCP send and receive buffer sizes. A value of 0 means OS level
      * auto-tuning is in effect.
      */
     attribute unsigned long recvBufferSize;
     attribute unsigned long sendBufferSize;
 
     /**
      * TCP keepalive configuration (support varies by platform).
+     * Note that the attribute as well as the setter can only accessed
+     * in the socket thread.
      */
     attribute boolean keepaliveEnabled;
     void setKeepaliveVals(in long keepaliveIdleTime,
                           in long keepaliveRetryInterval);
 };
--- a/netwerk/base/src/nsSocketTransport2.cpp
+++ b/netwerk/base/src/nsSocketTransport2.cpp
@@ -1041,18 +1041,18 @@ nsSocketTransport::ResolveHost()
     if (mConnectionFlags & nsSocketTransport::DISABLE_IPV4)
         dnsFlags |= nsIDNSService::RESOLVE_DISABLE_IPV4;
 
     NS_ASSERTION(!(dnsFlags & nsIDNSService::RESOLVE_DISABLE_IPV6) ||
                  !(dnsFlags & nsIDNSService::RESOLVE_DISABLE_IPV4),
                  "Setting both RESOLVE_DISABLE_IPV6 and RESOLVE_DISABLE_IPV4");
 
     SendStatus(NS_NET_STATUS_RESOLVING_HOST);
-    rv = dns->AsyncResolve(SocketHost(), dnsFlags, this, nullptr,
-                           getter_AddRefs(mDNSRequest));
+    rv = dns->AsyncResolveExtended(SocketHost(), dnsFlags, mNetworkInterfaceId, this,
+                                   nullptr, getter_AddRefs(mDNSRequest));
     if (NS_SUCCEEDED(rv)) {
         SOCKET_LOG(("  advancing to STATE_RESOLVING\n"));
         mState = STATE_RESOLVING;
     }
     return rv;
 }
 
 nsresult
@@ -2189,16 +2189,32 @@ nsSocketTransport::GetHost(nsACString &h
 NS_IMETHODIMP
 nsSocketTransport::GetPort(int32_t *port)
 {
     *port = (int32_t) SocketPort();
     return NS_OK;
 }
 
 NS_IMETHODIMP
+nsSocketTransport::GetNetworkInterfaceId(nsACString_internal &aNetworkInterfaceId)
+{
+    MOZ_ASSERT(PR_GetCurrentThread() == gSocketThread, "wrong thread");
+    aNetworkInterfaceId = mNetworkInterfaceId;
+    return NS_OK;
+}
+
+NS_IMETHODIMP
+nsSocketTransport::SetNetworkInterfaceId(const nsACString_internal &aNetworkInterfaceId)
+{
+    MOZ_ASSERT(PR_GetCurrentThread() == gSocketThread, "wrong thread");
+    mNetworkInterfaceId = aNetworkInterfaceId;
+    return NS_OK;
+}
+
+NS_IMETHODIMP
 nsSocketTransport::GetPeerAddr(NetAddr *addr)
 {
     // once we are in the connected state, mNetAddr will not change.
     // so if we can verify that we are in the connected state, then
     // we can freely access mNetAddr from any thread without being
     // inside a critical section.
 
     if (!mNetAddrIsSet) {
--- a/netwerk/base/src/nsSocketTransport2.h
+++ b/netwerk/base/src/nsSocketTransport2.h
@@ -288,16 +288,20 @@ private:
     //-------------------------------------------------------------------------
 
     // socket state vars:
     uint32_t     mState;     // STATE_??? flags
     bool mAttached;
     bool mInputClosed;
     bool mOutputClosed;
 
+    // The platform-specific network interface id that this socket
+    // associated with.
+    nsCString mNetworkInterfaceId;
+
     // this flag is used to determine if the results of a host lookup arrive
     // recursively or not.  this flag is not protected by any lock.
     bool mResolving;
 
     nsCOMPtr<nsICancelable> mDNSRequest;
     nsCOMPtr<nsIDNSRecord>  mDNSRecord;
 
     // mNetAddr is valid from GetPeerAddr() once we have
--- a/netwerk/protocol/http/TunnelUtils.cpp
+++ b/netwerk/protocol/http/TunnelUtils.cpp
@@ -1593,16 +1593,28 @@ SocketTransportShim::GetHost(nsACString 
 
 NS_IMETHODIMP
 SocketTransportShim::GetTimeout(uint32_t aType, uint32_t *_retval)
 {
   return mWrapped->GetTimeout(aType, _retval);
 }
 
 NS_IMETHODIMP
+SocketTransportShim::GetNetworkInterfaceId(nsACString_internal &aNetworkInterfaceId)
+{
+  return mWrapped->GetNetworkInterfaceId(aNetworkInterfaceId);
+}
+
+NS_IMETHODIMP
+SocketTransportShim::SetNetworkInterfaceId(const nsACString_internal &aNetworkInterfaceId)
+{
+  return mWrapped->SetNetworkInterfaceId(aNetworkInterfaceId);
+}
+
+NS_IMETHODIMP
 SocketTransportShim::SetTimeout(uint32_t aType, uint32_t aValue)
 {
   return mWrapped->SetTimeout(aType, aValue);
 }
 
 NS_IMETHODIMP
 SocketTransportShim::GetQoSBits(uint8_t *aQoSBits)
 {