diff options
| author | 2021-04-27 03:23:04 +0000 | |
|---|---|---|
| committer | 2021-04-27 03:23:04 +0000 | |
| commit | 63b83282c9ee2cd78c2bf67c96e04c0addf15145 (patch) | |
| tree | c2fdc76b291acbf349854261b92bb71144066266 | |
| parent | a24adb14a2af5497caeec8e74ee9962ff04c64f9 (diff) | |
| parent | 33e1705271093f339618ae450c99f0981ebf90d4 (diff) | |
Merge changes I292b8e32,I689d0838 am: 1488a15856 am: cab292d695 am: 33e1705271
Original change: https://android-review.googlesource.com/c/platform/frameworks/native/+/1686989
Change-Id: Ie726bb550f5b960145e7b5a70e2ea7eb0bf54625
| -rw-r--r-- | libs/binder/RpcConnection.cpp | 33 |
1 files changed, 15 insertions, 18 deletions
diff --git a/libs/binder/RpcConnection.cpp b/libs/binder/RpcConnection.cpp index 1388a801e4..f2302f7e56 100644 --- a/libs/binder/RpcConnection.cpp +++ b/libs/binder/RpcConnection.cpp @@ -130,24 +130,21 @@ bool RpcConnection::addVsockClient(unsigned int cid, unsigned int port) { #endif // __BIONIC__ -class SocketAddressImpl : public RpcConnection::SocketAddress { +class InetSocketAddress : public RpcConnection::SocketAddress { public: - SocketAddressImpl(const sockaddr* addr, size_t size, const String8& desc) - : mAddr(addr), mSize(size), mDesc(desc) {} + InetSocketAddress(const sockaddr* sockAddr, size_t size, const char* addr, unsigned int port) + : mSockAddr(sockAddr), mSize(size), mAddr(addr), mPort(port) {} [[nodiscard]] std::string toString() const override { - return std::string(mDesc.c_str(), mDesc.size()); + return String8::format("%s:%u", mAddr, mPort).c_str(); } - [[nodiscard]] const sockaddr* addr() const override { return mAddr; } + [[nodiscard]] const sockaddr* addr() const override { return mSockAddr; } [[nodiscard]] size_t addrSize() const override { return mSize; } - void set(const sockaddr* addr, size_t size) { - mAddr = addr; - mSize = size; - } private: - const sockaddr* mAddr = nullptr; - size_t mSize = 0; - String8 mDesc; + const sockaddr* mSockAddr; + size_t mSize; + const char* mAddr; + unsigned int mPort; }; AddrInfo GetAddrInfo(const char* addr, unsigned int port) { @@ -170,14 +167,15 @@ AddrInfo GetAddrInfo(const char* addr, unsigned int port) { } bool RpcConnection::setupInetServer(unsigned int port) { - auto aiStart = GetAddrInfo("127.0.0.1", port); + const char* kAddr = "127.0.0.1"; + + auto aiStart = GetAddrInfo(kAddr, port); if (aiStart == nullptr) return false; - SocketAddressImpl socketAddress(nullptr, 0, String8::format("127.0.0.1:%u", port)); for (auto ai = aiStart.get(); ai != nullptr; ai = ai->ai_next) { - socketAddress.set(ai->ai_addr, ai->ai_addrlen); + InetSocketAddress socketAddress(ai->ai_addr, ai->ai_addrlen, kAddr, port); if (setupSocketServer(socketAddress)) return true; } - ALOGE("None of the socket address resolved for 127.0.0.1:%u can be set up as inet server.", + ALOGE("None of the socket address resolved for %s:%u can be set up as inet server.", kAddr, port); return false; } @@ -185,9 +183,8 @@ bool RpcConnection::setupInetServer(unsigned int port) { bool RpcConnection::addInetClient(const char* addr, unsigned int port) { auto aiStart = GetAddrInfo(addr, port); if (aiStart == nullptr) return false; - SocketAddressImpl socketAddress(nullptr, 0, String8::format("%s:%u", addr, port)); for (auto ai = aiStart.get(); ai != nullptr; ai = ai->ai_next) { - socketAddress.set(ai->ai_addr, ai->ai_addrlen); + InetSocketAddress socketAddress(ai->ai_addr, ai->ai_addrlen, addr, port); if (addSocketClient(socketAddress)) return true; } ALOGE("None of the socket address resolved for %s:%u can be added as inet client.", addr, port); |