From c6bdc49f299616903f2809a2bb202bf2278e8b7d Mon Sep 17 00:00:00 2001 From: Thomas Zimmermann Date: Wed, 27 May 2015 13:49:07 +0200 Subject: [PATCH] Bug 1167210: Replace |union sockaddr_any| with |struct sockaddr_storage|, r=kmachulis Both types, |union sockaddr_any| and |struct sockaddr_storage|, provide a sockaddr type that can hold any address. The latter is standardized by POSIX, so we prefer it. --- .../bluedroid/BluetoothDaemonConnector.cpp | 1 + .../bluez/BluetoothUnixSocketConnector.cpp | 1 - .../bluez/BluetoothUnixSocketConnector.h | 1 + ipc/bluetooth/BluetoothDaemonConnection.cpp | 8 +++---- ipc/unixfd/UnixSocketWatcher.h | 22 ------------------- ipc/unixsocket/ConnectionOrientedSocket.h | 5 ++--- ipc/unixsocket/ListenSocket.cpp | 2 +- ipc/unixsocket/StreamSocket.cpp | 11 +++++----- 8 files changed, 15 insertions(+), 36 deletions(-) diff --git a/dom/bluetooth/bluedroid/BluetoothDaemonConnector.cpp b/dom/bluetooth/bluedroid/BluetoothDaemonConnector.cpp index fd39b8c974c..ca3a18646c4 100644 --- a/dom/bluetooth/bluedroid/BluetoothDaemonConnector.cpp +++ b/dom/bluetooth/bluedroid/BluetoothDaemonConnector.cpp @@ -7,6 +7,7 @@ #include "BluetoothDaemonConnector.h" #include +#include #include "nsThreadUtils.h" BEGIN_BLUETOOTH_NAMESPACE diff --git a/dom/bluetooth/bluez/BluetoothUnixSocketConnector.cpp b/dom/bluetooth/bluez/BluetoothUnixSocketConnector.cpp index 27d8ec46259..32faabf2142 100644 --- a/dom/bluetooth/bluez/BluetoothUnixSocketConnector.cpp +++ b/dom/bluetooth/bluez/BluetoothUnixSocketConnector.cpp @@ -22,7 +22,6 @@ */ #include "BluetoothUnixSocketConnector.h" -#include #include #include #include diff --git a/dom/bluetooth/bluez/BluetoothUnixSocketConnector.h b/dom/bluetooth/bluez/BluetoothUnixSocketConnector.h index 086eca64a08..75f4371c601 100644 --- a/dom/bluetooth/bluez/BluetoothUnixSocketConnector.h +++ b/dom/bluetooth/bluez/BluetoothUnixSocketConnector.h @@ -7,6 +7,7 @@ #ifndef mozilla_dom_bluetooth_BluetoothUnixSocketConnector_h #define mozilla_dom_bluetooth_BluetoothUnixSocketConnector_h +#include #include "BluetoothCommon.h" #include "mozilla/ipc/UnixSocketConnector.h" diff --git a/ipc/bluetooth/BluetoothDaemonConnection.cpp b/ipc/bluetooth/BluetoothDaemonConnection.cpp index c385bb2a490..a1f0dc79701 100644 --- a/ipc/bluetooth/BluetoothDaemonConnection.cpp +++ b/ipc/bluetooth/BluetoothDaemonConnection.cpp @@ -226,8 +226,8 @@ public: // nsresult Accept(int aFd, - const union sockaddr_any* aAddr, - socklen_t aAddrLen) override; + const struct sockaddr* aAddress, + socklen_t aAddressLength) override; // Methods for |DataSocketIO| // @@ -336,8 +336,8 @@ BluetoothDaemonConnectionIO::OnError(const char* aFunction, int aErrno) nsresult BluetoothDaemonConnectionIO::Accept(int aFd, - const union sockaddr_any* aAddr, - socklen_t aAddrLen) + const struct sockaddr* aAddress, + socklen_t aAddressLength) { MOZ_ASSERT(MessageLoopForIO::current() == GetIOLoop()); MOZ_ASSERT(GetConnectionStatus() == SOCKET_IS_CONNECTING); diff --git a/ipc/unixfd/UnixSocketWatcher.h b/ipc/unixfd/UnixSocketWatcher.h index 40fd868fa3e..37a0acc0d7b 100644 --- a/ipc/unixfd/UnixSocketWatcher.h +++ b/ipc/unixfd/UnixSocketWatcher.h @@ -8,33 +8,11 @@ #define mozilla_ipc_UnixSocketWatcher_h #include -#include -#include -#include -#ifdef MOZ_B2G_BT_BLUEZ -#include -#include -#include -#include -#endif #include "UnixFdWatcher.h" namespace mozilla { namespace ipc { -union sockaddr_any { - sockaddr_storage storage; // address-family only - sockaddr_un un; - sockaddr_in in; - sockaddr_in6 in6; -#ifdef MOZ_B2G_BT_BLUEZ - sockaddr_sco sco; - sockaddr_rc rc; - sockaddr_l2 l2; -#endif - // ... others -}; - class UnixSocketWatcher : public UnixFdWatcher { public: diff --git a/ipc/unixsocket/ConnectionOrientedSocket.h b/ipc/unixsocket/ConnectionOrientedSocket.h index a79bf9253f8..291ecd8049c 100644 --- a/ipc/unixsocket/ConnectionOrientedSocket.h +++ b/ipc/unixsocket/ConnectionOrientedSocket.h @@ -14,7 +14,6 @@ namespace mozilla { namespace ipc { class UnixSocketConnector; -union sockaddr_any; /* * |ConnectionOrientedSocketIO| and |ConnectionOrientedSocket| define @@ -28,8 +27,8 @@ public: virtual ~ConnectionOrientedSocketIO(); virtual nsresult Accept(int aFd, - const union sockaddr_any* aAddr, - socklen_t aAddrLen) = 0; + const struct sockaddr* aAddress, + socklen_t aAddressLength) = 0; }; class ConnectionOrientedSocket : public DataSocket diff --git a/ipc/unixsocket/ListenSocket.cpp b/ipc/unixsocket/ListenSocket.cpp index fc4c2321a8e..13e223fcecb 100644 --- a/ipc/unixsocket/ListenSocket.cpp +++ b/ipc/unixsocket/ListenSocket.cpp @@ -215,7 +215,7 @@ ListenSocketIO::OnSocketCanAcceptWithoutBlocking() } mCOSocketIO->Accept(fd, - reinterpret_cast(&storage), + reinterpret_cast(&storage), addressLength); } diff --git a/ipc/unixsocket/StreamSocket.cpp b/ipc/unixsocket/StreamSocket.cpp index 8f2124190c9..fb6684bbf9c 100644 --- a/ipc/unixsocket/StreamSocket.cpp +++ b/ipc/unixsocket/StreamSocket.cpp @@ -71,8 +71,8 @@ public: // nsresult Accept(int aFd, - const union sockaddr_any* aAddr, - socklen_t aAddrLen) override; + const struct sockaddr* aAddress, + socklen_t aAddressLength) override; // Methods for |DataSocket| // @@ -321,7 +321,8 @@ StreamSocketIO::FireSocketError() nsresult StreamSocketIO::Accept(int aFd, - const union sockaddr_any* aAddr, socklen_t aAddrLen) + const struct sockaddr* aAddress, + socklen_t aAddressLength) { MOZ_ASSERT(MessageLoopForIO::current() == GetIOLoop()); MOZ_ASSERT(GetConnectionStatus() == SOCKET_IS_CONNECTING); @@ -329,8 +330,8 @@ StreamSocketIO::Accept(int aFd, SetSocket(aFd, SOCKET_IS_CONNECTED); // Address setup - mAddressLength = aAddrLen; - memcpy(&mAddress, aAddr, mAddressLength); + mAddressLength = aAddressLength; + memcpy(&mAddress, aAddress, mAddressLength); // Signal success NS_DispatchToMainThread(