Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fc87fc21 authored by Steven Moreland's avatar Steven Moreland Committed by Automerger Merge Worker
Browse files

Merge changes I9b5b2876,I3b93e0a9 am: 94a9ae33

Original change: https://android-review.googlesource.com/c/platform/frameworks/native/+/1697653

Change-Id: I05b63b429cd2da1f2ed5856a4d2d1593feac7484
parents 88cf4b21 94a9ae33
Loading
Loading
Loading
Loading
+0 −4
Original line number Diff line number Diff line
@@ -49,8 +49,6 @@ bool RpcServer::setupUnixDomainServer(const char* path) {
    return setupSocketServer(UnixSocketAddress(path));
}

#ifdef __BIONIC__

bool RpcServer::setupVsockServer(unsigned int port) {
    // realizing value w/ this type at compile time to avoid ubsan abort
    constexpr unsigned int kAnyCid = VMADDR_CID_ANY;
@@ -58,8 +56,6 @@ bool RpcServer::setupVsockServer(unsigned int port) {
    return setupSocketServer(VsockSocketAddress(kAnyCid, port));
}

#endif // __BIONIC__

bool RpcServer::setupInetServer(unsigned int port, unsigned int* assignedPort) {
    const char* kAddr = "127.0.0.1";

+36 −30
Original line number Diff line number Diff line
@@ -61,14 +61,10 @@ bool RpcSession::setupUnixDomainClient(const char* path) {
    return setupSocketClient(UnixSocketAddress(path));
}

#ifdef __BIONIC__

bool RpcSession::setupVsockClient(unsigned int cid, unsigned int port) {
    return setupSocketClient(VsockSocketAddress(cid, port));
}

#endif // __BIONIC__

bool RpcSession::setupInetClient(const char* addr, unsigned int port) {
    auto aiStart = InetSocketAddress::getAddrInfo(addr, port);
    if (aiStart == nullptr) return false;
@@ -219,28 +215,34 @@ bool RpcSession::setupSocketClient(const RpcSocketAddress& addr) {

    // we've already setup one client
    for (size_t i = 0; i + 1 < numThreadsAvailable; i++) {
        // TODO(b/185167543): avoid race w/ accept4 not being called on server
        for (size_t tries = 0; tries < 5; tries++) {
            if (setupOneSocketClient(addr, mId.value())) break;
            usleep(10000);
        }
        // TODO(b/185167543): shutdown existing connections?
        if (!setupOneSocketClient(addr, mId.value())) return false;
    }

    return true;
}

bool RpcSession::setupOneSocketClient(const RpcSocketAddress& addr, int32_t id) {
    for (size_t tries = 0; tries < 5; tries++) {
        if (tries > 0) usleep(10000);

        unique_fd serverFd(
                TEMP_FAILURE_RETRY(socket(addr.addr()->sa_family, SOCK_STREAM | SOCK_CLOEXEC, 0)));
        if (serverFd == -1) {
            int savedErrno = errno;
        ALOGE("Could not create socket at %s: %s", addr.toString().c_str(), strerror(savedErrno));
            ALOGE("Could not create socket at %s: %s", addr.toString().c_str(),
                  strerror(savedErrno));
            return false;
        }

        if (0 != TEMP_FAILURE_RETRY(connect(serverFd.get(), addr.addr(), addr.addrSize()))) {
            if (errno == ECONNRESET) {
                ALOGW("Connection reset on %s", addr.toString().c_str());
                continue;
            }
            int savedErrno = errno;
        ALOGE("Could not connect socket at %s: %s", addr.toString().c_str(), strerror(savedErrno));
            ALOGE("Could not connect socket at %s: %s", addr.toString().c_str(),
                  strerror(savedErrno));
            return false;
        }

@@ -257,6 +259,10 @@ bool RpcSession::setupOneSocketClient(const RpcSocketAddress& addr, int32_t id)
        return true;
    }

    ALOGE("Ran out of retries to connect to %s", addr.toString().c_str());
    return false;
}

void RpcSession::addClient(unique_fd fd) {
    std::lock_guard<std::mutex> _l(mMutex);
    sp<RpcConnection> session = sp<RpcConnection>::make();
+1 −7
Original line number Diff line number Diff line
@@ -24,9 +24,7 @@
#include <sys/types.h>
#include <sys/un.h>

#ifdef __BIONIC__
#include <linux/vm_sockets.h>
#endif
#include "vm_sockets.h"

namespace android {

@@ -59,8 +57,6 @@ private:
    sockaddr_un mAddr;
};

#ifdef __BIONIC__

class VsockSocketAddress : public RpcSocketAddress {
public:
    VsockSocketAddress(unsigned int cid, unsigned int port)
@@ -80,8 +76,6 @@ private:
    sockaddr_vm mAddr;
};

#endif // __BIONIC__

class InetSocketAddress : public RpcSocketAddress {
public:
    InetSocketAddress(const sockaddr* sockAddr, size_t size, const char* addr, unsigned int port)
+0 −2
Original line number Diff line number Diff line
@@ -57,12 +57,10 @@ public:
     */
    [[nodiscard]] bool setupUnixDomainServer(const char* path);

#ifdef __BIONIC__
    /**
     * Creates an RPC server at the current port.
     */
    [[nodiscard]] bool setupVsockServer(unsigned int port);
#endif // __BIONIC__

    /**
     * Creates an RPC server at the current port using IPv4.
+0 −2
Original line number Diff line number Diff line
@@ -52,12 +52,10 @@ public:
     */
    [[nodiscard]] bool setupUnixDomainClient(const char* path);

#ifdef __BIONIC__
    /**
     * Connects to an RPC server at the CVD & port.
     */
    [[nodiscard]] bool setupVsockClient(unsigned int cvd, unsigned int port);
#endif // __BIONIC__

    /**
     * Connects to an RPC server at the given address and port.
Loading